library(olsrr) library(dplyr) library(ggplot2) library(gridExtra) library(purrr) library(tibble) library(nortest) library(goftest)
All subset regression tests all possible subsets of the set of potential independent variables. If there are K potential independent variables (besides the constant), then there are $2^{k}$ distinct subsets of them to be tested. For example, if you have 10 candidate independent variables, the number of subsets to be tested is $2^{10}$, which is 1024, and if you have 20 candidate variables, the number is $2^{20}$, which is more than one million.
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars) ols_step_all_possible(model)
The plot method shows the panel of fit criteria for all possible regression methods.
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars) k <- ols_step_all_possible(model) plot(k)
Select the subset of predictors that do the best at meeting some well-defined objective criterion, such as having the largest R2 value or the smallest MSE, Mallow's Cp or AIC.
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars) ols_step_best_subset(model)
The plot method shows the panel of fit criteria for best subset regression methods.
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars) k <- ols_step_best_subset(model) plot(k)
Build regression model from a set of candidate predictor variables by entering predictors based on
p values, in a stepwise manner until there is no variable left to enter any more. The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise forward regression model <- lm(y ~ ., data = surgical) ols_step_forward_p(model)
model <- lm(y ~ ., data = surgical) k <- ols_step_forward_p(model) plot(k)
# stepwise forward regression model <- lm(y ~ ., data = surgical) ols_step_forward_p(model, details = TRUE)
Build regression model from a set of candidate predictor variables by removing predictors based on
p values, in a stepwise manner until there is no variable left to remove any more. The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise backward regression model <- lm(y ~ ., data = surgical) ols_step_backward_p(model)
model <- lm(y ~ ., data = surgical) k <- ols_step_backward_p(model) plot(k)
# stepwise backward regression model <- lm(y ~ ., data = surgical) ols_step_backward_p(model, details = TRUE)
Build regression model from a set of candidate predictor variables by entering and removing predictors based on
p values, in a stepwise manner until there is no variable left to enter or remove any more. The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise regression model <- lm(y ~ ., data = surgical) ols_step_both_p(model)
model <- lm(y ~ ., data = surgical) k <- ols_step_both_p(model) plot(k)
# stepwise regression model <- lm(y ~ ., data = surgical) ols_step_both_p(model, details = TRUE)
Build regression model from a set of candidate predictor variables by entering predictors based on
Akaike Information Criteria, in a stepwise manner until there is no variable left to enter any more.
The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise aic forward regression model <- lm(y ~ ., data = surgical) ols_step_forward_aic(model)
model <- lm(y ~ ., data = surgical) k <- ols_step_forward_aic(model) plot(k)
# stepwise aic forward regression model <- lm(y ~ ., data = surgical) ols_step_forward_aic(model, details = TRUE)
Build regression model from a set of candidate predictor variables by removing predictors based on
Akaike Information Criteria, in a stepwise manner until there is no variable left to remove any more.
The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise aic backward regression model <- lm(y ~ ., data = surgical) k <- ols_step_backward_aic(model) k
model <- lm(y ~ ., data = surgical) k <- ols_step_backward_aic(model) plot(k)
# stepwise aic backward regression model <- lm(y ~ ., data = surgical) ols_step_backward_aic(model, details = TRUE)
Build regression model from a set of candidate predictor variables by entering and removing predictors based on
Akaike Information Criteria, in a stepwise manner until there is no variable left to enter or remove any more.
The model should include all the candidate predictor variables. If details is set to TRUE, each step is displayed.
# stepwise aic regression model <- lm(y ~ ., data = surgical) ols_step_both_aic(model)
model <- lm(y ~ ., data = surgical) k <- ols_step_both_aic(model) plot(k)
# stepwise aic regression model <- lm(y ~ ., data = surgical) ols_step_both_aic(model, details = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.