ModelEnvFormula          package:modeltools          R Documentation

_G_e_n_e_r_a_t_e _a _m_o_d_e_l _e_n_v_i_r_o_n_m_e_n_t _f_r_o_m _a 
_c_l_a_s_s_i_c_a_l _f_o_r_m_u_l_a _b_a_s_e_d _i_n_t_e_r_f_a_c_e.

_D_e_s_c_r_i_p_t_i_o_n:

     A flexible implementation of the classical formula based
     interface.

_U_s_a_g_e:

     ModelEnvFormula(formula, data = list(), subset = NULL, 
                     na.action = NULL, frame = NULL, other = list(), 
                     designMatrix = TRUE, responseMatrix = TRUE, ...)

_A_r_g_u_m_e_n_t_s:

 formula: a symbolic description of the model to be fit. 

    data: an optional data frame containing the variables in the model.
           If not found in 'data', the variables are taken from
          'frame', by default the environment from which
          'ModelEnvFormula' is called.

  subset: an optional vector specifying a subset of observations to be
          used in the fitting process. 

na.action: a function which indicates what should happen when the data
          contain 'NA''s. 

   frame: an optional environment 'formula' is evaluated in. 

   other: an optional named list of additional formulae. 

designMatrix: a logical indicating whether the design matrix defined by
          the right hand side of 'formula'  should be computed. 

responseMatrix: a logical indicating whether the design matrix defined
          by the left hand side of 'formula' should be computed.  

     ...: additional arguments for be passed to function, for example
          'contrast.arg' to 'model.matrix'. 

_D_e_t_a_i_l_s:

     This function is an attempt to provide a flexible infrastucture
     for the implementation of classical formula based interfaces. The
     arguments 'formula', 'data', 'subset' and 'na.action' are well
     known and are defined in the same way as in 'lm', for example.

     'ModelEnvFormula' returns an object of class
     'ModelEnvFormula-class' - a high level object for storing data
     improving upon the capabilities of 'data.frame's.

_V_a_l_u_e:

     An object of class 'ModelEnvFormula-class'.

_E_x_a_m_p_l_e_s:

     ### the `usual' interface
     data(iris)
     mf <- ModelEnvFormula(Species ~ ., data = iris)
     mf

     ### extract data from the ModelEnv object
     summary(mf@get("response"))
     summary(mf@get("input"))
     dim(mf@get("designMatrix"))

     ### contrasts
     mf <- ModelEnvFormula(Petal.Width ~ Species, data = iris, 
                           contrasts.arg = list(Species = contr.treatment))
     attr(mf@get("designMatrix"), "contrasts")
     mf <- ModelEnvFormula(Petal.Width ~ Species, data = iris, 
                           contrasts.arg = list(Species = contr.sum))
     attr(mf@get("designMatrix"), "contrasts")

     ### additional formulae
     mf <- ModelEnvFormula(Petal.Width ~ Species, data = iris, 
                           other = list(pl = ~ Petal.Length))
     ls(mf@env)
     identical(mf@get("pl")[[1]], iris[["Petal.Length"]])

