stepCriterion.lm {glmtoolbox} | R Documentation |
Variable Selection in Normal Linear Models
Description
Performs variable selection in normal linear models using a hybrid versions of forward stepwise and backward stepwise.
Usage
## S3 method for class 'lm'
stepCriterion(
model,
criterion = c("bic", "aic", "adjr2", "prdr2", "cp", "p-value"),
direction = c("forward", "backward"),
levels = c(0.05, 0.05),
trace = TRUE,
scope,
force.in,
force.out,
...
)
Arguments
model |
an object of the class lm. |
criterion |
an (optional) character string indicating the criterion which should be used to compare the candidate models. The available options are: AIC ("aic"), BIC ("bic"), adjusted R-squared ("adjr2"), predicted R-squared ("prdr2"), Mallows' CP ("cp") and p-value of the F test ("p-value"). As default, |
direction |
an (optional) character string indicating the type of procedure which should be used. The available options are: hybrid backward stepwise ("backward") and hybrid forward stepwise ("forward"). As default, |
levels |
an (optional) two-dimensional vector of values in the interval |
trace |
an (optional) logical switch indicating if should the stepwise reports be printed. As default, |
scope |
an (optional) list containing components |
force.in |
an (optional) formula-type object indicating the effects that should be in all models |
force.out |
an (optional) formula-type object indicating the effects that should be in no models |
... |
further arguments passed to or from other methods. For example, |
Details
The "hybrid forward stepwise" algorithm starts with the
simplest model (which may be chosen at the argument scope
, and
As default, is a model whose parameters in the linear predictor,
except the intercept, if any, are set to 0), and then the candidate
models are built by hierarchically including effects in the linear
predictor, whose "relevance" and/or "importance" in the model fit is
assessed by comparing nested models (that is, by comparing the models
with and without the added effect) using a criterion previously
specified. If an effect is added to the equation, this strategy may
also remove any effect which, according to the previously specified
criteria, no longer provides an improvement in the model fit. That
process continues until no more effects are included or excluded. The
"hybrid backward stepwise" algorithm works similarly.
Value
a list list with components including
initial | a character string indicating the linear predictor of the "initial model", |
direction | a character string indicating the type of procedure which was used, |
criterion | a character string indicating the criterion used to compare the candidate models, |
final | a character string indicating the linear predictor of the "final model", |
final.fit | an object of class lm with the results of the fit to the data of the "final model", |
References
James G., Witten D., Hastie T., Tibshirani R. (2013, page 210) An Introduction to Statistical Learning with Applications in R, Springer, New York.
See Also
stepCriterion.glm, stepCriterion.overglm, stepCriterion.glmgee
stepCriterion.glm, stepCriterion.overglm, stepCriterion.glmgee
Examples
###### Example 1: New York air quality measurements
fit1 <- lm(log(Ozone) ~ Solar.R + Temp + Wind, data=airquality)
scope=list(lower=~1, upper=~Solar.R*Temp*Wind)
stepCriterion(fit1, direction="forward", criterion="adjr2", scope=scope)
stepCriterion(fit1, direction="forward", criterion="bic", scope=scope)
stepCriterion(fit1, direction="forward", criterion="p-value", scope=scope)
###### Example 2: Fuel consumption of automobiles
fit2 <- lm(mpg ~ log(hp) + log(wt) + qsec, data=mtcars)
scope=list(lower=~1, upper=~log(hp)*log(wt)*qsec)
stepCriterion(fit2, direction="backward", criterion="bic", scope=scope)
stepCriterion(fit2, direction="forward", criterion="cp", scope=scope)
stepCriterion(fit2, direction="backward", criterion="prdr2", scope=scope)
###### Example 3: Credit card balance
Credit <- ISLR::Credit
fit3 <- lm(Balance ~ Cards + Age + Rating + Income + Student + Limit, data=Credit)
stepCriterion(fit3, direction="forward", criterion="prdr2")
stepCriterion(fit3, direction="forward", criterion="cp")
stepCriterion(fit3, direction="forward", criterion="p-value")