# stepwise forward regression
model <- lm(y ~ ., data = surgical)
ols_step_forward_adj_r2(model)
# stepwise forward regression plot
k <- ols_step_forward_adj_r2(model)
plot(k)
# selection metrics
k$metrics
# extract final model
k$model
# include or exclude variables
# force variable to be included in selection process
ols_step_forward_adj_r2(model, include = c("age"))
# use index of variable instead of name
ols_step_forward_adj_r2(model, include = c(5))
# force variable to be excluded from selection process
ols_step_forward_adj_r2(model, exclude = c("liver_test"))
# use index of variable instead of name
ols_step_forward_adj_r2(model, exclude = c(4))
# include & exclude variables in the selection process
ols_step_forward_adj_r2(model, include = c("age"), exclude = c("liver_test"))
# use index of variable instead of name
ols_step_forward_adj_r2(model, include = c(5), exclude = c(4))
Run the code above in your browser using DataLab