A flexible implementation of the classical formula based interface.

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

Arguments

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.

enclos

specifies the enclosure passed to eval for evaluating the model frame. The model frame is evaluated in envir = frame with enclos = enclos, see eval.

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.

setHook

a list of functions to MEapply every time set is called on the object.

...

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

Details

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.frames.

Value

An object of class ModelEnvFormula-class.

Examples


### the `usual' interface
data(iris)
mf <- ModelEnvFormula(Species ~ ., data = iris)
mf
#> 
#> A ModelEnvFormula with 
#> 
#>   response variable(s):   Species 
#>   input variable(s):      Sepal.Length Sepal.Width Petal.Length Petal.Width 
#>   number of observations: 150 
#> 

### extract data from the ModelEnv object
summary(mf@get("response"))
#>        Species  
#>  setosa    :50  
#>  versicolor:50  
#>  virginica :50  
summary(mf@get("input"))
#>   Sepal.Length    Sepal.Width     Petal.Length    Petal.Width   
#>  Min.   :4.300   Min.   :2.000   Min.   :1.000   Min.   :0.100  
#>  1st Qu.:5.100   1st Qu.:2.800   1st Qu.:1.600   1st Qu.:0.300  
#>  Median :5.800   Median :3.000   Median :4.350   Median :1.300  
#>  Mean   :5.843   Mean   :3.057   Mean   :3.758   Mean   :1.199  
#>  3rd Qu.:6.400   3rd Qu.:3.300   3rd Qu.:5.100   3rd Qu.:1.800  
#>  Max.   :7.900   Max.   :4.400   Max.   :6.900   Max.   :2.500  
dim(mf@get("designMatrix"))
#> [1] 150   5

### contrasts
mf <- ModelEnvFormula(Petal.Width ~ Species, data = iris, 
                      contrasts.arg = list(Species = contr.treatment))
#> Warning: variable 'Species' is absent, its contrast will be ignored
attr(mf@get("designMatrix"), "contrasts")
#> $Species
#>            versicolor virginica
#> setosa              0         0
#> versicolor          1         0
#> virginica           0         1
#> 
mf <- ModelEnvFormula(Petal.Width ~ Species, data = iris, 
                      contrasts.arg = list(Species = contr.sum))
#> Warning: variable 'Species' is absent, its contrast will be ignored
attr(mf@get("designMatrix"), "contrasts")
#> $Species
#>            [,1] [,2]
#> setosa        1    0
#> versicolor    0    1
#> virginica    -1   -1
#> 

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