Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 501: 1 mediator, multiple focal predictors Example Variables: 2 predictors X1, X2, 1 mediator M, 1 outcome Y Preliminary notes: The code below assumes that
Model Diagram:
Statistical Diagram:
Model Equation(s): Y = b0 + b1M + c1'X1 + c2'X2;
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX: Y = b0 + b1M + c1'X1 + c2'X2;
Y = b0 + b1(a0 + a1X1 + a2X2) + c1'X1 + c2'X2
Y = b0 + a0b1 + a1b1X1 + a2b1X2 + c1'X1 + c2'X2
Y = (b0 + a0b1) + (a1b1 + c1')X1 + (a2b1 + c2')X2
Indirect effect of X1 on Y: a1b1 Indirect effect of X2 on Y: a2b1 Direct effect of X1 on Y: c1' Direct effect of X2 on Y: c2'
Mplus code for the model:
! Predictor variables  X1, X2
USEVARIABLES = X1 X2 M Y; ANALYSIS:
! In model statement name each path using parentheses MODEL:
Y ON X1 (cdash1); ! direct effect of X1 on Y
M ON X1 (a1);
! Use model constraint to calculate indirect and total effects MODEL CONSTRAINT:
OUTPUT:
Editing required for testing indirect effect(s) using alternative MODEL INDIRECT: subcommand MODEL INDIRECT: offers an alternative to MODEL CONSTRAINT: for models containing indirect effects, where these are not moderated. To use MODEL INDIRECT: instead, you would edit the code above as follows: First, you can remove the naming of parameters using parentheses in the MODEL: command, i.e. you just need: MODEL:
Second, replace the MODEL CONSTRAINT: subcommand with the following MODEL INDIRECT: subcommand: MODEL INDIRECT:
Leave the OUTPUT: command unchanged.
Return to Model Template index. To cite this page and/or any code used, please use:







