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: LCA with a covariate (1-step approach)

Description This code fits a 4-class, latent-class model for marijuana use and attitudes using a model-based approach (1-step approach). It includes a covariate for grades in the model. Software Downloads Latent Gold Mplus SAS Stata Exercise Exercise 5 This exercise asks you to use a model-based approach (1-step approach) to add a covariate for grades to a 4-class model for marijuana use and attitudes that uses 7 binary indicators of the latent class variable. You have to carefully consider what latent class to use as the reference class in the multinomial logistic regression. You may wish to standardize the grades...

LCA: LCA with a covariate and a grouping variable (1-step approach)

Description This code fits a 4-class, latent-class model for marijuana use and attitudes using a model-based approach (1-step approach). It includes a covariate for grades and a grouping variable for year in the model. Software Downloads Latent Gold SAS Exercise Exercise 5 This exercise asks you to use a model-based approach (1-step approach) to add a covariate for grades and a grouping variable for year to a 4-class model for marijuana use and attitudes that uses 7 binary indicators of the latent class variable. You have to carefully consider what latent class to use as the reference class in the...

LCA: LCA with a grouping variable and without measurement variance

Description 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. Software Downloads Latent Gold Mplus SAS Stata Exercise Exercise 4 This exercise asks you to add a grouping variable for year to a 4-class model for marijuana use and attitudes that uses 7 binary indicators of the latent class variable. It asks you to fit a model...

LPA: Baseline LPA with all continuous indicators and a covariate

Description This code fits a baseline, latent-profile model for the “Big 5” personality traits using 5 continuous indicators of the latent class variable and biological sex as a covariate. Software Downloads Latent Gold Mplus Exercise Exercise 6 This exercise asks you to select and interpret a latent profile model for the “Big 5” personality traits using 5 continuous indicators of the latent class variable as well as add a covariate for biological sex. Then, it asks you to interpret all parameters in the model. Note that, by default in most software packages, the variances of the indicators are restricted to...

LPA: Baseline LPA with all continuous indicators and a grouping variable with measurement invariance

Description This code fits a baseline, latent-profile model for the “Big 5” personality traits using 5 continuous indicators of the latent class variable and biological sex as the grouping variable. It also imposes measurement invariance across the groups. Software Downloads Latent Gold Mplus Exercise Exercise 6 This exercise asks you to select and interpret a latent profile model for the “Big 5” personality traits using 5 continuous indicators of the latent class variable as well as add a grouping variable for biological sex. Then, it asks you to interpret all parameters in the model. Please be sure to impose measurement...

LPA: Baseline LPA with continuous and categorical indicators (mixed indicator model)

Description This code fits a mixed indicator latent-profile model (using both continuous and categorical indicators) to identify family subgroups that conform to risk factors associated with adolescent antisocial behavior. This code corresponds to the research paper titled “Constellations of Family Risk for Long-Term Adolescent Antisocial Behavior” published in Journal of Family Psychology in 2020. The paper can be found here: https://pmc.ncbi.nlm.nih.gov/articles/PMC7375013/ Software Downloads Mplus Model Features Model Category Your Content Goes Here Model Type Your Content Goes Here Indicator Type Your Content Goes Here Available Software Your Content Goes Here Measurement Invariance Your Content Goes Here Approach to Outcomes Your...

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.