compare_models: Compare fitted models on the same data

View source: R/compare-models.R

compare_modelsR Documentation

Compare fitted models on the same data

Description

One row per model with its log likelihood, number of parameters, information criteria, classification quality and convergence, so alternative specifications (for example trajectory classes alone against a growth mixture model) are compared without assembling tables by hand. delta_bic is each model's BIC above the smallest, and bic_weight the Schwarz weight, exp(-delta/2) normalized over the models compared (Wagenmakers and Farrell 2004): the approximate posterior probability of each model if one of them is true, with equal prior probabilities.

Usage

compare_models(...)

Arguments

...

Two or more fits from mixture_regression() (with or without random). Name them to label the rows; unnamed fits are labelled by their expression.

Details

Information criteria are comparable only on the same data: every model must be fitted to the same outcome, persons (or groups) and observations, or the comparison is refused.

Value

A base data.frame of class latents_comparison with one row per model: model, n_classes, random, n_parameters, log_likelihood, aic, bic, sabic, icl, entropy, smallest_share, delta_bic, bic_weight, converged. Raises latents_bad_argument for fits it cannot compare and latents_incomparable_models for fits to different data.

References

Wagenmakers, E.-J., & Farrell, S. (2004). AIC model selection using Akaike weights. Psychonomic Bulletin & Review, 11, 192–196.

Examples

# Fixed trajectories against growth curves with a random intercept,
# for the first 60 students
few_students <- subset(growth_scores, student <= 60)
trajectories <- mixture_regression(score ~ wave, few_students, n_classes = 2,
                                   id = "student", class_level = "group",
                                   seed = 1)
growth <- mixture_regression(score ~ wave, few_students, n_classes = 2,
                             id = "student", class_level = "group",
                             random = "intercept", seed = 1)
compare_models(trajectories = trajectories, growth = growth)

latents documentation built on Oct. 16, 2026, 5:09 p.m.