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

Model 501: 1 mediator, multiple focal predictors

Example Variables: 2 predictors X1, X2, 1 mediator M, 1 outcome Y

Preliminary notes:

The code below assumes that

  • The primary IVs (variables X1, X2) are continuous or dichotomous
  • The mediator (variable M) is continuous. 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'X1 + c2'X2;
M = a0 + a1X1 + a2X2;

 

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

Y = b0 + b1M + c1'X1 + c2'X2;
M = a0 + a1X1 + a2X2;


Hence... substituting in equations for M

Y = b0 + b1(a0 + a1X1 + a2X2) + c1'X1 + c2'X2


Hence... multiplying out brackets

Y = b0 + a0b1 + a1b1X1 + a2b1X2 + c1'X1 + c2'X2


Hence... grouping terms into form Y = a + bX

Y = (b0 + a0b1) + (a1b1 + c1')X1 + (a2b1 + c2')X2


Hence...

Indirect effect of X1 on Y:

a1b1

Indirect effect of X2 on Y:

a2b1

Direct effect of X1 on Y:

c1'

Direct effect of X2 on Y:

c2'

 

Mplus code for the model:

! Predictor variables - X1, X2
! Mediator variable(s) M
! Moderator variable(s) - none
! Outcome variable - Y

USEVARIABLES = X1 X2 M Y;

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

! In model statement name each path using parentheses

MODEL:
   Y ON M (b1);

   Y ON X1 (cdash1);   ! direct effect of X1 on Y
   Y ON X2 (cdash2);   ! direct effect of X2 on Y

   M ON X1 (a1);
   M ON X2 (a2);

! Use model constraint to calculate indirect and total effects

MODEL CONSTRAINT:
   NEW(a1b1 a2b1 TOTALX1 TOTALX2);
   a1b1 = a1*b1;   ! Indirect effect of X1 on Y via M
   a2b1 = a2*b1;   ! Indirect effect of X2 on Y via M
   TOTALX1 = a1*b1 + cdash1;   ! Total effect of X1 on Y
   TOTALX2 = a2*b1 + cdash2;   ! Total effect of X2 on Y

OUTPUT:
   STAND CINT(bcbootstrap);

 

Editing required for testing indirect effect(s) using alternative MODEL INDIRECT: subcommand

MODEL INDIRECT: offers an alternative to MODEL CONSTRAINT: for models containing indirect effects, where these are not moderated. To use MODEL INDIRECT: instead, you would edit the code above as follows:

First, you can remove the naming of parameters using parentheses in the MODEL: command, i.e. you just need:

MODEL:
   Y ON X1 X2 M;
   M ON X1 X2;

Second, replace the MODEL CONSTRAINT: subcommand with the following MODEL INDIRECT: subcommand:

   MODEL INDIRECT:
   Y IND X1;
   Y IND X2;

Leave the OUTPUT: command unchanged.

 

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