## Fit different candidate models
mod1 <- lm(mpg ~ disp, data = mtcars)
mod2 <- lm(mpg ~ disp + hp, data = mtcars)
mod3 <- lm(mpg ~ disp + hp + wt, data = mtcars)
mod4 <- lm(mpg ~ disp + hp + wt + carb, data = mtcars)
## Group models into list
models_list <- list("Model 1" = mod1, "Model 2" = mod2,
"Model 3" = mod3, "Model 4" = mod4)
## Prepare data for visualisation
## Specific metric
model_selection_data(models = models_list,
metric = c("AIC"))
## Multiple metrics can be plotted together as well
model_selection_data(models = models_list,
metric = c("AIC", "BIC"))
## If single metric is specified then breakup of metric
## between goodness of fit and penalty can also be visualised
model_selection_data(models = models_list,
metric = c("AICc"),
breakup = TRUE)
## Sort models
model_selection_data(models = models_list,
metric = c("AICc"),
breakup = TRUE, sort = TRUE)
## If multiple metrics are specified then sorting
## will be done on first metric specified in list (AIC in this case)
model_selection_data(models = models_list,
metric = c("AIC", "BIC", "AICc", "BICc"), sort = TRUE)
Run the code above in your browser using DataLab