ModelEnvMatrix.Rd
A simple model environment creator function working off matrices for input and response. This is much simpler and more limited than formula-based environments, but faster and easier to use, if only matrices are allowed as input.
ModelEnvMatrix(designMatrix=NULL, responseMatrix=NULL,
subset = NULL, na.action = NULL, other=list(), ...)
design matrix of input
matrix of responses
an optional vector specifying a subset of observations to be used in the fitting process.
a function which indicates what should happen when the data
contain NA
's.
an optional named list of additional formulae.
currently not used
ModelEnvMatrix
returns an object of class
ModelEnv-class
- a high level object for storing
data improving upon the capabilities of simple data matrices.
Funny things may happen if the inpiut and response matrices do not have
distinct column names and the data new data are supplied via the
get
and set
slots.
An object of class ModelEnv-class
.
### use Sepal measurements as input and Petal as response
data(iris)
me <- ModelEnvMatrix(iris[,1:2], iris[,3:4])
me
#>
#> A ModelEnv with
#>
#> response matrix column(s): Petal.Length Petal.Width
#> design matrix column(s): Sepal.Length Sepal.Width
#> number of observations: 150
#>
### extract data from the ModelEnv object
dim(me@get("designMatrix"))
#> [1] 150 2
summary(me@get("responseMatrix"))
#> Petal.Length Petal.Width
#> Min. :1.000 Min. :0.100
#> 1st Qu.:1.600 1st Qu.:0.300
#> Median :4.350 Median :1.300
#> Mean :3.758 Mean :1.199
#> 3rd Qu.:5.100 3rd Qu.:1.800
#> Max. :6.900 Max. :2.500
### subsets and missing values
iris[1,1] <- NA
me <- ModelEnvMatrix(iris[,1:2], iris[,3:4], subset=1:5, na.action=na.omit)
## First case is not complete, so me contains only cases 2:5
me
#>
#> A ModelEnv with
#>
#> response matrix column(s): Petal.Length Petal.Width
#> design matrix column(s): Sepal.Length Sepal.Width
#> number of observations: 4
#>
me@get("designMatrix")
#> Sepal.Length Sepal.Width
#> [1,] 4.9 3.0
#> [2,] 4.7 3.2
#> [3,] 4.6 3.1
#> [4,] 5.0 3.6
me@get("responseMatrix")
#> Petal.Length Petal.Width
#> [1,] 1.4 0.2
#> [2,] 1.3 0.2
#> [3,] 1.5 0.2
#> [4,] 1.4 0.2
## use different cases
me@set(data=iris[10:20,])
me@get("designMatrix")
#> Sepal.Length Sepal.Width
#> 10 4.9 3.1
#> 11 5.4 3.7
#> 12 4.8 3.4
#> 13 4.8 3.0
#> 14 4.3 3.0
#> 15 5.8 4.0
#> 16 5.7 4.4
#> 17 5.4 3.9
#> 18 5.1 3.5
#> 19 5.7 3.8
#> 20 5.1 3.8
## these two should be the same
stopifnot(all.equal(me@get("responseMatrix"), as.matrix(iris[10:20,3:4])))