The LCAKB’s Code Repository is designed to be a “one-stop shop” to download sample code for latent class models. Many of the code examples come from projects and workshops conducted by Drs. Bethany Bray, John Dziak, and Stephanie Lanza when they were investigators at The Methodology Center at Penn State and supported in part by National Institute on Drug Abuse Center of Excellence awards from 1996-2021 (P50 DA039838 and P50 DA010075). In addition, many of the code examples come from the work of their collaborators and trainees, including those supported by the Prevention and Methodology Training Program, a National Institute on Drug Abuse Training Program (T32 DA017629).

Below you will find a list of all available models and code “snippets.” You can use the filters on the sidebar to narrow down the models for which you are looking. The LCAKB Code Repository is under active development and is currently being expanded. New models and code snippets will be published soon. Please sign up to our mailing list below to be informed of when they are published. If you would like to contribute a piece of code to help your fellow researchers, please email Dr. Bethany Bray at bcbray@latentclassanalysis.com.

If you would like to support continued development of the LCAKB, buy us a coffee! Click our mug to donate.

All Models

LCA: Baseline LCA with 3+ level categorical indicators

This code fits a longitudinal latent class model, using categorical indicators with 3+ levels, to identify latent classes indicated by multidimensional experiences of racism and heterosexism during the transition to adulthood among sexual minority men of color.

LCA: Latent class moderation

This code demonstrates how to use a latent class moderator to examine heterogeneity in intervention effects among adolescents receiving treatment for cannabis use. First, the code identifies latent classes of contextual and individual risk at baseline using LCA. Then, it uses an adjusted 3-step approach with BCH weights to regress the outcomes on level of care, latent class membership, the interaction between them, and covariates.

LCA: LCA with a grouping variable and without measurement variance

This code fits a 4-class, latent-class model for marijuana use and attitudes using 7 binary indicators of the latent class variable. It includes a grouping variable for year, and observations came from 3 different years. Measurement invariance across groups is not imposed resulting in an unrestricted latent class model with multiple groups.

Let’s stay in touch.

We are in this together. Receive an email whenever a new model or resource is added to the Knowledge Base website.