Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 5: 1 or more mediators, in parallel if multiple, 1 moderator of direct IV-DV path only Example Variables: 1 predictor X, 1 mediator M, 1 moderator W, 1 outcome Y Preliminary notes: The code below assumes that
  Model Diagram: ![]()   Statistical Diagram: ![]()   Model Equation(s):
Y = b0 + b1M + c1'X + c2'W + c3'XW
 
Algebra to calculate indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1M + c1'X + c2'W + c3'XW
Y = b0 + b1(a0 + a1X) + c1'X + c2'W + c3'XW
Y = b0 + a0b1 + a1b1X + c1'X + c2'W + c3'XW
Y = (b0 + a0b1 + c2'W) + (a1b1 + c1' + c3'W)X
One indirect effect of X on Y:
a1b1
One direct effect of X on Y, conditional on W:
c1' + c3'W
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X M W Y XW;
! Create interaction term
DEFINE:
ANALYSIS:
! In model statement name each path and intercept using parentheses
MODEL:
   Y ON X (cdash1);
   [M] (a0);
! 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 effect - and conditional direct effects for each value of W
   a1b1 = a1*b1;
   DIR_LO = cdash1 + cdash3*LOW_W;
   TOT_LO = DIR_LO + a1b1;
! 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 = (b0 + a0*b1 + cdash2*LOW_W) + TOT_LO*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|