fit.models {fit.models} | R Documentation |
Fit dot Models
Description
Fit a statistical model using different estimators (e.g., robust and least-squares) or combine fitted models into a single object. Generic methods then produce side-by-side comparisons of the parameter estimates and diagnostic plots.
Usage
fit.models(model.list, ...)
Arguments
model.list |
a list or a character vector containing names of modeling
functions. Only required when |
... |
see details. |
Details
There are two distinct ways the fit.models
function can be used.
The first is to fit the same model using different estimators. In this
case, model.list
should be a character vector or a list where each
element is the name of a modeling function and the remaining arguments (in
...) are the common arguments to the functions in model.list
.
For example, the following command fits robust and least squares linear
models to Brownlee's Stack Loss Plant Data.
fit.models(c("rlm", "lm"), stack.loss ~ ., data = stackloss)
The resulting
fit.models
object is a list with the output of
rlm(stack.loss ~ ., data = stackloss)
in the first element and
lm(stack.loss ~ ., data = stackloss)
in the second. The
class attribute of the returned list is set (in this case) to "lmfm"
which is the fit.models
class (fmclass) for comparing linear-model-like
fits.
The second use of fit.models is to combine fitted model objects. In
this case, fit.models
combines its arguments into a fit.models object
(a list where element i
is occupied by argument i
and sets the
class attribute to the appropriate fit.models
class.
Value
The returned object is a list containing the fitted models. The class of the retuned object depends on the classes of the model objects it contains.
See Also
fmclass.add.class
for adding a class to an existing
fit.models class and fmclass.register
to create a new
fit.models class.
Examples
# First, use fit.models to fit robust and least squares linear
# regression models to Brownlee's Stack Loss Plant Data.
# Step 1: rlm (robust linear model) is in the MASS package.
library(MASS)
# Step 2: tell fit.models rlm can be compared to lm
fmclass.add.class("lmfm", "rlm")
fm1 <- fit.models(c("rlm", "lm"), stack.loss ~ ., data = stackloss)
summary(fm1) #rlm does not provide p-values or Multiple R-squared
# Second, use fit.models to combine fitted models into a
# fit.models object.
lm.complete <- lm(stack.loss ~ ., data = stackloss)
lm.clean <- lm(stack.loss ~ ., data = stackloss, subset = 5:20)
fm2 <- fit.models(lm.clean, lm.complete)
summary(fm2)
plot(fm2)
# Name the models in the fit.models object.
fm3 <- fit.models(c(Robust = "rlm", "Least Squares" = "lm"),
stack.loss ~ ., data = stackloss)
fm4 <- fit.models(Clean = lm.clean, Complete = lm.complete)