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

Model 1a: 1 moderator [BASIC MODERATION], continuous moderator example

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 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 + b1X + b2W + b3XW

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

Y = b0 + b1X + b2W + b3XW

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

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

Hence...

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

b1 + b3W

Mplus code for the model:

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

USEVARIABLES = X 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 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 SIMP_LO SIMP_MED SIMP_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 simple slopes for each value of W

SIMP_LO = b1 + b3*LOW_W;
SIMP_MED = b1 + b3*MED_W;
SIMP_HI = b1 + b3*HIGH_W;

! Use loop plot to plot model 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 + b2*LOW_W) + (b1 + b3*LOW_W)*XVAL;
MEDMOD = (b0 + b2*MED_W) + (b1 + b3*MED_W)*XVAL;
HIMOD = (b0 + b2*HIGH_W) + (b1 + b3*HIGH_W)*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
STAND CINT(bcbootstrap);