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

Model 502: 1 mediator, multiple focal predictors

Example Variables: 1 predictor X, 1 mediator M, 2 outcomes Y1, Y2

Preliminary notes:

The code below assumes that

  • The primary IV (variable X) is continuous or dichotomous
  • The mediator (variable M) is continuous. An example of how to handle a dichotomous mediator is given in model 4c.
  • The DVs (variables Y1, Y2) are 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):

Y1 = b0 + b1M + c1'X;
Y2 = b0 + b2M + c2'X;
M = a0 + a1X;

 

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

Y1 = b0 + b1M + c1'X;
Y2 = b0 + b2M + c2'X;
M = a0 + a1X;


Hence... substituting in equations for M

Y1 = b0 + b1(a0 + a1X) + c1'X;
Y2 = b0 + b2(a0 + a1X) + c2'X;


Hence... multiplying out brackets

Y1 = b0 + a0b1 + a1b1X1 + c1'X1
Y2 = b0 + a0b2 + a1b2X1 + c2'X1


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

Y1 = (b0 + a0b1) + (a1b1 + c1')X1
Y1 = (b0 + a0b2) + (a1b2 + c2')X1


Hence...

Indirect effect of X on Y1:

a1b1

Indirect effect of X on Y2:

a1b2

Direct effect of X on Y1:

c1'

Direct effect of X on Y2:

c2'

 

Mplus code for the model:

! Predictor variables - X
! Mediator variable(s) M
! Moderator variable(s) - none
! Outcome variable - Y1, Y2

USEVARIABLES = X1 M Y1 Y2;

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

! In model statement name each path using parentheses

MODEL:
   Y1 ON M (b1);
   Y2 ON M (b2);

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

   M ON X (a1);

! Use model constraint to calculate indirect and total effects

MODEL CONSTRAINT:
   NEW(a1b1 a1b2 TOTALY1 TOTALY2);
   a1b1 = a1*b1;   ! Indirect effect of X on Y1 via M
   a1b2 = a1*b2;   ! Indirect effect of X on Y2 via M
   TOTALY1 = a1*b1 + cdash1;   ! Total effect of X on Y1
   TOTALY2 = a1*b2 + cdash2;   ! Total effect of X on Y2

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:
   Y1 ON X M;
   Y2 ON X M;
   M ON X;

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

   MODEL INDIRECT:
   Y1 IND X;
   Y2 IND X;

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