Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 2: 2 moderators, 2-way interactions with predictor only Example Variables: 1 predictor X, 2 moderators W, Z, 1 outcome Y Preliminary notes: The code below assumes that
  Model Diagram: ![]()   Statistical Diagram: ![]()   Model Equation(s):
Y = b0 + b1X + b2W + + b3Z + b4XW + b5XZ
 
Algebra to calculate indirect and/or conditional effects by writing model as Y = a + bX:
Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ
Y = (b0 + b2W + b3Z) + (b1 + b4W + b5Z)X
One direct effect of X on Y, conditional on W and Z:
b1 + b4W + b5Z
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X W Y XW XZ;
! Create interaction terms
DEFINE:
ANALYSIS:
! In model statement name each path, and intercept, using parentheses
MODEL:
! Use model constraint subcommand to test simple slopes
! 2 moderators, 3 values for each, gives 9 combinations
MODEL CONSTRAINT:
   LOW_W = #LOWW;   ! replace #LOWW in the code with your chosen low value of W
   LOW_Z = #LOWZ;   ! replace #LOWZ in the code with your chosen low value of Z
! Now calc simple slopes for each value of W and Z
   LOW_LOZ = b1 + b4*LOW_W + b5*LOW_Z;
   LOW_MEZ = b1 + b4*LOW_W + b5*MED_Z;
   LOW_HIZ = b1 + b4*LOW_W + b5*HIGH_Z;
! Use loop plot to plot model for all combinations of low, med, high values of W and Z
   PLOT(PLOW_LOZ PMEW_LOZ PHIW_LOZ PLOW_MEZ PMEW_MEZ PHIW_MEZ
   LOOP(XVAL,1,5,0.1);
   PLOW_LOZ = (b0 + b2*LOW_W + b3*LOW_Z) + LOW_LOZ*XVAL;
   PLOW_MEZ = (b0 + b2*LOW_W + b3*MED_Z) + LOW_MEZ*XVAL;
   PLOW_HIZ = (b0 + b2*LOW_W + b3*HIGH_Z) + LOW_HIZ*XVAL;
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|