File: fit.models.Rd

package info (click to toggle)
r-cran-fit.models 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 364 kB
  • sloc: sh: 13; makefile: 2
file content (88 lines) | stat: -rw-r--r-- 3,241 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fit.models.R
\name{fit.models}
\alias{fit.models}
\title{Fit dot Models}
\usage{
fit.models(model.list, ...)
}
\arguments{
\item{model.list}{a list or a character vector containing names of modeling
functions.  Only required when \code{fit.models} is being used to fit models
(rather than combine already fitted models into a \code{fit.models} object).}

\item{\dots}{see details.}
}
\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.
}
\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.
}
\details{
There are two distinct ways the \code{fit.models} function can be used.

The first is to fit the same model using different estimators.  In this
case, \code{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
\dots) are the common arguments to the functions in \code{model.list}.
For example, the following command fits robust and least squares linear
models to Brownlee's Stack Loss Plant Data. \preformatted{
fit.models(c("rlm", "lm"), stack.loss ~ ., data = stackloss)} The resulting
\code{fit.models} object is a list with the output of \preformatted{
rlm(stack.loss ~ ., data = stackloss)} in the first element and
\preformatted{ lm(stack.loss ~ ., data = stackloss)} in the second.  The
class attribute of the returned list is set (in this case) to \code{"lmfm"}
which is the \code{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, \code{fit.models} combines its arguments into a fit.models object
(a list where element \eqn{i} is occupied by argument \eqn{i} and sets the
class attribute to the appropriate \code{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)
}
\seealso{
\code{\link{fmclass.add.class}} for adding a class to an existing
fit.models class and \code{\link{fmclass.register}} to create a new
fit.models class.
}
\keyword{models}