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

Model 1b: 1 moderator [BASIC MODERATION], dichotomous moderator

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
• The moderator (variable W) is dichotomous. 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

so inserting the values of 0 and 1 for moderator W gives....

when W = 0, Y = b0 + b1X; when W = 1, Y = (b0 + b2) + (b1 + b3)X

Mplus code for the model:

! Predictor variable - X
! Mediator variable(s) – (not applicable)
! Moderator variable(s) - W, dichotomous, coded 0/1
! 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 insert your two moderator values, 0 and 1

MODEL CONSTRAINT:
NEW(LOW_W HIGH_W SIMP_LO SIMP_HI);

LOW_W = 0;
HIGH_W = 1;

! Now calc simple slopes for each value of W

SIMP_LO = b1 + b3*LOW_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 HIMOD);
LOOP(XVAL,1,5,0.1);
LOMOD = (b0 + b2*LOW_W) + (b1 + b3*LOW_W)*XVAL;
HIMOD = (b0 + b2*HIGH_W) + (b1 + b3*HIGH_W)*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
STAND CINT(bcbootstrap);

If you are feeling confident you could simplify the MODEL CONSTRAINT code to:

MODEL CONSTRAINT:
NEW(SIM_MOD0 SIM_MOD1);
SIM_MOD0 = b1;
SIM_MOD1 = b1 + b3;

! Use loop plot to plot model for values of W = 0, W = 1
! 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(MOD0 MOD1);

LOOP(XVAL,1,5,0.1);

MOD0 = b0 + b1*XVAL;
MOD1 = (b0 + b2) + (b1 + b3)*XVAL;

PLOT:
TYPE = plot2;

OUTPUT:
STAND CINT(bcbootstrap);