multilca: Fit a two-level latent class model

View source: R/multilca.R

multilcaR Documentation

Fit a two-level latent class model

Description

Two-level latent class analysis for categorical indicators: multilpa() with discrete indicators in vars treated as categorical unless named in ordinal or count through .... Each profile is described by unrestricted response probabilities for categorical items and the corresponding structured parameters for ordinal and count items, and the group classes differ in how probable each profile is for their observations. For models that combine categorical and continuous indicators, call multilpa() and name the categorical ones in its categorical argument.

Usage

multilca(data, vars, id, n_profiles, n_group_classes = 2L, ...)

Arguments

data

A data frame with one row per observation.

vars

Names of the categorical indicator columns. Numeric, integer, logical, character and factor columns are accepted; factor levels keep their declared order and other types are sorted.

id

Name of the group identifier column, or NULL for a single-level model.

n_profiles

Number of observation-level latent classes (profiles).

n_group_classes

Number of group-level latent classes. Defaults to 2, or to 1 when id = NULL (a single-level model has no second level).

...

Further arguments to multilpa(), such as n_starts, seed, missing, tol or profile_covariates. ordinal and count can name structured discrete indicators; the remaining indicators are categorical. categorical cannot be supplied.

Value

A fitted model of class multilpa (or multilpa_covariates when membership covariates are given), exactly as multilpa() returns it with the corresponding discrete indicator types. Categorical response probabilities are in get_results(fit, "responses"), one row per profile, item and category.

Conditions

latents_bad_argument when categorical is supplied, since its columns are derived from vars, ordinal and count here. Every condition of multilpa() can also be raised.

See Also

multilpa() for continuous and mixed indicators, and vignette("lca", package = "latents").

Examples

activities <- c("time_with_friends", "on_social_media", "tv_video_games")
fit <- multilca(subset(student_esm, day <= 1), vars = activities,
                id = "student", n_profiles = 2, n_group_classes = 2,
                n_starts = 1, seed = 1)
get_results(fit, "responses")
get_results(fit, "profile_probabilities")

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