Mediation and moderation? PreviousNext
Mplus Discussion > Structural Equation Modeling >
 mw posted on Tuesday, September 11, 2012 - 1:26 am
I'm all new to this and not particularly good! But I need to test a path model. I've got to grips with testing mediation, but now need to put a moderator in the model. I've trawled through some guides but still confused, I really just need some code to do it in Mplus.

I'm better with visuals rather than trying to explain it, so have provided my model here...
 Bengt O. Muthen posted on Tuesday, September 11, 2012 - 7:12 am
One good approach is to let your moderator variable E be a grouping variable in a multiple-group mediation model. The User's Guide has several examples of multiple-group models.
 mw posted on Tuesday, September 11, 2012 - 10:47 am
Thank you for your reply. I really do want to keep the moderator as a continuous variable though and not split it. Is there a way of running the model without multiple groups?
 Bengt O. Muthen posted on Tuesday, September 11, 2012 - 11:08 am
Then you have to think about how your moderator of the M ->Y relationship might interact with M (and X, Y). You have an interaction between your moderator and your mediator. Interactions involving DVs (the mediator in your case) may pose special analysis issues - for instance, the chi-square test of model fit is off because the variance of Y conditional on X and your moderator is not constant.
 mw posted on Tuesday, September 11, 2012 - 12:10 pm
I've had a look at the preacher and hayes mplus code for a similar kind of analysis (I think it is anyway!)assuming w is the moderator and m is the mediator

y on m x w mw;
m on x;
w with m;
mw with m;

Would that be suitable, if I just added a few more 'x' variables to recreate my model?

I suppose you are saying I need to work out if the moderator affects the A B and C variables in my model (pictured above) as well.

To that I'm not really sure! It should correlate, but can I just specify that it will or will I end up in a huge over/non-identified mess?
 Kristopher J. Preacher posted on Tuesday, September 11, 2012 - 11:37 pm
This code should work. It is a model in which the 'b' path is moderated by z, and it contains 3 x variables.

TITLE: moderated mediation with 3 x's;
DATA: FILE IS mplus.help3.dat;
VARIABLE: NAMES ARE x1-x3 m z y;
DEFINE: mz=m*z;
MODEL: y ON m x1-x3 z mz; m ON x1-x3;
m WITH z mz; x1-x3;

You would need to include a MODEL CONSTRAINT section that computes the conditional indirect effects that are of interest, but this is the basic model syntax.
 mw posted on Wednesday, September 12, 2012 - 6:26 am
Thank you! I'll run it and see!
 mw posted on Sunday, September 16, 2012 - 12:54 pm
I've decided to change my mediator to a latent variable. Will the above code be the same? or do I have to create/define the interaction differently with a latent variable.

I've read something about XWITH (?) but not sure how I'd include that in Prof. Preacher's code above.
 Linda K. Muthen posted on Sunday, September 16, 2012 - 3:52 pm
Use XWITH to create the latent variable interaction and include it on the right-hand side of ON as shown above.
 marlies  posted on Wednesday, April 17, 2013 - 10:10 am
Dear drs. Muthen,

I have a question about a model with one moderation and a mediation, which is also moderated. This is my full model, with dependent variable y, predictor x, mediator m and second level moderator z.

s1 | y ON x ;
s2 | m ON x;
y ON m;

y m s1 s2 ON

y m s1 s2 WITH y m s1 s2 ;

In this model, the cross-level interaction between x and z on y is not signficant and neither is the cross-level interaction effect of x and z on m.

However, if I take out the interaction of x and z on m, so I run this model:

s1 | y ON x ;
y ON m;
m ON x;

y s1 ON z;

y WITH s1;

then suddenly the interaction of x and z on y is significant (the p value changes from a non-significant 0.28 to a significant 0.047). However, it cannot have turned significant due to the mediation of m, since there was no interaction effect of x and z on m.

Could it be that testing my full path model (so with both interaction effects)is statistically not okay?

Thank you in advance for your answer!

Kind regards,

 Bengt O. Muthen posted on Wednesday, April 17, 2013 - 12:29 pm
I think your full model is correctly done. When you change m ON x from random to fixed, that may well influence the random y ON x regression.

You may also want to try this out using Bayesian estimation to see how close to normal the posterior distributions are for the s ON z parameters; the Bayes results may be more trustworthy if they are not close to normal, as assumed with ML.
 marlies  posted on Wednesday, April 17, 2013 - 11:47 pm
Thank you for your quick answer!

Kind regards,
 Laura Giurge posted on Friday, May 01, 2015 - 7:39 am
Firstly, thank you again for the quick response! I am not a statistician so I am probably not expressing my thoughts well. Here is the model:

My aim and questions are whether it is possible to add a lower level moderation in a 2-1-1 model on the 1-1 path in Mplus and whether there are some examples of such models or models with lower level moderation only (I could not find this)? Below, I followed the syntax from Preacher et al. (2010, 2011) for the 2-1-1 model. I tried to add the lower level moderator and construct the indirect effects as in Model 3 (Preacher et al., 2007). The model below gave no errors in Mplus. I'm sharing it for learning purposes. I find this forum incredibly helpful in that respect!

Thank you!

USEVARIABLES = Id sqy gmx gmm gmw mw;
Missing are all (-99);
DEFINE: mw = gmm*gmw;
sb | sqy ON gmm;
mb | sqy ON mw;
sqy ON gmw;
gmm ON gmx(a);
sqy ON gmm(b);
sqy ON mw (b2);
sqy ON gmx (c);
sqy ON gmw;
[mb] (mbw);
NEW (bb indb bb2 indb2);
indb2=a* (b+bb2);
 Laura Giurge posted on Friday, May 01, 2015 - 7:43 am
I apologize for the above message! It was posted in the wrong forum. My sincere apologies.

 Bengt O. Muthen posted on Friday, May 01, 2015 - 3:58 pm
Ok; answered elsewhere.
 sharon posted on Monday, October 09, 2017 - 8:31 am
Hi everyone, i could really use some help for a moderation that i would like to try on Mplus, but i dont know how to code it. Does anyone have a syntax ? its a simple moderation analyse with x, m, and y.
Thanks again for your help!
 Bengt O. Muthen posted on Monday, October 09, 2017 - 10:33 am
See the Mplus runs starting at Table 2.25 for our Regression and Mediation book which are posted at
Back to top
Add Your Message Here
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Options: Enable HTML code in message
Automatically activate URLs in message