if (FALSE) {
# stepwise regression
model <- lm(y ~ ., data = stepdata)
ols_step_both_r2(model)
# stepwise regression plot
model <- lm(y ~ ., data = stepdata)
k <- ols_step_both_r2(model)
plot(k)
# selection metrics
k$metrics
# final model
k$model
# include or exclude variables
# force variable to be included in selection process
model <- lm(y ~ ., data = stepdata)
ols_step_both_r2(model, include = c("x6"))
# use index of variable instead of name
ols_step_both_r2(model, include = c(6))
# force variable to be excluded from selection process
ols_step_both_r2(model, exclude = c("x2"))
# use index of variable instead of name
ols_step_both_r2(model, exclude = c(2))
# include & exclude variables in the selection process
ols_step_both_r2(model, include = c("x6"), exclude = c("x2"))
# use index of variable instead of name
ols_step_both_r2(model, include = c(6), exclude = c(2))
}
Run the code above in your browser using DataLab