# stepwise backward regression
model <- lm(y ~ ., data = surgical)
ols_step_backward_adj_r2(model)
# final model and selection metrics
k <- ols_step_backward_aic(model)
k$metrics
k$model
# include or exclude variable
# force variables to be included in the selection process
ols_step_backward_adj_r2(model, include = c("alc_mod", "gender"))
# use index of variable instead of name
ols_step_backward_adj_r2(model, include = c(7, 6))
# force variable to be excluded from selection process
ols_step_backward_adj_r2(model, exclude = c("alc_heavy", "bcs"))
# use index of variable instead of name
ols_step_backward_adj_r2(model, exclude = c(8, 1))
Run the code above in your browser using DataLab