Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 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
  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
Y = (b0 + b2W) + (b1 + b3W)X
One direct effect of X on Y, conditional on W:
b1 + b3W
so inserting the values of 0 and 1 for moderator W gives....
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X W Y XW;
! Create interaction term
DEFINE:
ANALYSIS:
! In model statement name each path and intercept using parentheses
MODEL:
! Use model constraint subcommand to test simple slopes
MODEL CONSTRAINT:
   LOW_W = 0;
! Now calc simple slopes for each value of W
   SIMP_LO = b1 + b3*LOW_W;
! Use loop plot to plot model for low, med, high values of W
   PLOT(LOMOD HIMOD);
PLOT:
OUTPUT:
If you are feeling confident you could simplify the MODEL CONSTRAINT code to:
MODEL CONSTRAINT:
! Use loop plot to plot model for values of W = 0, W = 1
   PLOT(MOD0 MOD1);
   LOOP(XVAL,1,5,0.1);
   MOD0 = b0 + b1*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|