Mplus code for mediation, moderation, and moderated mediation modelsModel 4a (latent variable version): 1 mediator [BASIC MEDIATION] Example Variables: 1 latent predictor X measured by 4 observed variables X1X4; 1 latent mediators M, measured by 4 observed variables M1M4, 1 latent outcome Y measured by 4 observed variables Y1Y4 Preliminary notes: The code below assumes that
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
Algebra to calculate total, indirect and/or conditional effects by writing model as Y = a + bX: Y = b0 + b1M + c'X
Y = b0 + b1(a0 + a1X) + c'X
Y = b0 + a0b1 + a1b1X + c'X
Y = (b0 + a0b1) + (a1b1 + c')X
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 X1X4
USEVARIABLES = X1 X2 X3 X4 M1 M2 M3 M4 Y1 Y2 Y3 Y4; ANALYSIS:
! In model statement first state measurement model
MODEL: ! Measurement model
! Fit structural model and name parameters
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:
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:







