Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 503: 1 mediator, predictor has non-linear effect on mediator and outcome 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'XX
 
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1M + c1'X + c2'XX
dY/dX = c1' + 2c2'X
Instantaneous Indirect Effect (IIE) of X on Y:
(a1 + 2a2X)b1
And we also have the... Instantaneous Direct Effect (IDE) of X on Y:
c1' + 2c2'X
 
Mplus code for the model:
! Predictor variable(s) - X, XX
USEVARIABLES = X XX M Y;
ANALYSIS:
! In model statement name each path using parentheses
MODEL:
   Y ON X (cdash1);   ! direct effect of X on Y
   M ON X (a1);
! Use model constraint to calculate instantaneous indirect and direct effects
MODEL CONSTRAINT:
    LOW_X = #LOWX;   ! replace #LOWX in the code with your chosen low value of X
! Calc instantaneous indirect effects for low, medium, high values of X
    IIE_LOWX = (a1 + 2*a2*LOW_X)*b1;
! Calc instantaneous direct effects for low, medium, high values of X
    IDE_LOWX = cdash1 + 2*cdash2*LOW_X;
! Use loop plot to plot instantaneous indirect effect of X on Y
    PLOT(IIEX);
    LOOP(XVAL,1,5,0.1);
    IIEX = (a1*b1 + 2*a2*b1*XVAL)*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|