Moderated mediation PreviousNext
Mplus Discussion > Structural Equation Modeling >
 Student 09 posted on Monday, January 16, 2012 - 4:33 am

using the multiple group analysis in Mplus, I would like to test whether an indirect effect differs between two subsamples (group a & group b).

For each group, I requested the indirect effect by using the model constraint command.


y2 ON y1 (p1a);
y1 ON x (p2a);

NEW (ind_1);
Ind_1 = p1a*p2a;

MODEL group b:

y2 ON y1 (p1b);
y1 ON x (p2b);

NEW (ind_2);
Ind_2 = p1b*p2b;

This syntax yields the two indirect effects (ind_1 & ind_2). But now I wonder how to test their difference – how would I constrain these parameters to be equal, given that they come from two different groups?
 Bengt O. Muthen posted on Monday, January 16, 2012 - 11:03 am
You should use a Model Constraint where you define their difference - this will give you the test as a z score:

NEW (ind_1 ind_2 diff);
ind_1 = p1a*p2a;
ind_2 = p1b*p2b;
diff = ind_1-ind_2;
 Lisa M. Yarnell posted on Thursday, March 29, 2012 - 3:16 pm

Can I run a moderated mediation analysis as a two-group model, employing the MODEL INDIRECT command?

In other words, can MODEL INDIRECT be used in conjunction with a grouping variable, allowing for tests of moderated mediation?

 Linda K. Muthen posted on Thursday, March 29, 2012 - 5:00 pm
You can run moderated mediation using multiple group analysis but you can't use MODEL INDIRECT. You will need to use MODEL CONSTRAINT to compare indirect effects across groups. MODEL INDIRECT does not have this function.
 Valerie Simon posted on Sunday, July 01, 2012 - 8:51 am
How do I test whether multiple indirect effects differ between 2 groups? The model includes paths from 2 Xs (ext2, stigma2) through a single mediator (ai_t) to 2 DV's (VDATE, PDATE).

I used the model constraint language as per Bengt's response above to create the 4indirect diffs...
ai_t on ext_pt2 (a1a);
ai_t on STIGMA2 (a2a);
PDATE on ai_t (b1a);
VDATE on ai_t (b2a);
ai_t on ext_pt2 (a1b);
ai_t on STIGMA2 (a2b);
PDATE on ai_t (b1b);
VDATE on ai_t (b2b);
NEW (ind_1 ind_2 diff);
ind_1 = a1a*b1a;
ind_2 = a1b*b1b;
diff = ind_1-ind_2;
NEW (ind_3 ind_4 diff);
ind_3 = a2a*b1a;
ind_4= a2b*b1b;
diff = ind_3-ind_4;
NEW (ind_5 ind_6 diff);
ind_5 = a1a*b2a;
ind_6 = a1b*b2b;
diff = ind_5-ind_6;
NEW (ind_7 ind_8 diff);
ind_7 = a2a*b2a;
ind_8 = a2b*b2b;
diff = ind_7-ind_8;

Mplus will run a single constraint test but when I include more than one I get an error message saying that I've entered an already used parameter. Although true, each indirect is comprised of unique pairs of parameters. Is there a way to simultaneous test differences in the 4 indirect effects?
 Linda K. Muthen posted on Sunday, July 01, 2012 - 10:48 am
Please send your output and license number to
 Lisa M. Yarnell posted on Monday, March 25, 2013 - 10:55 pm

In using the MODEL CONSTRAINT option to define new parameters for one's model, does this increase the number of parameters estimated and hence affect degrees of freedom?

A five-knownclass model in which I used MODEL CONSTRAINT to define an a*b indirect path (to test for mediation) had different degrees of freedom than I expected, and I wondered if this is because I added parameters to the model through using this command?

 Linda K. Muthen posted on Tuesday, March 26, 2013 - 11:36 am
If you put a constraint on a parameter in MODEL CONSTRAINT, this can affect the degrees of freedom. If you define a new parameter, this should not.
 Lisa M. Yarnell posted on Tuesday, March 26, 2013 - 3:16 pm
Thanks, Linda. Can I label parameters that are class-specific estimates in a knownclass model, then use those class-specific labels to constrain parameters within classes? For example--would this work?

[gender] (gen_m_w);
gender (gen_v_w);

[gender] (gen_m_cn);
gender (gen_v_cn);

