Mplus code for mediation, moderation, and moderated mediation modelsModel 89: 2 or more mediators in series, 1 moderator, moderating the direct IV-DV path, the first mediator-DV path, and the second mediator-DV path Example Variables: 1 predictor X, 2 mediators M1 and M2, 1 moderator W, 1 outcome Y Preliminary notes: The code below assumes that
  Model Diagram: ![]()   Statistical Diagram: ![]()   Model Equation(s):
Y = b0 + b1M1 + b2M2 + b3W + b4M1W + b5M2W + c1'X + c2'W + c3'XW
 
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1M1 + b2M2 + b3M1W + b4M2W + c1'X + c2'W + c3'XW
Y = b0 + b1(a01 + a1X) + b2(a02 + a2X + d1(a01 + a1X)) + b3(a01 + a1X)W + b4(a02 + a2X + d1(a01 + a1X))W + c1'X + c2'W + c3'XW
Y = b0 + a01b1 + a1b1X + a02b2 + a2b2X + a01d1b2 + a1d1b2X + a01b3W + a1b3XW +
a02b4 + a2b4X + a01d1b4W + a1d1b4XW + c1'X + c2'W + c3'XW
Y = (b0 + a01b1 + a02b2 + a01d1b2 + a01b3W + a02b4 + a01d1b4W + c2'W) + (a1b1 + a2b2 + a2b4W + a1d1b2 + a1b3W + a1d1b4W + c1' + c3'W)X
Three indirect effects of X on Y, conditional on W:
a1(b1 + b3W), a2(b2 + b4W), a1d1(b2 + b4W)
One direct effect of X on Y:
c1' + c3'W
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X M1 M2 W Y XW M1W M2W;
! Create interaction term
DEFINE:
ANALYSIS:
! In model statement name each path using parentheses
MODEL:
   Y ON X (cdash1);
   M1 ON X (a1);
   M2 ON X (a2);
! Use model constraint subcommand to test simple slopes
MODEL CONSTRAINT:
   LOW_W = #LOWW;   ! replace #LOWW in the code with your chosen low value of W
! Now calc indirect and total effects for each value of W
! Conditional indirect effects of X on Y via M1 only given values of W
   LWa1b1 = a1*b1 + a1*b3*LOW_W;
! Conditional indirect effects of X on Y via M2 only given values of W
   LWa2b2 = a2*b2 + a2*b4*LOW_W;
! Conditional indirect effects of X on Y via M1 and M2 given values of W
   LWa1d1b2 = a1*d1*b2 + a1*d1*b4*LOW_W;
! Indices of Moderated Mediation
   IMM_A = a1*b3;
! Conditional direct effects of X on Y given values of W
   DIR_LW = cdash1 + cdash3*LOW_W;
! Conditional total effects of X on Y given values of W
   TOT_LOWW = LWa1d1b2 + LWa2b2 + LWa1b1 + DIR_LW;
! Use loop plot to plot total effect of X on Y for low, med, high values of W
   PLOT(LOMOD MEDMOD HIMOD);
   LOOP(XVAL,1,5,0.1);
   LOMOD = TOT_LOWW*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|