if (FALSE) {
# stepwise regression
model <- lm(y ~ ., data = stepdata)
ols_step_both_sbc(model)
# stepwise regression plot
model <- lm(y ~ ., data = stepdata)
k <- ols_step_both_sbc(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_sbc(model, include = c("x6"))
# use index of variable instead of name
ols_step_both_sbc(model, include = c(6))
# force variable to be excluded from selection process
ols_step_both_sbc(model, exclude = c("x2"))
# use index of variable instead of name
ols_step_both_sbc(model, exclude = c(2))
# include & exclude variables in the selection process
ols_step_both_sbc(model, include = c("x6"), exclude = c("x2"))
# use index of variable instead of name
ols_step_both_sbc(model, include = c(6), exclude = c(2))
}
Run the code above in your browser using DataLab