Skip to contents

Overview

latents-package latents
Latent Profile, Class and Transition Models

Fitting models

Two-level latent profile, latent class and latent transition models.

lpa()
Fit a latent profile model that groups observations by their pattern on continuous indicators
lca()
Fit a latent class model that groups observations by their pattern of categorical responses
multilpa()
Fit a two-level latent profile model: profiles of observations and classes of the groups they are nested in
multilca()
Fit a two-level latent class model: classes of categorical responses and classes of the groups they are nested in
lta()
Fit a latent transition model of how units move between latent states over repeated occasions
fit_staged()
Fit a two-level profile model in two stages, holding the profiles fixed while the group classes are estimated
starting_values()
Get the estimates of a fitted profile or class model as starting values for another fit
prior_control()
Set a prior that regularises the means and covariances of Gaussian profile models

Results

Every table of a fitted model, retrieved by name.

get_results()
Get any table of a fitted model, grid, comparison, test or diagnostics result as a data frame
descriptives()
Describe each variable of a data frame or a fitted model, with its variation within and between groups
diagnostics()
Diagnose a fitted model: convergence, replication, class sizes, separation and local independence
report()
Print the estimates, descriptive statistics and diagnostic checks of a fitted model, and draw its plots
overview()
Print and plot everything about any object of the package: its summary, its checks and every plot
get_checks()
Get every diagnostic check of a fitted model, with its value, rule and status
get_entropy()
Get the relative entropy, from 0 to 1, of how sharply a model separates its classes
get_classification()
Get how many units each class holds and how certain their assignment is
get_avepp()
Get the average posterior probability of every class among the units assigned to each class
get_residuals()
Get the bivariate residuals: the association between pairs of indicators that each class leaves unexplained
get_replication()
Get how many random starts converged, failed and reached the best log likelihood

Evaluating a model

enumerate_lpa()
Fit latent profile models with different numbers of profiles and covariance structures, and compare them
enumerate_lca()
Fit latent class models with different numbers of classes, and compare them
enumerate_classes()
Fit models with different numbers of classes and collect their criteria and diagnostics for comparison
get_candidate() candidate_fit()
Get one fitted model out of an enumeration grid or a model comparison
get_candidates()
Get the table of every candidate model in an enumeration grid, with its criteria and diagnostics
get_best()
Get the converged candidate with the lowest value of each information criterion
get_deltas()
Get how much each information criterion improves as a class or a group class is added
get_knees()
Get the candidate after which adding classes improves each information criterion much less
get_tree()
Get how the classes of each candidate split into the classes of the next, as a table
bootstrap_lrt()
Test whether a model with one more class improves on a nested model, with a parametric bootstrap likelihood ratio
sensitivity()
Refit a model from several random seeds and check whether it reaches the same solution
align_labels()
Renumber one fit's profiles and group classes to match the most similar ones of another fit
parameter_inference()
Compute standard errors, confidence intervals and tests for the estimates of a fitted model
pool_imputations()
Fit a profile or class model to each imputed data set and pool the results across the imputations

Mixture regression and growth models

Regressions whose coefficients differ across latent classes, at one or two levels, for continuous, binary and count outcomes; classes of trajectories, with random effects within classes (growth mixture models).

mixture_regression()
Fit a mixture regression model in which the relationship between an outcome and its predictors differs across latent classes
enumerate_regressions()
Fit mixture regression models with different numbers of classes, and compare them
compare_models()
Compare the fit, classification and convergence of several fitted models in one table
predict(<latents_mixture_regression>) simulate(<latents_mixture_regression>) predict(<multilpa>)
Predict class membership or outcomes from a fitted model, and simulate data from it

External variables

Three-step analysis with a correction for classification error.

three_step()
Compare latent classes on an outcome not used to define them, correcting for classification error
r3step()
Regress latent class membership on covariates not used to define the classes, correcting for classification error

Plots of a fit

One function per picture; each takes any fit that has the view.

plot_profiles()
Plot how the profiles differ on the indicators: each profile's mean, or another summary, on every indicator
plot_bars()
Plot the mean of each continuous indicator in each profile as bars
plot_heatmap()
Plot profile means as tiles of profiles by indicators, or a grid's criterion as tiles of candidates
plot_raincloud()
Plot the distribution of each continuous indicator in each profile as a density, its quartiles and the points
plot_parallel()
Plot every case as a line across the continuous indicators, one panel per profile
plot_pairs()
Plot every pair of continuous indicators against each other, with the cases and an ellipse for each profile
plot_responses()
Plot each profile's probability of one response category on every categorical or ordinal indicator
plot_prevalence()
Plot how common each profile is within each group class of a two-level model
plot_sequences()
Plot each unit's sequence of assigned profiles across the occasions as a row of coloured cells
plot_transitions()
Plot the estimated probability of moving from each profile to each profile between occasions
plot_trajectories()
Plot the curve of the outcome in each class of a mixture regression model
plot_individuals()
Plot individual persons' observations and predicted curves beside the trajectory of their class
plot_coefficients()
Plot the regression coefficients of each class of a mixture regression, with 95% confidence intervals
plot_classification()
Plot each person's posterior probability of every class in a growth model as a stacked bar
plot_all()
Plot every view an object has and return the plots as one list

Classification plots

The four classification views, for a fit of any family or a grid.

plot_sizes()
Plot how many units each class holds, or the size of the smallest class of every candidate in a grid
plot_posteriors()
Plot the posterior probability of each unit's assigned class, by class
plot_entropy()
Plot how uncertain the classification is, by unit for a fitted model or by candidate for a grid
plot_avepp()
Plot the average posterior probability matrix of a fit, or the lowest average posterior probability of every candidate
plot_diagnostics()
Plot how well a fitted model separates its classes: sizes, posteriors, entropy and average posterior probabilities

Plots of a candidate grid

plot_criteria()
Plot every information criterion of a grid, or of a model comparison, against the number of classes
plot_enumeration()
Plot the information criteria of an enumeration grid against the number of classes
plot_selection()
Plot the evidence for choosing the number of classes from an enumeration grid
plot_deltas()
Plot how much the information criterion falls each time a class or a group class is added
plot_trust()
Plot whether each candidate of a grid converged, lies on a boundary and replicated its best log likelihood
plot_tree()
Plot how the classes of each solution split or rearrange as one more class is added
plot_views()
List the views a plot call can draw for a fitted model or a grid, with what each one shows

Transition networks

Latent transitions handed to the tna package.

get_tna()
Get the transitions between a fitted model's profiles as one transition network for the whole sample
get_group_tna()
Get one transition network per latent group class, to compare how their members move between profiles

Data

course_engagement
Student engagement across a sequence of courses
engagement_momentum
Simulated engagement states and trajectories over a study programme
student_esm
Leisure activities of university students in daily life
study_hours
Study hours and quiz scores under two study strategies
growth_scores
Simulated achievement scores with three growth trajectories
growth_schools
Reading growth of students nested in schools
srl
Self-regulated learning scores generated by a large language model

Methods

Coefficients, covariance, intervals and likelihood of a fit.

vcov(<multilpa_covariates>) coef(<multilpa>) vcov(<multilpa>) confint(<multilpa>)
Extract the coefficients, their covariance matrix and the log likelihood of a fitted model

Conditions

latents-conditions
Errors, warnings and diagnostic messages