step.glm(object, scope, scale, direction="both", trace=T, keep=NULL, steps=1000,control=NULL)
glm
or its inheritant, an
lm
object.
scope
is a list consisting of two formulas,
one named
"upper"
, the other
"lower"
.
These define the range of models to be considered for selection,
and only their right hand sides are of relevance.
All models considered have to include the terms specified in
scope$lower
,
and have to be included in those in
scope$upper
.
The supplied model
object
is used as the starting model, and hence
there is the requirement that it lies between
$upper
and
$lower
.
scope
is missing, the search defaults to a backward step-wise search,
using
formula(object)
as the upper scope, and the NULL model as the
lower scope.
If
scope
is a single
formula
object, it is assumed to be the upper model.
Any "." in the scope formula is interpreted relative to the formula
in
object
.
glm
models at each step.
By default, the scaled Chi-squared statistic for the initial model is used,
but if forward selection is to be performed,
this is not necessarily a sound choice.
"both"
,
"backward"
, or
"forward"
, with a default of
"both"
.
If
scope
is missing, the default for
direction
is
"backward"
.
TRUE
, information is printed during the running of
step.glm
.
This is an encouraging choice in general, since
step.glm
can
take some time to compute either for large models or when
called with an extensive
scope=
argument.
The information printed includes the anova tables computed for the selection
of each model, as well as a simple one line model summary for
each selected and iterated model.
glm
object and the associated
"AIC" statistic, and whose output is arbitrary.
Typically
keep
will select a subset of the components of
the object and return them.
The default is not to keep anything.
maxit
and/or
epsilon
such as is produced by
glm.control
. Values specified here will override the control values
used in the original model.
"anova"
component corresponding to the steps taken in the
search, as well as a
"keep"
component if the
keep=
argument was
supplied in the call.
After parsing the
scope=
argument,
step.glm
computes the model
matrix corresponding to the upper scope.
It then enters a loop, adding or deleting a term at a time.
The term for deletion or addition is based on the output of
drop1
and
add1
, a type of score test based on the current fit.
Once a model is selected, it is iterated to convergence, and
the loop continues.
The iterations stop when no step decreases the AIC criterion,
defined by AIC = Deviance +2*scale*df.resid.
glm.object <- glm(Kyphosis ~ Age + Start + Number, family = binomial, data = kyphosis) step(glm.object) step(glm.object,list(upper = ~.^2, lower = ~ Age))