Mplus code for mediation, moderation, and moderated mediation models

Model 4a (latent variable version): 1 mediator [BASIC MEDIATION]

Example Variables: 1 latent predictor X measured by 4 observed variables X1-X4; 1 latent mediators M, measured by 4 observed variables M1-M4, 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 + b1M + c'X
M = a0 + a1X

 

Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX:

Y = b0 + b1M + c'X
M = a0 + a1X


Hence... substituting in equations for M

Y = b0 + b1(a0 + a1X) + c'X


Hence... multiplying out brackets

Y = b0 + a0b1 + a1b1X + c'X


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

Y = (b0 + a0b1) + (a1b1 + c')X


Hence...

Indirect effect of X on Y:

a1b1

Direct effect of X on Y:

c'

 

Mplus code for the model:

! Latent predictor variable X measured by X1-X4
! Latent mediator variable M, measured by M1-M4
! Latent outcome variable Y measured by Y1-Y4

USEVARIABLES = X1 X2 X3 X4 M1 M2 M3 M4 Y1 Y2 Y3 Y4;

ANALYSIS:
   TYPE = GENERAL;
   ESTIMATOR = ML;
   BOOTSTRAP = 10000;

! In model statement first state measurement model
! Then state structural model naming each path and intercept using parentheses

MODEL:

! Measurement model
   X BY X1 X2 X3 X4;
   M BY M1 M2 M3 M4;
   Y BY Y1 Y2 Y3 Y4;

! Fit structural model and name parameters
   [Y] (b0);
   Y ON M (b1);

   Y ON X (cdash);   ! direct effect of X on Y

   M ON X (a1);

! Use model constraint to calculate indirect and total effects

MODEL CONSTRAINT:
   NEW(a1b1 TOTAL);
   a1b1 = a1*b1;   ! Indirect effect of X on Y via M
   TOTAL = a1*b1 + cdash;   ! Total effect of X on Y

OUTPUT:
   STAND CINT(bcbootstrap);

 

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:
   Y ON X M;
   M ON X;

Second, replace the MODEL CONSTRAINT: subcommand with the following MODEL INDIRECT: subcommand:

   MODEL INDIRECT:
   Y IND X;

Leave the OUTPUT: command unchanged.

 

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