StatModel-class.Rd
A class for unfitted statistical models.
Objects can be created by calls of the form new("StatModel", ...)
.
name
:Object of class "character"
, the name of the
model.
dpp
:Object of class "function"
, a function for
data preprocessing (usually formula-based).
fit
:Object of class "function"
, a function for
fitting the model to data.
predict
:Object of class "function"
, a function for
computing predictions.
capabilities
:Object of class
"StatModelCapabilities"
.
signature(model = "StatModel", data = "ModelEnv")
:
fit model
to data
.
This is an attempt to provide unified infra-structure for unfitted
statistical models. Basically, an unfitted model provides a function for
data pre-processing (dpp
, think of generating design matrices),
a function for fitting the specified model to data (fit
), and
a function for computing predictions (predict
).
Examples for such unfitted models are provided by linearModel
and
glinearModel
which provide interfaces in the "StatModel"
framework
to lm.fit
and glm.fit
, respectively. The functions
return objects of S3 class "linearModel"
(inheriting from "lm"
) and
"glinearModel"
(inheriting from "glm"
), respectively. Some
methods for S3 generics such as predict
, fitted
, print
and model.matrix
are provided to make use of the "StatModel"
structure. (Similarly, survReg
provides an experimental interface to
survreg
.)
### linear model example
df <- data.frame(x = runif(10), y = rnorm(10))
mf <- dpp(linearModel, y ~ x, data = df)
mylm <- fit(linearModel, mf)
### equivalent
print(mylm)
#> Linear model with coefficients:
#> (Intercept) x
#> 0.6243 -0.7374
lm(y ~ x, data = df)
#>
#> Call:
#> lm(formula = y ~ x, data = df)
#>
#> Coefficients:
#> (Intercept) x
#> 0.6243 -0.7374
#>
### predictions
Predict(mylm, newdata = data.frame(x = runif(10)))
#> 1 2 3 4 5 6
#> 0.46210168 0.08753049 0.46425172 0.28791558 0.37892806 0.20524112
#> 7 8 9 10
#> 0.43835476 0.28217645 -0.05232398 -0.09301416