Lab 9 - The Manual 3-Step Approach - Automated

~~~~ Mixture Models with Covariates and Distal Outcomes ~~~~ Structural Equation Modeling - Instructor: Karen Nylund-Gibson

Adam Garber

May 28, 2020

University of California, Santa Barbara

Figure. Picture has been adapted from study by Múthen, 2006.

Lab preparation

Creating a version-controlled R-Project with Github

Download repository here:

On the Github repository webpage:

  1. fork your own branch of the lab repository
  2. copy the repository web URL address from the clone or download menu

Within R-Studio:

  1. click “NEW PROJECT”
  2. choose option Version Control
  3. choose option Git
  4. paste the repository web URL path copied from the clone or download menu on Github page
  5. choose location of the R-Project

Data source:

  1. The first example utilizes a dataset on undergraduate Cheating available from the poLCA package (Dayton, 1998): \(\color{blue}{\text{See documentation here}}\)

  2. The second examples utilizes the public-use dataset, The Longitudinal Survey of American Youth (LSAY): \(\color{blue}{\text{See documentation here}}\)

Load packages

Incorparating distal outcome variables with mixture models

Note: Prior to adding covariates or distals enumeration must be conducted.

\(\color{blue}{\text{See Lab 7 for examples of enumeration with MplusAutomation}}\)

Manual 3-step

Integrate covariates and distals with a mixture model ____________________________________

End of manual 3-step

\(C_k\) as moderator

step3mod  <- mplusObject(
  TITLE = "Step3 - 3step LSAY - Lab9", 
  usevar = n;
  missing are all (999);
  classes = c(4);
  usevar = female mathg12;" ,
 "estimator = mlr; 
  type = mixture; 
  starts = 0;",
  !!!!!DISTAL = mathg12, COVARIATE = female, MODERATOR = C!!!!!
  mathg12 on female;

  mathg12 on female(s1);  ! conditional slope (class 1)
  [mathg12](m1);          ! conditional distal mean
  mathg12;                ! conditional distal variance (freely estimated)

  mathg12 on female(s2);
  mathg12 on female(s3);

  mathg12 on female(s4);
  mathg12; "),
   "New (slope12 slope13 slope23 
    slope14 slope24 slope34);
    slope12 = s1-s2;  ! test pairwise slope differences
    slope13 = s1-s3;
    slope23 = s2-s3;
    slope14 = s1-s4;
    slope24 = s2-s4;
    slope34 = s3-s4;",
  MODELTEST = " ! can run only a single Omnibus test per model 
  usevariables = colnames(savedata), 
  rdata = savedata)

step3mod_fit <- mplusModeler(step3mod,
               dataout=here("3step_mplus", "Step3_moderation_LSAY.dat"), 
               modelout=here("3step_mplus", "Step3_moderation_LSAY.inp"), 
               check=TRUE, run = TRUE, hashfilename = FALSE)


Drew A. Linzer, Jeffrey B. Lewis (2011). poLCA: An R Package for Polytomous Variable Latent Class Analysis. Journal of Statistical Software, 42(10), 1-29. URL

Hallquist, M. N., & Wiley, J. F. (2018). MplusAutomation: An R Package for Facilitating Large-Scale Latent Variable Analyses in Mplus. Structural equation modeling: a multidisciplinary journal, 25(4), 621-638.

Miller, J. D., Hoffer, T., Suchner, R., Brown, K., & Nelson, C. (1992). LSAY codebook. Northern Illinois University.

Muthén, B. O., Muthén, L. K., & Asparouhov, T. (2017). Regression and mediation analysis using Mplus. Los Angeles, CA: Muthén & Muthén.

Muthén, L.K. and Muthén, B.O. (1998-2017). Mplus User’s Guide. Eighth Edition. Los Angeles, CA: Muthén & Muthén

R Core Team (2017). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL

Wickham et al., (2019). Welcome to the tidyverse. Journal of Open Source Software, 4(43), 1686,