# stepwise forward regression
model <- lm(y ~ ., data = surgical)
ols_step_forward_aic(model)
# stepwise forward regression plot
k <- ols_step_forward_aic(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_aic(model, include = c("age"))
# use index of variable instead of name
ols_step_forward_aic(model, include = c(5))
# force variable to be excluded from selection process
ols_step_forward_aic(model, exclude = c("liver_test"))
# use index of variable instead of name
ols_step_forward_aic(model, exclude = c(4))
# include & exclude variables in the selection process
ols_step_forward_aic(model, include = c("age"), exclude = c("liver_test"))
# use index of variable instead of name
ols_step_forward_aic(model, include = c(5), exclude = c(4))
Run the code above in your browser using DataLab