gen_v_w = gen_m_w*(1-gen_m_w);
gen_v_cn = gen_m_cn*(1-gen_m_cn);
 Linda K. Muthen posted on Wednesday, March 27, 2013 - 6:44 am
Yes, you can label class-specific parameters.
 Allison Elledge posted on Thursday, February 13, 2014 - 11:17 am
Hi Dr. Muthen,

Similar to Student09 in Jan 2012 of this thread, I am interested in testing whether an indirect effect differs between two groups.

On Jan 16 2012, you wrote:

You should use a Model Constraint where you define their difference - this will give you the test as a z score:

NEW (ind_1 ind_2 diff);
ind_1 = p1a*p2a;
ind_2 = p1b*p2b;
diff = ind_1-ind_2;

I ran my model with this syntax, but I want to be sure that I am looking in the right place in the output and interpreting correctly. My understanding is that I should be looking at the third and fourth columns of the model results section, under "New/additional parameters." This section of my output looks like this:

New/Additional Parameters
INDIRECT 0.003 0.024 0.144 0.885
INDIRECT 0.001 0.065 0.010 0.992
DIFF 0.003 0.069 0.039 0.969

My understanding is that for DIFF, Est./S.E = 0.039 and p = .969, meaning that the population means are equal across groups. This would mean that the indirect effect is not moderated by the variable I used to group (weight status). Am I interpreting this correctly? Thank you!
 Bengt O. Muthen posted on Friday, February 14, 2014 - 11:50 am
That's correct. One cannot reject that the two indirect effects are equal.
 Allison Elledge posted on Saturday, February 22, 2014 - 6:44 am
Thank you for your response. As a follow up question related to my model, I found partial measurement invariance across gender in my initial invariance testing (at the weak level). Once freeing one parcel loading on my independent latent variable, the chi sq diff tests held for weak and strong invariance. My understanding is that I would need to free this loading across gender groups in my structural model. However, I am already specifying two groups for my moderated mediation analyses. Can I also specify two separate groups by gender to account for that partial measurement invariance? If so, what would that syntax look like? And how would that change my interpretation of model fit and the diff score created to determine moderation? Thank you!
 Bengt O. Muthen posted on Saturday, February 22, 2014 - 3:58 pm
Sounds like you would then have 4 groups (2 x 2). In which case you can e.g. specify gender-invariance of the slopes involved in the moderated mediation. Just label the parameters according to the equalities you want to specify.
 Allison Elledge posted on Friday, May 02, 2014 - 2:07 pm
Is there a way to determine probability of finding group differences in a multiple group analysis, post-hoc? I ran a moderated mediation model using a multiple group analysis and did not find significant moderation. This may be because one group only had 29 participants in it, compared to 95 in the other. I am wondering if I can determine the probability of detecting group differences, given the numbers that I had? Thank you!
 Bengt O. Muthen posted on Friday, May 02, 2014 - 4:19 pm
You can do a Monte Carlo simulation - see the UG chapter 12. This would give you an idea of the power to reject equality.
 Shiny posted on Tuesday, August 26, 2014 - 7:48 am
I d like to follow up with this discussion. I understand that when difference test Shows insignificant p value, it means the indirect effects are equal. Is the difference test in mplus a heterogenity test in its nature?

I checked some statistical mateirals. Some researchers used a relatively subjective approach, comparing the Mediation sizes (the coefficients) or simply look at whether the indirect effects are full v.s parital v.s non effects in different groups. They sometimes skipped the difference test. or they consider the Group difference existed (e.g., when full Mediation in one Group and partial in another), although in the difference test result p is not significant. I would love to get a comment from Dr. Muthen.
 Bengt O. Muthen posted on Tuesday, August 26, 2014 - 3:33 pm
Q1. I don't know what a heterogeneity test is in this context.

I think it is good to carry out a test.
 ri ri  posted on Saturday, September 06, 2014 - 12:24 am
To compare two indirect effects, I ran the difference test. In one Group I have a Mediation effect, in the other Group, there is no Mediation effect. However, difference test showed no difference, because p>.05. I wonder how could that be?

New/Additional Parameters
ind1 -0.657 0.311 -2.113 0.035
ind2 -0.567 0.397 -1.427 0.153
diff -0.090 0.505 -0.179 0.858

