Description Usage Arguments Details Value See Also Examples
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.
1 | fit.models(model.list, ...)
|
model.list |
a list or a character vector containing names of modeling
functions. Only required when |
... |
see 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.
1 | fit.models(c("rlm", "lm"), stack.loss ~ ., data = stackloss)
|
The resulting
fit.models object is a list with the output of
1 | rlm(stack.loss ~ ., data = stackloss)
|
in the first element and
1 | 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.
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.
fmclass.add.class for adding a class to an existing
fit.models class and fmclass.register to create a new
fit.models class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.