Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 74: 1 or more mediators, in parallel if multiple (example uses 1), IV also moderates the Mediator-DV path Example Variables: 1 predictor X, 1 mediator M, 1 outcome Y Preliminary notes: The code below assumes that
Model Diagram: ![]()   Statistical Diagram: ![]()   Model Equation(s):
Y = b0 + b1M + c1'X + c2'MX
 
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1M + c1'X + c2'MX
Y = b0 + b1(a0 + a1X) + c1'X + c2'(a0 + a1X)X
Y = b0 + a0b1 + a1b1X + c1'X + a0c2'X + a1c2'XX
Y = (b0 + a1b1) + (a1b1 + c1' + a0c2' + a1c2'X)X
Conditional Indirect effect of X on Y:
a1b1 + a1c2'X = a1*(b1 + c2'X)
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X M Y XM;
DEFINE:
ANALYSIS:
! In model statement name each path using parentheses
MODEL:
   Y ON X (cdash1);   ! direct effect of X on Y
   [M] (a0);
! Use model constraint to calculate indirect effect
MODEL CONSTRAINT:
    LOW_X = #LOWX;   ! replace #LOWX in the code with your chosen low value of X
! Calc conditional indirect effects of X on Y via M for low, medium, high values of X
    IND_LOWX = a1*b1 + a1*cdash2*LOW_X;
! Use loop plot to plot conditional indirect effect of X on Y
    PLOT(INDX);
    LOOP(XVAL,1,5,0.1);
    INDX = (a1*b1 + a1*cdash2*XVAL)*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|