## 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
Run the code above in your browser using DataLab