expand.model.frame           package:base           R Documentation

_A_d_d _n_e_w _v_a_r_i_a_b_l_e_s _t_o _a _m_o_d_e_l _f_r_a_m_e

_D_e_s_c_r_i_p_t_i_o_n:

     Evaluates new variables as if they had been part of the formula of
     the specified model.  This ensures that the same 'na.action' and
     'subset' arguments are applied and allows, for example, 'x' to be
     recovered for a model using 'sin(x)' as a predictor.

_U_s_a_g_e:

     expand.model.frame(model, extras, envir=environment(formula(model)),
                        na.expand = FALSE)

_A_r_g_u_m_e_n_t_s:

   model: a fitted model

  extras: one-sided formula or vector of character strings describing
          new variables to be added

   envir: an environment to evaluate things in

na.expand: logical; see below

_D_e_t_a_i_l_s:

     If 'na.expand=FALSE' then 'NA' values in the extra variables will
     be passed to the 'na.action' function used in 'model'.  This may
     result in a shorter data frame (with 'na.omit') or an error (with
     'na.fail').  If 'na.expand=TRUE' the returned data frame will have
     precisely the same rows as 'model.frame(model)', but the columns
     corresponding to the extra variables may contain 'NA'.

_V_a_l_u_e:

     A data frame.

_S_e_e _A_l_s_o:

     'model.frame','predict'

_E_x_a_m_p_l_e_s:

     data(trees)
     model <- lm(log(Volume) ~ log(Girth) + log(Height), data=trees)
     expand.model.frame(model, ~ Girth) # prints data.frame like

     dd <- data.frame(x=1:5, y=rnorm(5), z=c(1,2,NA,4,5))
     model <- glm(y ~ x, data=dd, subset=1:4, na.action=na.omit)
     expand.model.frame(model, "z", na.expand=FALSE) # = default
     expand.model.frame(model, "z", na.expand=TRUE)

