add1.lm
is used to investigate a Linear Model Object by adding to
it, in turn, each of an number of specified terms.
add1.lm(object, scope, scale, keep, x = NULL)
lm
object, or any object that inherits from class
lm
. In particular,
a
glm
object is also appropriate for a
chi-squaredanalysis based on the score-test.
formula
object describing the terms to be added.
This argument is required, and is parsed to produce a set of
terms that may be added to the model on their own without breaking
the hierarchy rules.
The
scope
can also be a character vector of term labels.
Any
"."
in
scope
is interpreted relative to the
formula implied by the
object
argument.
Cp
statistic.
If not supplied,
scale
is estimated by the residual variance of
object
,
or else in the case of a
glm
object the dispersion parameter.
"coefficients"
,
"fitted.values"
,
"residuals"
,
"x.residuals"
,
"effects"
,
"R"
are allowed.
If
keep
is
TRUE
, the complete set is implied.
Use
"x.residuals"
to get the
X
matrix corresponding to a given term,
adjusted for all the terms in the model
object
.
The other components are as in
object
.
The default behavior is not to keep anything.
object
as well as
all those to be added.
This is an optional argument, used, for example, by
step.glm
,
and saves recomputing the model matrix every time.
object
and scope.
object
and scope.
"list"
, with a column for
each superset model, and a row for each component kept.
Using the
"R"
component of
object
, as well as the corresponding
qr
object, each of the superset models corresponding to
object
plus a term as specified in
scope
are fitted.
An
anova
object is constructed, consisting of the term labels,
the degrees of freedom, the residual sum of squares, and the Cp statistic
for each superset model.
add1
handles weighted
lm
objects, in particular
glm
objects.
The weighted residual sum of squares is a Pearson chi-square statistic
based on the weights of the model
object
, and a one-step
iteration towards the superset model.
This results in a
score testfor the inclusion of each term. The function
add1
is used as a primitive in
step.glm
.
This function is a method for the generic function
for class lm.
It can be invoked by calling
for an object x of the appropriate class, or directly by calling
regardless of the class of the object.
Chambers, J.M., and Hastie, T.J. (1991). Statistical Models in S, 125 and 233--238
attach(catalyst) fit1<- aov(Yield ~ Temp + Cat + Conc) add1(fit1, ~ .^2) # consider all interactions of terms in lm.object for inclusion attach(kyphosis) kyph.glm <- glm(Kyphosis ~ poly(Age, 2) + (Number > 5) * Start, family = binomial) add1(kyph.glm, ~ . - Age + poly(Age, 2)+ log(Age) + sqrt(Age)) # try some candidate transformations for Age.