select_n_classes: Select Number of Latent Classes via BIC

View source: R/latent_class.R

select_n_classesR Documentation

Select Number of Latent Classes via BIC

Description

Fits a latent class metafrontier model for each value in n_classes_range and tabulates the Bayesian information criterion (BIC) and marginal log-likelihood of each fit. The optimal number of classes minimises BIC. Fits that fail are silently dropped from the table. Because the EM algorithm can converge to local optima, the ranking is sensitive to the number of random starts: pass n_starts (forwarded to latent_class_metafrontier) and increase it for a more reliable comparison across class counts.

Usage

select_n_classes(formula, data, n_classes_range = 2:5, ...)

Arguments

formula

formula.

data

data frame.

n_classes_range

integer vector of class counts to try.

...

additional arguments passed to latent_class_metafrontier, notably n_starts.

Value

A data frame with columns n_classes, BIC, and marginal_ll.

Examples


sim <- simulate_metafrontier(n_groups = 2, n_per_group = 80, seed = 42)
bic_table <- select_n_classes(
  log_y ~ log_x1 + log_x2,
  data = sim$data, n_classes_range = 2:3,
  n_starts = 3, seed = 42
)
print(bic_table)



metafrontier documentation built on Aug. 19, 2026, 5:08 p.m.