Mplus code for mediation, moderation, and moderated mediation modelsModel 80 (latent variable version): 3 or more mediators, both in parallel and in series Example Variables: 1 latent predictor X measured by 4 observed variables X1X4, 3 latent mediators M1, M2, and M3, , each measured by 4 observed variables M1_1M1_4, M2_1M2_4, and M3_1M3_4 respectively, 1 latent outcome Y measured by 4 observed variables Y1Y4 Preliminary notes: The code below assumes that
Model Diagram:
Statistical Diagram:
Model Equation(s): Y = b0 + b1M1 + b2M2 + b3M3 + c'X
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX: Y = b0 + b1M1 + b2M2 + b3M3 + c'X
Y = b0 + b1(a01 + a1X) + b2(a02 + a2X) + b3M3 + c'X
Y = b0 + b1(a01 + a1X) + b2(a02 + a2X) + b3(a03 + a3X + d1(a01 + a1X) + d2(a02 + a2X)) + c'X
Y = b0 + a01b1 + a1b1X + a02b2 + a2b2X + a03b3 + a3b3X + a01d1b3 + a1d1b3X + a02d2b3 + a2d2b3X + c'X
Y = (b0 + a01b1 + a02b2 + a03b3 + a01d1b3 + a02d2b3) + (a1b1 + a2b2 + a3b3 + a1d1b3 + a2d2b3 + c')X
Five indirect effects of X on Y: a1b1, a2b2, a3b3, a1b3d1, a2b3d2 One direct effect of X on Y: c'
Mplus code for the model:
! Latent predictor variable X measured by X1X4
USEVARIABLES = X1 X2 X3 X4 M1_1 M1_2 M1_3 M1_4 M2_1 M2_2 M2_3 M2_4 M3_1 M3_2 M3_3 M3_4 Y1 Y2 Y3 Y4; ANALYSIS:
! In model statement first state measurement model MODEL:
! Fit structural model and name parameters
Y ON X (cdash); ! direct effect of X on Y M1 ON X (a1);
M3 ON M1 (d1);
! Use model constraint to calculate specific indirect paths and total indirect effect
MODEL CONSTRAINT:
OUTPUT:
Editing required for testing indirect effect using alternative MODEL INDIRECT: subcommand MODEL INDIRECT: offers an alternative to MODEL CONSTRAINT: for models containing indirect effects, where these are not moderated. To instead use MODEL INDIRECT: to test this model, you would edit the code above as follows: First, you can remove the naming of parameters using parentheses in the MODEL: command, i.e. you just need: MODEL:
Second, replace the MODEL CONSTRAINT: subcommand with the following MODEL INDIRECT: subcommand: MODEL INDIRECT:
Leave the OUTPUT: command unchanged.
Return to Model Template index. To cite this page and/or any code used, please use:







