 ## Mplus code for mediation, moderation, and moderated mediation models

Model 1a (latent variable version): 1 moderator [BASIC MODERATION]

Example Variables: 1 latent predictor X measured by 4 observed variables X1-X4, 1 latent moderator W measured by 4 observed variables W1-W4, 1 latent outcome Y measured by 4 observed variables Y1-Y4

Preliminary notes:

The code below assumes that

• The latent IV (factor X) is measured by continuous observed variables X1-X4.
• Any latent moderator(s) (factors W, V, Q, Z) are measured by continuous observed variables W1-W4, Z1-Z4, V1-V4, Q1-Q4 respectively.
• Any latent mediator(s) (factor M, or factors M1, M2, etc.) are measured by continuous observed variables M1-M4 or M1_1-M1-4, M2_1-M2_4 respectively.
• The latent outcome Y is measured by continuous observed variables Y1-Y4.

Model Diagram (factor indicator variables omitted for space/clarity reasons): Statistical Diagram (factor indicator variables omitted for space/clarity reasons): Model Equation(s):

Y = b0 + b1X + b2W + b3XW

Algebra to calculate indirect and/or conditional effects by writing model as Y = a + bX:

Y = b0 + b1X + b2W + b3XW

Hence... grouping terms into form Y = a + bX

Y = (b0 + b2W) + (b1 + b3W)X

Hence...

One direct effect of X on Y, conditional on W:

b1 + b3W

Mplus code for the model:

! Latent predictor variable X measured by X1-X4
! Latent moderator W measured by W1-W4
! Latent outcome variable Y measured by Y1-Y4

USEVARIABLES = X1 X2 X3 X4
W1 W2 W3 W4
Y1 Y2 Y3 Y4;

ANALYSIS:
TYPE = GENERAL RANDOM;
ESTIMATOR = ML;
ALGORITHM = INTEGRATION;

! In model statement first state measurement model
! Then create any latent interactions required
! Then state structural model naming each path and intercept using parentheses

MODEL:

! Measurement model
! This makes this factor standardised
X BY X1 X2 X3 X4;
W BY W1* W2 W3 W4;
Y BY Y1 Y2 Y3 Y4;

W@1;

! Create latent interactions
XW | X XWITH W;

! Fit structural model and name parameters
! Note that intercept of Y is fixed = 0 since they are latent vars
! so no code to state and name them as parameters
Y ON X (b1);
Y ON W (b2);
Y ON XW (b3);

! Use model constraint subcommand to test simple slopes
! You need to pick low, medium and high moderator values,
! for example, of 1 SD below mean, mean, 1 SD above mean

! Since we have standardised factors, this is simple - use moderator values of -1, 0, 1 !

MODEL CONSTRAINT:
NEW(LOW_W MED_W HIGH_W SIMP_LO SIMP_MED SIMP_HI);

LOW_W = -1;   ! -1 SD below mean of W
MED_W = 0;   ! mean of W
HIGH_W = 1;   ! +1 SD below mean of W

! Now calc simple slopes for each value of W

SIMP_LO = b1 + b3*LOW_W;
SIMP_MED = b1 + b3*MED_W;
SIMP_HI = b1 + b3*HIGH_W;

! Use loop plot to plot total effects of X on Y for low, med, high values of W
! NOTE - values from -3 to 3 in LOOP() statement since
! X is factor with mean set at default of 0

PLOT(LOMOD MEDMOD HIMOD);
LOOP(XVAL,-3,3,0.1);
LOMOD = (b1 + b3*LOW_W)*XVAL;
MEDMOD = (b1 + b3*MED_W)*XVAL;
HIMOD = (b1 + b3*HIGH_W)*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
CINT;