View source: R/select_models.R
select_models | R Documentation |
Performs stepwise model selection using forward, backward, or both directions across different regression approaches. Returns a summary table with evaluation metrics (AIC, BIC, log-likelihood, deviance) and the best model.
select_models(
data,
outcome,
exposures,
approach = "logit",
direction = "forward"
)
data |
A data frame containing the outcome and predictor variables. |
outcome |
A character string indicating the outcome variable. |
exposures |
vector of predictor variables to consider in the model. |
approach |
Regression method. One of:
|
direction |
Stepwise selection direction. One of:
|
A list with the following components:
results_table
: A tibble summarising each tested model's metric
(AIC, BIC, deviance, log-likelihood, adjusted R² if applicable).
best_model
: The best-fitting model object based on low AIC.
all_models
: A named list of all fitted models.
data <- data_PimaIndiansDiabetes
stepwise <- select_models(
data = data,
outcome = "glucose",
exposures = c("age", "pregnant", "mass"),
approach = "linear",
direction = "forward"
)
summary(stepwise)
stepwise$results_table
stepwise$best_model
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.