Mplus Syntax
quantpsy.org
© 2010-2024,
Kristopher J. Preacher

Mplus syntax to accompany models and analyses in:

Rhemtulla, M., Schoemann, A. M., & Preacher, K. J. (2011). A multilevel SEM approach to examine dyadic correlations. Paper presented at the Modern Modeling Methods (M3) conference, Storrs, CT.

Schoemann, A. M., Rhemtulla, M., & Preacher, K. J. (2011). Investigating correlations for exchangeable dyads using multilevel structural equation modeling. Poster presented at the New Methods Preconference of the 12th annual Meeting of the Society for Personality and Social Psychology, San Antonio, TX.

Mplus syntax for single level model for dyads with 2 variables (X,Y).

    TITLE: Schoemann, Rhemtulla, & Preacher (2011) Single-level SEM;

    DATA: FILE IS "SingleDyads.dat";

    VARIABLE: NAMES ARE x1a x1b x2a x2b;

    ANALYSIS: MODEL IS NOCOVARIANCES;

    MODEL:

    !set up residual variance terms for indicators with paths estimated rather than variances.
    ea1 BY x1a*(e1);
    ea2 BY x2a*(e2);
    eb1 BY x1b*(e1);
    eb2 BY x2b*(e2);

    ea1@1; ea2@1; eb1@1; eb2@1;

    !fix residuals at 0 so mplus doesn't make its own residual variance terms: 
    x1a@0; x2a@0; x1b@0; x2b@0;

    ea1 WITH ea2*(ri);
    eb1 WITH eb2*(ri);

    ! set up latent factors that reflect shared variance between a and b
    ! paths are fixed to be equal, variance is fixed at 1 
    x1 by x1a*(l1);
    x1 by x1b*(l1);

    x2 by x2a*(l2);
    x2 by x2b*(l2);

    ! fix variances at 1. 
    x1@1; x2@1; 

    x1 WITH x2*;
    [x1 x2];
    [x1a@0 x1b@0 x2a@0 x2b@0];

    !have Mplus estimate SDs and ICCs as parameters: 
    MODEL CONSTRAINT: NEW(sdx1 sdx2 iccx1 iccx2);

    l1=sdx1*sqrt(iccx1); e1=sdx1*sqrt(1-iccx1);
    l2=sdx2*sqrt(iccx2); e2=sdx2*sqrt(1-iccx2);

Mplus syntax for MSEM model for dyads with 2 variables (X,Y).

    TITLE: Schoemann, Rhemtulla, & Preacher (2011) MSEM;

    DATA: FILE IS "MSEMDyads.dat";
    !note that data must be in long format

    VARIABLE: NAMES ARE x y dyad; CLUSTER IS dyad;

    ANALYSIS: TYPE IS TWOLEVEL;

    MODEL:

    %WITHIN%
    Xw BY x*(a); x@0; Xw@1;
    Yw BY y*(b); y@0; Yw@1;
    Xw WITH Yw*;

    %BETWEEN%
    Xb BY x*(c); x@0; Xb@1;
    Yb BY y*(d); y@0; Yb@1;
    Xb WITH Yb*;
    [Xb Yb x@0 y@0];

    MODEL CONSTRAINT: NEW(sdx sdy iccx*.502 iccy*.442);
    a=sdx*sqrt(1-iccx); c=sdx*sqrt(iccx);
    b=sdy*sqrt(1-iccy); d=sdy*sqrt(iccy);