Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes'
PROCESS analysis examples
Model 1c: 1 moderator [BASIC MODERATION], dichotomous moderator (using multigroup method)
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;
! Define groups of moderator W
GROUPING = W (0 = GP0 1 = GP1);
ANALYSIS:
TYPE = GENERAL;
ESTIMATOR = ML;
! In model statement first state basic regression that is being moderated
MODEL:
Y ON X;
! Then restate for each group, naming each group's intercept and slope coefficient
! and fixing residual variances equal
MODEL GP0:
[Y](b0g0);
Y ON X (b1g0);
Y (vary);
MODEL GP1:
[Y](b0g1);
Y ON X (b1g1);
Y (vary);
! Use model constraint subcommand to create and test difference in slopes
! Note that slopes for each group provide simple slopes tests already
MODEL CONSTRAINT:
NEW(b3);
b3 = b1g1  b1g0;
! 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(LINEGP0 LINEGP1);
LOOP(XVAL,1,5,0.1);
LINEGP0 = b0g0 + b1g0*XVAL;
LINEGP1 = b0g1 + b1g1*XVAL;
PLOT:
TYPE = plot2;
OUTPUT:
STAND CINT;
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
