This function performs an automated selection of the 'best' parameters, updating and returning the "best" model.
Usage
select_parameters(model, ...)
# S3 method for class 'lm'
select_parameters(model, direction = "both", steps = 1000, k = 2, ...)
# S3 method for class 'merMod'
select_parameters(model, direction = "backward", steps = 1000, ...)Arguments
- model
A statistical model (of class
lm,glm, ormerMod).- ...
Arguments passed to or from other methods.
- direction
the mode of stepwise search, can be one of
"both","backward", or"forward", with a default of"both". If thescopeargument is missing the default fordirectionis"backward". Values can be abbreviated.- steps
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.
- k
The multiple of the number of degrees of freedom used for the penalty. Only
k = 2gives the genuine AIC:k = log(n)is sometimes referred to as BIC or SBC.
Classical lm and glm
For frequentist GLMs, select_parameters() performs an AIC-based stepwise
selection.
Mixed models
For mixed-effects models of class merMod, stepwise selection is based on
cAIC4::stepcAIC(). This step function only searches the "best" model
based on the random-effects structure, i.e. select_parameters() adds or
excludes random-effects until the cAIC can't be improved further.
Examples
if (FALSE) { # requireNamespace("lme4")
model <- lm(mpg ~ ., data = mtcars)
select_parameters(model)
model <- lm(mpg ~ cyl * disp * hp * wt, data = mtcars)
select_parameters(model)
# \donttest{
# lme4 -------------------------------------------
model <- lme4::lmer(
Sepal.Width ~ Sepal.Length * Petal.Width * Petal.Length + (1 | Species),
data = iris
)
select_parameters(model)
# }
}
