Mplus code for mediation, moderation, and moderated mediation models

Model 2 (latent variable version): 2 moderators, 2-way interactions with predictor only

Example Variables: 1 latent predictor X measured by 4 observed variables X1-X4, 2 latent moderators W and Z, each measured by sets of 4 observed variables W1-W4 and Z1-Z4 respectively, 1 latent outcome Y measured by 4 observed variables Y1-Y4

Preliminary notes:

The code below assumes that

  • The latent IV (factor X) is measured by continuous observed variables X1-X4.
  • Any latent moderator(s) (factors W, V, Q, Z) are measured by continuous observed variables W1-W4, Z1-Z4, V1-V4, Q1-Q4 respectively.
  • Any latent mediator(s) (factor M, or factors M1, M2, etc.) are measured by continuous observed variables M1-M4 or M1_1-M1-4, M2_1-M2_4 respectively.
  • The latent outcome Y is measured by continuous observed variables Y1-Y4.

 

Model Diagram (factor indicator variables omitted for space/clarity reasons):

 

Statistical Diagram (factor indicator variables omitted for space/clarity reasons):

 

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


Hence... grouping terms into form Y = a + bX

Y = (b0 + b2W + b3Z) + (b1 + b4W + b5Z)X


Hence...

One direct effect of X on Y, conditional on W and Z:

b1 + b4W + b5Z

 

Mplus code for the model:

! Latent predictor variable X measured by X1-X4
! Latent moderator variables W and Z, measured by W1-W4 and Z1-Z4 respectively
! Latent outcome variable Y measured by Y1-Y4

USEVARIABLES = X1 X2 X3 X4
W1 W2 W3 W4 Z1 Z2 Z3 Z4
Y1 Y2 Y3 Y4;

ANALYSIS:
   TYPE = GENERAL RANDOM;
   ESTIMATOR = ML;
   ALGORITHM = INTEGRATION;

! In model statement first state measurement model
! Then create any latent interactions required
! Then state structural model naming each path and intercept using parentheses

MODEL:

! Measurement model
! Identify moderator factor by fixing variance = 1 (instead of first loading)
! This makes this factor standardised
   X BY X1 X2 X3 X4;
   W BY W1* W2 W3 W4;
   Z BY Z1* Z2 Z3 Z4;
   Y BY Y1 Y2 Y3 Y4;

   W@1;   Z@1;

! Create latent interactions
   XW | X XWITH W;
   XZ | X XWITH Z;

! Fit structural model and name parameters
! Note that intercept of Y is fixed = 0 since they are latent vars
! so no code to state and name them as parameters
   Y ON X (b1);
   Y ON W (b2);
   Y ON Z (b3);
   Y ON XW (b4);
   Y ON XZ (b5);

! Use model constraint subcommand to test simple slopes
! You need to pick low, medium and high moderator values for both W and Z,
! for example, of 1 SD below mean, mean, 1 SD above mean

! Since we have standardised factors, this is simple - use moderator values of -1, 0, 1 !

! 2 moderators, 3 values for each, gives 9 combinations
! arbitrary naming convention for simple slopes used below:
! MEW_LOZ = medium value of W and low value of Z, etc.

MODEL CONSTRAINT:
   NEW(LOW_W MED_W HIGH_W LOW_Z MED_Z HIGH_Z LOW_LOZ MEW_LOZ HIW_LOZ
   LOW_MEZ MEW_MEZ HIW_MEZ LOW_HIZ MEW_HIZ HIW_HIZ);

   LOW_W = -1;   ! -1 SD below mean of W
   MED_W = 0;   ! mean of W
   HIGH_W = 1;   ! +1 SD below mean of W

   LOW_Z = -1;   ! -1 SD below mean of Z
   MED_Z = 0;   ! mean of Z
   HIGH_Z = 1;   ! +1 SD below mean of Z

! Now calc simple slopes for each value of W and Z

   LOW_LOZ = b1 + b4*LOW_W + b5*LOW_Z;
   MEW_LOZ = b1 + b4*MED_W + b5*LOW_Z;
   HIW_LOZ = b1 + b4*HIGH_W + b5*LOW_Z;

   LOW_MEZ = b1 + b4*LOW_W + b5*MED_Z;
   MEW_MEZ = b1 + b4*MED_W + b5*MED_Z;
   HIW_MEZ = b1 + b4*HIGH_W + b5*MED_Z;

   LOW_HIZ = b1 + b4*LOW_W + b5*HIGH_Z;
   MEW_HIZ = b1 + b4*MED_W + b5*HIGH_Z;
   HIW_HIZ = b1 + b4*HIGH_W + b5*HIGH_Z;

! Use loop plot to plot total effects of X on Y for low, med, high values of W
! NOTE - values from -3 to 3 in LOOP() statement since
! X is factor with mean set at default of 0

   PLOT(PLOW_LOZ PMEW_LOZ PHIW_LOZ PLOW_MEZ PMEW_MEZ PHIW_MEZ
   PLOW_HIZ PMEW_HIZ PHIW_HIZ);

   LOOP(XVAL,-3,3,0.1);

   PLOW_LOZ = LOW_LOZ*XVAL;
   PMEW_LOZ = MEW_LOZ*XVAL;
   PHIW_LOZ = HIW_LOZ*XVAL;

   PLOW_MEZ = LOW_MEZ*XVAL;
   PMEW_MEZ = MEW_MEZ*XVAL;
   PHIW_MEZ = HIW_MEZ*XVAL;

   PLOW_HIZ = LOW_HIZ*XVAL;
   PMEW_HIZ = MEW_HIZ*XVAL;
   PHIW_HIZ = HIW_HIZ*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

Home
Statistical Consultancy
Data Management
Public Training Courses
Inhouse & Bespoke Training
Links & Resources
About Us & Contact Details