# stepwise backward regression
model <- lm(y ~ ., data = surgical)
ols_step_backward_p(model)
# stepwise backward regression plot
model <- lm(y ~ ., data = surgical)
k <- ols_step_backward_p(model)
plot(k)
# selection metrics
k$metrics
# final model
k$model
# include or exclude variables
# force variable to be included in selection process
ols_step_backward_p(model, include = c("age", "alc_mod"))
# use index of variable instead of name
ols_step_backward_p(model, include = c(5, 7))
# force variable to be excluded from selection process
ols_step_backward_p(model, exclude = c("pindex"))
# use index of variable instead of name
ols_step_backward_p(model, exclude = c(2))
# hierarchical selection
model <- lm(y ~ bcs + alc_heavy + pindex + age + alc_mod, data = surgical)
ols_step_backward_p(model, 0.1, hierarchical = TRUE)
# plot
k <- ols_step_backward_p(model, 0.1, hierarchical = TRUE)
plot(k)
Run the code above in your browser using DataLab