Mplus code for mediation, moderation, and moderated mediation modelsModel 2 (latent variable version): 2 moderators, 2-way interactions with predictor only Example Variables: 1 latent predictor X measured by 4 observed variables X1-X4, 2 latent moderators W and Z, each measured by sets of 4 observed variables W1-W4 and Z1-Z4 respectively, 1 latent outcome Y measured by 4 observed variables Y1-Y4 Preliminary notes: The code below assumes that
  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 + + b3Z + b4XW + b5XZ
 
Algebra to calculate indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ
Y = (b0 + b2W + b3Z) + (b1 + b4W + b5Z)X
One direct effect of X on Y, conditional on W and Z:
b1 + b4W + b5Z
 
Mplus code for the model:
! Latent predictor variable X measured by X1-X4
USEVARIABLES = X1 X2 X3 X4
ANALYSIS:
! In model statement first state measurement model
MODEL:
! Measurement model
   W@1;   Z@1;
! Create latent interactions
! Fit structural model and name parameters
! Use model constraint subcommand to test simple slopes
! Since we have standardised factors, this is simple - use moderator values of -1, 0, 1 !
! 2 moderators, 3 values for each, gives 9 combinations
MODEL CONSTRAINT:
   LOW_W = -1;   ! -1 SD below mean of W
   LOW_Z = -1;   ! -1 SD below mean of Z
! Now calc simple slopes for each value of W and Z
   LOW_LOZ = b1 + b4*LOW_W + b5*LOW_Z;
   LOW_MEZ = b1 + b4*LOW_W + b5*MED_Z;
   LOW_HIZ = b1 + b4*LOW_W + b5*HIGH_Z;
! Use loop plot to plot total effects of X on Y for low, med, high values of W
   PLOT(PLOW_LOZ PMEW_LOZ PHIW_LOZ PLOW_MEZ PMEW_MEZ PHIW_MEZ
   LOOP(XVAL,-3,3,0.1);
   PLOW_LOZ = LOW_LOZ*XVAL;
   PLOW_MEZ = LOW_MEZ*XVAL;
   PLOW_HIZ = LOW_HIZ*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|