Mplus code for the mediation, moderation, and moderated mediation model templates from Andrew Hayes' PROCESS analysis examplesModel 1e: 1 moderator [BASIC MODERATION], dichotomous outcome (logistic regression) 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):
logit(Y) = b0 + b1X + b2W + b3XW
 
Algebra to calculate indirect and/or conditional effects by writing model as logit(Y) = a + bX:
logit(Y) = b0 + b1X + b2W + b3XW
logit(Y) = (b0 + b2W) + (b1 + b3W)X
One direct effect of X on logit(Y), conditional on W:
b1 + b3W
The multiplicative effect of X on the odds of Y, conditional on W:
exp(b1 + b3W) = exp(b1)*exp(b3W)
 
Mplus code for the model:
! Predictor variable - X
USEVARIABLES = X W Y XW;
CATEGORICAL = Y;
! 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 = #LOWW;   ! replace #LOWW in the code with your chosen low value of W
! Now calc conditional odds ratios for each value of W
   OR_LO = exp(b1 + b3*LOW_W);
! Use loop plot to plot predicted probabilities by X
   PLOT(PLOMOD PMEDMOD PHIMOD);
PLOT:
OUTPUT:
 
Return to Model Template index.
To cite this page and/or any code used, please use:
|
|
|
|
|
|
|
|