I guess the difference of the Parameters is small (.090), thus it gives a big p value? Can I Report the indirect effects differ across groups? Does it only make sense, to conduct a difference test when indirect effects exist in both Groups? Maybe in my case, when in one Group there is no indrect effect, I do not Need a difference test?
 Bengt O. Muthen posted on Saturday, September 06, 2014 - 10:50 am
I think it is natural that if ind2 is not significantly different from zero, the ind2-ind1 difference is not significantly different from zero - the latter distance is smaller. I would report all 3 findings.
 ri ri  posted on Saturday, September 06, 2014 - 11:05 am
Thank you for your answer! I will Report all the findings as you suggested. But can I still say, there is a moderated Mediation because the Mediation effects are not the same in two Groups.

may I ask the statistical Background of the ind1 - ind2? I think I read somewhere this is a z score test?I would like to also indicate in my paper what the difference test means in mplus. Thanks!
 Bengt O. Muthen posted on Monday, September 08, 2014 - 5:01 pm
If ind1 and ind2 are not significantly different you can't say that you have moderated mediation.

The estimate/SE for "diff" is a Z-score.
 ri ri  posted on Friday, September 19, 2014 - 10:10 am
Thank you for the helpful Information. I am now summarizing the Analysis and Tools in my paper and want to add one sentence about difference test provided by mplus.

can I say: we used a z-score difference test in Mplus to test whether indirect effects vary across Groups. Or is there a more precise term to describe this difference test? It is good to get your expert view! Thanks!
 Linda K. Muthen posted on Saturday, September 20, 2014 - 6:54 am
It looks like you used MODEL CONSTRAINT to test the difference. The test of the difference is a z-score. There is nothing more to say.
 Meike Slagt posted on Thursday, May 07, 2015 - 6:30 am
Dear dr. Muthén,
I’m testing a moderated mediation model in which the association between an independent variable IV and a dependent variable DV is mediated by Med, and paths a and c are moderated by Mod. The moderation effect is represented by a product term (Int = IV*Mod). We used the following syntax:

DV on IV Mod Int;
DV on Med (b1);
Med on IV (a1);
Med on Mod;
Med on Int (a3);

new (indlow indmed indhigh indirect difind);

!indirect effect at low, medium, and high value of moderator (moderator is centered)
indmed=(a1+a3*0)*b1; !also represents indirect effect regardless of moderation

!total indirect effect
indirect =(a1+a3)*b1;

!difference between total indirect effect and indirect effect regardless of moderation
difind = indirect - indmed;

However, I get two error messages:
*** ERROR (A1+A3*-0.5) *B1 ^ERROR
*** ERROR in MODEL CONSTRAINT command A parameter label has been redeclared in MODEL CONSTRAINT. Problem with: INDMED

So there seems to be a problem with the way I define new variables in the MODEL CONSTRAINT command. What am I specifying wrongly here? Thank you for your help!
 Bengt O. Muthen posted on Thursday, May 07, 2015 - 10:06 am
Try changing



 Meike Slagt posted on Thursday, May 07, 2015 - 1:08 pm
Thank you, that get's rid of the first warning. The second warning still remains, however:
*** ERROR in MODEL CONSTRAINT command. A parameter label has been redeclared in MODEL CONSTRAINT. Problem with: INDMED

If I remove all the syntax pertaining to INDMED, the warning persists, but then starts blaming another new variable, INDIRECT.
 Bengt O. Muthen posted on Thursday, May 07, 2015 - 1:50 pm
Then we need to see the output - send to support along with license number.
 ri ri  posted on Monday, May 11, 2015 - 8:50 am
I did a difftest using MODEL CONSTRAINT.Is there a Name for the estimate coefficient?

Here is an example of my result:

DIFF2 -0.117 0.548 -0.214 0.830

I want to Report what -.0117 represents for.

I understand the difftest is a z-score test, but is it possible to get a z value in difftest?

 Linda K. Muthen posted on Monday, May 11, 2015 - 10:53 am
The DIFF2 parameter is what you specified in MODEL CONSTRAINT. The third column is the z-test.
 Tennisha Riley posted on Thursday, October 08, 2015 - 9:41 am
I am having trouble with conducting a moderated mediation similar to user (student09). My two groups are gender (1 = male 2= female). Could you take look to see what I may be doing incorrectly?

variable: names =....
usevariables = Gender...;
missing = all(-999);
grouping = Gender (1=Male 2=Female);

