| stepwise | R Documentation |
Stepwise Model Selection
stepwise(
mod,
direction = c("backward/forward", "forward/backward", "backward", "forward"),
criterion = c("BIC", "AIC"),
...
)
mod |
a model object of a class that can be handled by |
direction |
if |
criterion |
for selection. Either |
... |
arguments to be passed to |
This function is a front end to the stepAIC function in the MASS package.
The model selected by stepAIC.
John Fox
W. N. Venables and B. D. Ripley Modern Applied Statistics Statistics with S, Fourth Edition Springer, 2002.
stepAIC
## adapted from stepAIC in MASS
## Assigning bwt to the global environment is required to run this example within
## the browser-based help system. In other contexts, standard assignment can be used.
if (require(MASS)){
data(birthwt)
bwt <<- with(birthwt, {
race <- factor(race, labels = c("white", "black", "other"))
ptd <- factor(ptl > 0)
ftv <- factor(ftv)
levels(ftv)[-(1:2)] <- "2+"
data.frame(low = factor(low), age, lwt, race, smoke = (smoke > 0), ptd,
ht = (ht > 0), ui = (ui > 0), ftv)
})
birthwt.glm <- glm(low ~ ., family = binomial, data = bwt)
print(stepwise(birthwt.glm, trace = FALSE))
print(stepwise(birthwt.glm, direction="forward/backward"))
}
## wrapper for stepAIC in the MASS package
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.