The R Project SVN R

Rev

Rev 59039 | Rev 67599 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 59039 Rev 61433
Line 13... Line 13...
13
\description{
13
\description{
14
  Select a formula-based model by AIC.
14
  Select a formula-based model by AIC.
15
}
15
}
16
\usage{
16
\usage{
17
step(object, scope, scale = 0,
17
step(object, scope, scale = 0,
18
     direction = c("both", "backward", "forward"), 
18
     direction = c("both", "backward", "forward"),
19
     trace = 1, keep = NULL, steps = 1000, k = 2, \dots)
19
     trace = 1, keep = NULL, steps = 1000, k = 2, \dots)
20
}
20
}
21
\arguments{
21
\arguments{
22
  \item{object}{
22
  \item{object}{
23
    an object representing a model of an appropriate class (mainly
23
    an object representing a model of an appropriate class (mainly
Line 36... Line 36...
36
    \code{\link{glm}} models.  The default value, \code{0}, indicates
36
    \code{\link{glm}} models.  The default value, \code{0}, indicates
37
    the scale should be estimated: see \code{\link{extractAIC}}.
37
    the scale should be estimated: see \code{\link{extractAIC}}.
38
  }
38
  }
39
  \item{direction}{
39
  \item{direction}{
40
    the mode of stepwise search, can be one of \code{"both"},
40
    the mode of stepwise search, can be one of \code{"both"},
41
    \code{"backward"}, or \code{"forward"}, with a default of \code{"both"}. 
41
    \code{"backward"}, or \code{"forward"}, with a default of \code{"both"}.
42
    If the \code{scope} argument is missing the default for
42
    If the \code{scope} argument is missing the default for
43
    \code{direction} is \code{"backward"}.
43
    \code{direction} is \code{"backward"}.
44
  }
44
  }
45
  \item{trace}{
45
  \item{trace}{
46
    if positive, information is printed during the running of \code{step}.
46
    if positive, information is printed during the running of \code{step}.
47
    Larger values may give more detailed information.
47
    Larger values may give more detailed information.
48
  }
48
  }
49
  \item{keep}{
49
  \item{keep}{
50
    a filter function whose input is a fitted model object and the 
50
    a filter function whose input is a fitted model object and the
51
    associated \code{AIC} statistic, and whose output is arbitrary. 
51
    associated \code{AIC} statistic, and whose output is arbitrary.
52
    Typically \code{keep} will select a subset of the components of 
52
    Typically \code{keep} will select a subset of the components of
53
    the object and return them. The default is not to keep anything.
53
    the object and return them. The default is not to keep anything.
54
  }
54
  }
55
  \item{steps}{
55
  \item{steps}{
56
    the maximum number of steps to be considered.  The default is 1000
56
    the maximum number of steps to be considered.  The default is 1000
57
    (essentially as many as required).  It is typically used to stop the
57
    (essentially as many as required).  It is typically used to stop the
Line 96... Line 96...
96
  Models specified by \code{scope} can be templates to update
96
  Models specified by \code{scope} can be templates to update
97
  \code{object} as used by \code{\link{update.formula}}.  So using
97
  \code{object} as used by \code{\link{update.formula}}.  So using
98
  \code{.} in a \code{scope} formula means \sQuote{what is
98
  \code{.} in a \code{scope} formula means \sQuote{what is
99
  already there}, with \code{.^2} indicating all interactions of
99
  already there}, with \code{.^2} indicating all interactions of
100
  existing terms.
100
  existing terms.
101
  
101
 
102
  There is a potential problem in using \code{\link{glm}} fits with a
102
  There is a potential problem in using \code{\link{glm}} fits with a
103
  variable \code{scale}, as in that case the deviance is not simply
103
  variable \code{scale}, as in that case the deviance is not simply
104
  related to the maximized log-likelihood.  The \code{"glm"} method for
104
  related to the maximized log-likelihood.  The \code{"glm"} method for
105
  function \code{\link{extractAIC}} makes the
105
  function \code{\link{extractAIC}} makes the
106
  appropriate adjustment for a \code{gaussian} family, but may need to be
106
  appropriate adjustment for a \code{gaussian} family, but may need to be
Line 147... Line 147...
147
  Pregibon (1992); but the implementation in \R is more general.
147
  Pregibon (1992); but the implementation in \R is more general.
148
}
148
}
149
\examples{\donttest{
149
\examples{\donttest{
150
## following on from example(lm)
150
## following on from example(lm)
151
\dontshow{utils::example("lm", echo = FALSE)}
151
\dontshow{utils::example("lm", echo = FALSE)}
152
step(lm.D9)  
152
step(lm.D9)
153
 
153
 
154
summary(lm1 <- lm(Fertility ~ ., data = swiss))
154
summary(lm1 <- lm(Fertility ~ ., data = swiss))
155
slm1 <- step(lm1)
155
slm1 <- step(lm1)
156
summary(slm1)
156
summary(slm1)
157
slm1$anova
157
slm1$anova