
Last chance! 50% off unlimited learning
Sale ends in
This function performs an automated selection of the 'best' parameters, updating and returning the "best" model. For frequentist simple GLMs, it performs an AIC-based stepwise selection. For Bayesian models, it uses the projpred
package.
parameters_selection(model, ...)# S3 method for lm
parameters_selection(model, direction = "both",
steps = 1000, k = 2, ...)
# S3 method for merMod
parameters_selection(model, direction = "backward",
steps = 1000, ...)
# S3 method for stanreg
parameters_selection(model, method = NULL,
cross_validation = FALSE, ...)
A statistical model.
Arguments passed to or from other methods.
the mode of stepwise search, can be one of "both"
,
"backward"
, or "forward"
, with a default of "both"
.
If the scope
argument is missing the default for
direction
is "backward"
. Values can be abbreviated.
the maximum number of steps to be considered. The default is 1000 (essentially as many as required). It is typically used to stop the process early.
the multiple of the number of degrees of freedom used for the penalty.
Only k = 2
gives the genuine AIC: k = log(n)
is sometimes
referred to as BIC or SBC.
The method used in the variable selection. Can be NULL (default), "forward" or "L1". See projpred::varsel
.
Select with cross-validation.
The model refitted with optimal number of parameters.
# NOT RUN {
model <- lm(mpg ~ ., data = mtcars)
parameters_selection(model)
model <- lm(mpg ~ cyl * disp * hp * wt, data = mtcars)
parameters_selection(model)
# }
# NOT RUN {
# lme4 -------------------------------------------
library(lme4)
model <- lmer(Sepal.Width ~ Sepal.Length * Petal.Width * Petal.Length + (1 | Species), data = iris)
parameters_selection(model)
# rstanarm -------------------------------------------
library(rstanarm)
model <- stan_glm(mpg ~ ., data = mtcars, iter = 500, refresh = 0)
parameters_selection(model, cross_validation = TRUE)
model <- stan_glm(mpg ~ cyl * disp * hp, data = mtcars, iter = 500, refresh = 0)
parameters_selection(model, cross_validation = FALSE)
# }
Run the code above in your browser using DataLab