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

Model 5: 1 or more mediators, in parallel if multiple, 1 moderator of direct IV-DV path only

Example Variables: 1 predictor X, 1 mediator M, 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 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'W + c3'XW
M = a0 + a1X

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

Y = b0 + b1M + c1'X + c2'W + c3'XW
M = a0 + a1X

Hence... substituting in equation for M

Y = b0 + b1(a0 + a1X) + c1'X + c2'W + c3'XW

Hence... multiplying out brackets

Y = b0 + a0b1 + a1b1X + c1'X + c2'W + c3'XW

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

Y = (b0 + a0b1 + c2'W) + (a1b1 + c1' + c3'W)X

Hence...

One indirect effect of X on Y:

a1b1

One direct effect of X on Y, conditional on W:

c1' + c3'W

Mplus code for the model:

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

USEVARIABLES = X M W Y XW;

! 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;
BOOTSTRAP = 10000;

! In model statement name each path and intercept using parentheses

MODEL:
[Y] (b0);
Y ON M (b1);

Y ON X (cdash1);
Y ON W (cdash2);
Y ON XW (cdash3);

[M] (a0);
M ON X (a1);

! 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
! Also calc total effects at lo, med, hi values of moderator

MODEL CONSTRAINT:
NEW(LOW_W MED_W HIGH_W a1b1 DIR_LO DIR_MED DIR_HI TOT_LO TOT_MED TOT_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 indirect effect - and conditional direct effects for each value of W

a1b1 = a1*b1;

DIR_LO = cdash1 + cdash3*LOW_W;
DIR_MED = cdash1 + cdash3*MED_W;
DIR_HI = cdash1 + cdash3*HIGH_W;

TOT_LO = DIR_LO + a1b1;
TOT_MED = DIR_MED + a1b1;
TOT_HI = DIR_HI + a1b1;

! Use loop plot to plot total effect of X on Y for 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(LOMOD MEDMOD HIMOD);

LOOP(XVAL,1,5,0.1);

LOMOD = (b0 + a0*b1 + cdash2*LOW_W) + TOT_LO*XVAL;
MEDMOD = (b0 + a0*b1 + cdash2*MED_W) + TOT_MED*XVAL;
HIMOD = (b0 + a0*b1 + cdash2*HIGH_W) + TOT_HI*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
STAND CINT(bcbootstrap);