Mplus code for mediation, moderation, and moderated mediation modelsModel 504: 3 or more mediators, both in parallel and in series, 2 moderators, 1 moderating paths between predictor and mediator, the second moderating paths between mediators, and between mediator and DV Example Variables: 1 predictor X, 3 mediators M1, M2, and M3, 2 moderators W, V, 1 outcome Y Preliminary notes: The code below assumes that
  Model Diagram: ![]()   Statistical Diagram: ![]()   Model Equation(s):
Y = b0 + b1M1 + b2M2 + b3M3 + b4V + b5M1V + c'X
 
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1M1 + b2M2 + b3M3 + b4V + b5M1V + c'X
Y = Y = b0 + b1(a01 + a1X + a4W + a5XW) + b2(a02 + a2X) + b3M3 + b4V + b5(a01 + a1X + a4W + a5XW)V + c'X
Y = b0 + b1(a01 + a1X + a4W + a5XW) + b2(a02 + a2X) + b3(a03 + a3X + d1(a01 + a1X + a4W + a5XW) + d2(a02 + a2X) + d3V + d4(a01 + a1X + a4W + a5XW)V) + b4V + b5(a01 + a1X + a4W + a5XW)V + c'X
Y = b0 + a01b1 + a1b1X + a4b1W + a5b1XW + a02b2 + a2b2X + a03b3 + a3b3X + a01d1b3 + a1d1b3X + a4d1b3W + a5d1b3XW + a02d2b3 + a2d2b3X + b3d3V + a01d4b3V + a1d4b3XV + a4d4b3WV + a5d4b3XWV + b4V + a01b5V + a1b5XV + a4b5WV + a5b5XWV + c'X
Y = (b0 + a01b1 + a4b1W + a02b2 + a03b3 + a01d1b3 + a4d1b3W + a02d2b3 + b3d3V + a01d4b3V + a4d4b3WV + b4V + a01b5V + a4b5WV) + (a1b1 + a5b1W + a2b2 + a3b3 + a1d1b3 + a5d1b3W + a2d2b3 + a1d4b3V + a5d4b3WV + a1b5V + a5b5WV + c')X
Five indirect effects of X on Y:
a1b1 + a5b1W + a1b5V + a5b5WV, a2b2, a3b3, a2d2b3, a1b3d1 + a5d1b3W + a1d4b3V + a5d4b3WV
One direct effect of X on Y:
c'
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X M1 M2 M3 W V Y XW M1V;
ANALYSIS:
! In model statement name each path using parentheses
MODEL:
   Y ON X (cdash);   ! direct effect of X on Y
   M1 ON X (a1);
   M3 ON M1 (d1);
! 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
   LOW_V = #LOWV;   ! replace #LOWV in the code with your chosen low value of V
! Now calc specific indirect effects for each value of W and V
   a2b2 = a2*b2;
   a3b3 = a3*b3;
   a2d2b3 = a2*d2*b3;
   adbLWLV = a1*d1*b3 + a5*d1*b3*LOW_W + a1*d4*b3*LOW_V + a5*d4*b3*LOW_W*LOW_V;
! Now calc total indirect effects for each value of W and V
! Now calc total effects for each value of W and V
! Use loop plot to plot total indirect effect of X on Y for low, med, high values of W
   PLOT(PTI_LWLV PTI_MWLV PTI_HWLV PTI_LWMV PTI_MWMV PTI_HWMV
   LOOP(XVAL,1,5,0.1);
   PTI_LWLV = TI_LWLV*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|