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

Model 74: 1 or more mediators, in parallel if multiple (example uses 1), IV also moderates the Mediator-DV path

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 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'MX
M = a0 + a1X

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

Y = b0 + b1M + c1'X + c2'MX
M = a0 + a1X

Hence... substituting in equations for M

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

Hence... multiplying out brackets

Y = b0 + a0b1 + a1b1X + c1'X + a0c2'X + a1c2'XX

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

Y = (b0 + a1b1) + (a1b1 + c1' + a0c2' + a1c2'X)X

Hence...

Conditional Indirect effect of X on Y:

a1b1 + a1c2'X = a1*(b1 + c2'X)

Mplus code for the model:

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

USEVARIABLES = X M Y XM;

DEFINE:
XM = X*M;

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

! In model statement name each path using parentheses

MODEL:
Y ON M (b1);

Y ON X (cdash1);   ! direct effect of X on Y
Y ON XM (cdash2);

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

! Use model constraint to calculate indirect effect

MODEL CONSTRAINT:
NEW(LOW_X MED_X HIGH_X IND_LOWX IND_MEDX IND_HIX);

LOW_X = #LOWX;   ! replace #LOWX in the code with your chosen low value of X
MED_X = #MEDX;   ! replace #MEDX in the code with your chosen medium value of X
HIGH_X = #HIGHX;   ! replace #HIGHX in the code with your chosen high value of X

! Calc conditional indirect effects of X on Y via M for low, medium, high values of X

IND_LOWX = a1*b1 + a1*cdash2*LOW_X;
IND_MEDX = a1*b1 + a1*cdash2*MED_X;
IND_HIX = a1*b1 + a1*cdash2*HIGH_X;

! Use loop plot to plot conditional indirect effect of X on Y
! 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(INDX);

LOOP(XVAL,1,5,0.1);

INDX = (a1*b1 + a1*cdash2*XVAL)*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
STAND CINT(bcbootstrap);