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

Model 1e: 1 moderator [BASIC MODERATION], dichotomous outcome (logistic regression)

Example Variables: 1 predictor X, 1 moderator W, 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 dichotomous and satisfies the assumptions of logistic regression.

 

Model Diagram:

 

Statistical Diagram:

 

Model Equation(s):

logit(Y) = b0 + b1X + b2W + b3XW

 

Algebra to calculate indirect and/or conditional effects by writing model as logit(Y) = a + bX:

logit(Y) = b0 + b1X + b2W + b3XW


Hence... grouping terms into form logit(Y) = a + bX

logit(Y) = (b0 + b2W) + (b1 + b3W)X


Hence...

One direct effect of X on logit(Y), conditional on W:

b1 + b3W


Hence, writing as an odds ratio...

The multiplicative effect of X on the odds of Y, conditional on W:

exp(b1 + b3W) = exp(b1)*exp(b3W)

 

Mplus code for the model:

! Predictor variable - X
! Mediator variable(s) (not applicable)
! Moderator variable(s) - W
! Outcome variable - Y - a dichotomous outcome, coded 0/1

USEVARIABLES = X W Y XW;

CATEGORICAL = Y;

! Create interaction term
! Note that it has to be placed at end of USEVARIABLES subcommand above

DEFINE:
   XW = X*W;

ANALYSIS:
   TYPE = GENERAL;
   ESTIMATOR = ML;

! In model statement name each path and intercept using parentheses

MODEL:
   [Y$1] (b0);
   Y ON X (b1);
   Y ON W (b2);
   Y ON XW (b3);

! Use model constraint subcommand to test simple slopes
! You need to pick low, medium and high moderator values,
! for example, of 1 SD below mean, mean, 1 SD above mean

MODEL CONSTRAINT:
   NEW(LOW_W MED_W HIGH_W OR_LO OR_MED OR_HI);

   LOW_W = #LOWW;   ! replace #LOWW in the code with your chosen low value of W
   MED_W = #MEDW;   ! replace #MEDW in the code with your chosen medium value of W
   HIGH_W = #HIGHW;   ! replace #HIGHW in the code with your chosen high value of W

! Now calc conditional odds ratios for each value of W

   OR_LO = exp(b1 + b3*LOW_W);
   OR_MED = exp(b1 + b3*MED_W);
   OR_HI = exp(b1 + b3*HIGH_W);

! Use loop plot to plot predicted probabilities by X
! conditional on low, med, high values of W

! 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(PLOMOD PMEDMOD PHIMOD);
   LOOP(XVAL,1,5,0.1);
   PLOMOD = 1/(1 + exp(-1*((b0 + b2*LOW_W) + (b1 + b3*LOW_W)*XVAL)));
   PMEDMOD = 1/(1 + exp(-1*((b0 + b2*MED_W) + (b1 + b3*MED_W)*XVAL)));
   PHIMOD = 1/(1 + exp(-1*((b0 + b2*HIGH_W) + (b1 + b3*HIGH_W)*XVAL)));

PLOT:
   TYPE = plot2;

OUTPUT:
   STAND;

 

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