View source: R/ols-best-subsets-regression.R
ols_step_best_subset | R Documentation |
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. The default metric used for selecting the model is R2 but the user can choose any of the other available metrics.
ols_step_best_subset(model, ...)
## Default S3 method:
ols_step_best_subset(
model,
max_order = NULL,
include = NULL,
exclude = NULL,
metric = c("rsquare", "adjr", "predrsq", "cp", "aic", "sbic", "sbc", "msep", "fpe",
"apc", "hsp"),
...
)
## S3 method for class 'ols_step_best_subset'
plot(x, model = NA, print_plot = TRUE, ...)
model |
An object of class |
... |
Other inputs. |
max_order |
Maximum subset order. |
include |
Character or numeric vector; variables to be included in selection process. |
exclude |
Character or numeric vector; variables to be excluded from selection process. |
metric |
Metric to select model. |
x |
An object of class |
print_plot |
logical; if |
ols_step_best_subset
returns an object of class "ols_step_best_subset"
.
An object of class "ols_step_best_subset"
is a list containing the following:
metrics |
selection metrics |
Kutner, MH, Nachtscheim CJ, Neter J and Li W., 2004, Applied Linear Statistical Models (5th edition). Chicago, IL., McGraw Hill/Irwin.
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
ols_step_best_subset(model)
ols_step_best_subset(model, metric = "adjr")
ols_step_best_subset(model, metric = "cp")
# maximum subset
model <- lm(mpg ~ disp + hp + drat + wt + qsec, data = mtcars)
ols_step_best_subset(model, max_order = 3)
# plot
model <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
k <- ols_step_best_subset(model)
plot(k)
# return only models including `qsec`
ols_step_best_subset(model, include = c("qsec"))
# exclude `hp` from selection process
ols_step_best_subset(model, exclude = c("hp"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.