drop1.lm
function is used to investigate a linear model object by successively omitting specified terms from the model.
drop1.lm(object, scope, scale, keep, all.cols)
lm
object, or any object that inherits from class
"lm"
. In particular, a
glm
object is also appropriate to use with this function; see the Details section below.
formula
object describing the terms that should be dropped from the model.
This argument is usually omitted, in which case all possible terms are dropped (without breaking hierarchy rules).
The
scope
can also be a character vector of term labels.
If the argument is supplied as a formula, any period
"."
is interpreted relative to the formula in the
object
argument.
df
term in the
Cp
statistic. If not supplied,
scale
is estimated by the residual variance of
object
; in the case of a
glm
object,
scale
is estimated by the dispersion parameter.
coefficients
,
fitted.values
,
residuals
,
x.residuals
,
effects
, and
R
.
The
x.residuals
component for a given term is the
X
matrix corresponding to that term, adjusted for all the other terms in
object
.
The other components are as in
object
.
If
keep=T
, the complete set of components is saved. The default behavior is not to keep anything.
drop1
for singular model matrices.
If all columns are used, new columns are introduced to replace those dropped from the model that are aliased with other terms in the full model.
This means it is possible for the
drop1
fit to be unchanged from the original fit, and for a dropped term to have 0 degrees of freedom.
If
all.cols=FALSE
, the non-singular matrix from the full model (formed by omitting aliased rows) is used throughout
drop1
.
In this case, each term typically has the same number of degrees of freedom as in the full model.
By default,
all.cols=TRUE
.
"R"
return component of
object
, each of the subset models corresponding to the terms specified in
scope
is computed.
An
anova
object is constructed, consisting of the term labels, degrees of freedom, residual sum of squares, and the
Cp
statistic for each subset model.
If
keep
is missing, the
anova
object is all that is returned.
If
keep
is specified, a list with components
"anova"
and
"keep"
is returned.
In this case, the
"keep"
component is a matrix of mode
"list"
, containing one column for each subset model and one row for each kept component.
This function is a method for the generic function
for the class "lm". It can be invoked by calling
for an object x of the appropriate class, or directly by calling
directly regardless of the class of the object.
The
drop1.lm
function handles weighted
lm
objects, including
glm
objects.
The weighted residual sum of squares is a Pearson chi-square statistic, based on the weights of the full model and a one-step iteration towards the subset model.
This results in a score test for the removal of each term. The function
drop1
is used as a primitive in
step.glm
.
Chambers, J.M., and Hastie, T.J. (1991). Statistical Models in S. London: Chapman & Hall.
fit1 <- lm(cost ~ age + type + car.age, claims, weights = number, na.action = na.exclude) # Single term deletions drop1(fit1) # Drop all terms except 'Age' drop1(fit1, ~ . - Age) drop1(fit1, keep=T)