Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examples

Model 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

  • The primary IV (variable X) is continuous or dichotomous
  • Any moderators (variables W, V, Q, Z) are continuous, though the only adaptation required to handle dichotomous moderators is in the MODEL CONSTRAINT: and loop plot code - an example of how to do this is given in model 1b. Handling categorical moderators with > 2 categories is demonstrated in model 1d.
  • Any mediators (variable M, or M1, M2, etc.) are continuous and satisfy the assumptions of standard multiple regression. An example of how to handle a dichotomous mediator is given in model 4c.
  • The DV (variable Y) is continuous and satisfies the assumptions of standard multiple regression. An example of how to handle a dichotomous DV is given in model 1e (i.e. a moderated logistic regression) and in model 4d (i.e. an indirect effect in a logistic regression).

Model Diagram:

 

Statistical Diagram:

 

Model Equation(s):

Y = b0 + b1M + c1'X + c2'XX
M = a0 + a1X + a2XX

 

Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:

Y = b0 + b1M + c1'X + c2'XX
M = a0 + a1X + a2XX


Hence... differentiating each equation to calculate the rates of change in the DV wrto the IV(s)

dY/dX = c1' + 2c2'X
dY/dM = b1
dM/dX = a1 + 2a2X


Hence... multiplying the relationships between X and M, and M and Y to get the indirect effect:

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
! Mediator variable(s) – M
! Moderator variable(s) - none
! Outcome variable - Y

USEVARIABLES = X XX M Y;

ANALYSIS:
   TYPE = GENERAL;
   ESTIMATOR = ML;
   BOOTSTRAP = 10000;

! In model statement name each path using parentheses

MODEL:
   Y ON M (b1);

   Y ON X (cdash1);   ! direct effect of X on Y
   Y ON XX (cdash2);   ! direct effect of X on Y

   M ON X (a1);
   M ON XX (a2);

! Use model constraint to calculate instantaneous indirect and direct effects
! at different values of X

MODEL CONSTRAINT:
   NEW(LOW_X MED_X HIGH_X
   IIE_LOWX IIE_MEDX IIE_HIX
   IDE_LOWX IDE_MEDX IDE_HIX);

    LOW_X = #LOWX;   ! replace #LOWX in the code with your chosen low value of X
    MED_X = #MEDX;   ! replace #MEDX in the code with your chosen medium value of X
    HIGH_X = #HIGHX;   ! replace #HIGHX in the code with your chosen high value of X

! Calc instantaneous indirect effects for low, medium, high values of X

    IIE_LOWX = (a1 + 2*a2*LOW_X)*b1;
    IIE_MEDX = (a1 + 2*a2*MED_X)*b1;
    IIE_HIX = (a1 + 2*a2*HIGH_X)*b1;

! Calc instantaneous direct effects for low, medium, high values of X

    IDE_LOWX = cdash1 + 2*cdash2*LOW_X;
    IDE_MEDX = cdash1 + 2*cdash2*MED_X;
    IDE_HIX = cdash1 + 2*cdash2*HIGH_X;

! Use loop plot to plot instantaneous indirect effect of X on Y
! NOTE - values of 1,5 in LOOP() statement need to be replaced by
! logical min and max limits of predictor X used in analysis

    PLOT(IIEX);

    LOOP(XVAL,1,5,0.1);

    IIEX = (a1*b1 + 2*a2*b1*XVAL)*XVAL;

PLOT:
   TYPE = plot2;

OUTPUT:
   STAND CINT(bcbootstrap);

 

Return to Model Template index.

To cite this page and/or any code used, please use:
Stride, C.B., Gardner, S., Catley, N. & Thomas, F.(2015) 'Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examples', http://www.offbeat.group.shef.ac.uk/FIO/mplusmedmod.htm

Home
Statistical Consultancy
Data Management
Public Training Courses
Inhouse & Bespoke Training
Links & Resources
About Us & Contact Details