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

Model 4d: 1 or more mediators, in parallel if multiple (example uses 1) [BASIC MEDIATION], dichotomous 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
  • 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 dichotomous and satisfies the assumptions of binary logistic regression.

Model Diagram:

 

Statistical Diagram:

 

Model Equation(s):

logit(Y) = b0 + b1M + c'X
M = a0 + a1X

 

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

logit(Y) = b0 + b1M + c'X
M = a0 + a1X


Hence... substituting in equations for M

logit(Y) = b0 + b1(a0 + a1X) + c'X


Hence... multiplying out brackets

logit(Y) = b0 + a0b1 + a1b1X + c'X


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

logit(Y) = (b0 + a0b1) + (a1b1 + c')X


Hence...

Indirect effect of X on Y:

a1b1 - or, if expressed as an odds ratio, exp(a1b1)

Direct effect of X on Y:

c' - or, if expressed as an odds ratio, exp(c')

 

Mplus code for the model:

! Predictor variable - X
! Mediator variable(s) M
! Moderator variable(s) - none
! Outcome variable - Y

USEVARIABLES = X M Y;

CATEGORICAL = Y;

ANALYSIS:
   TYPE = GENERAL;
   ESTIMATOR = ML;

! In model statement name each path using parentheses

MODEL:
   Y ON M (b1);

   Y ON X (cdash);   ! direct effect of X on Y

   M ON X (a1);

! Use model constraint to calculate indirect effect, and odds ratio

MODEL CONSTRAINT:
   NEW(a1b1 ORa1b1);
   a1b1 = a1*b1;   ! Indirect effect of X on Y via M
   ORa1b1 = exp(a1*b1);   ! Odds ratio wrto indirect effect of X on Y via M

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

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

   MODEL INDIRECT:
   Y 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