analysis: type = general;


X by...
Y2 on Y1(b1_Male) X;
Y1 on X (b2_Male);

model constraint:

New (ind_Male);
ind_Male = b1_Male*b2_Male;

X by...
Y2 on Y1(b1_Female) X;
Y1 on X (b2_Female);

model constraint:
New (ind_Female);
ind_Male = b1_Female*b2_Female;

model test:
ind_Male = ind_Female;

Below is the error I am getting.

The following parameter label is ambiguous. Check that the corresponding
parameter has not been changed. Parameter label: B1_MALE

Why would this parameter be ambiguous? Would I need to define the parameter first? Do I need to instead include the direct effect coefficients from my non-grouping analysis? I am unsure of whether this parameter is "made up" or defined in some way.
 Linda K. Muthen posted on Thursday, October 08, 2015 - 11:56 am
Please send the full output and your license number to
 Jayoung Gong posted on Wednesday, November 25, 2015 - 3:44 am
I'd like to know if this syntax is right to investigate my model. X is the predictor, Y is the outcome, M is the mediation, W and Z are the moderations.X->M is moderated by W, and M->Y is moderated by Z.

My syntax is like below.


X BY g1-g6;
W BY i1-i2;
M BY c1-c3;
Z BY s1-s2;
Y BY j1-j2;

M ON X(a1)

Y ON M(b1)

NEW(ind1 ind2);


Is this right for moderated mediation model?
 Bengt O. Muthen posted on Wednesday, November 25, 2015 - 10:09 am
For observed variables you would not use XWITH but instead use DEFINE to create the product.
 Jayoung Gong posted on Wednesday, November 25, 2015 - 5:59 pm
Thank you for the answer.
in my model, there are all continuous variables. I assume they are all latent variables. (I use "BY" for them.)

I'm quite confused if I need to use "DEFINE" instead of "XWITH" in this case.
 Bengt O. Muthen posted on Thursday, November 26, 2015 - 6:11 pm
Sorry, I missed that you had X, M, Y latent. Yes, your input looks correct.
 Ofer Eldad posted on Sunday, May 27, 2018 - 12:27 pm
Hi Dr. Muthen,

In moderated mediation, can I test the significant of the difference between two indirect effects through simple subtraction when the outcome is dichotomous in cross-classified data?

Meaning, can I still use the following?
diff = ind1 - ind2;

In general I am a bit confused as to how to calculate terms of interest in mplus given a dichotomous outcome. For example, when calculating indirect effect, should I go with
ind = a*b;
or is it more appropriate to approach it as an odds ratio
ind = exp(a*b);

Many thanks,
 Bengt O. Muthen posted on Sunday, May 27, 2018 - 5:59 pm
Binary Y in mediation modeling needs special considerations. See our Topic 11 Short Course handout and YouTube video at
 Ofer Eldad posted on Monday, June 04, 2018 - 9:11 pm
Thanks for the response.
I saw the lecture and read more about using counterfactually-defined indirect effect.

Am I correct that I cannot find the indirect effect through multiple mediators for binary outcome through "model indirect"?
Is there an alternative way to do this?

 Ofer Eldad posted on Monday, June 04, 2018 - 9:22 pm
In addition, any suggestion on how to approach the problem when the data is crossclassified?

That is, any way to compute the counterfactually-defined indirect effect for cross classified data with a binary outcome?
 Bengt O. Muthen posted on Tuesday, June 05, 2018 - 5:07 pm
9:11 post:

Q1: right

Q2: How to do it in Mplus is shown in the article

Nguyen, T.Q., Webb-Vargas, Y., Koning, I.K. & Stuart, E.A. (2016). Causal mediation analysis with a binary outcome and multiple continuous or ordinal mediators: Simulations and application to an alcohol intervention. Structural Equation Modeling: A Multidisciplinary Journal, 23:3, 368-383 DOI: 10.1080/10705511.2015.1062730
 Tihomir Asparouhov posted on Tuesday, June 05, 2018 - 5:41 pm
If you are using a cross-classified model, the potential outcome based approach has to be conditioned on both clustering effects. That is because the random effects would influence the computation of the indirect effect. You can use the factor scores if you decide to go that route but you will have to compute this for every pair of clusters from the two crossed-nesting levels. You might consider using the simpler approach from Chapter 2 in the Regression and Mediation Analysis book.
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