Plotting MLM interaction PreviousNext
Mplus Discussion > Multilevel Data/Complex Sample >
 Jaimee posted on Tuesday, May 27, 2014 - 4:01 pm
I am trying to figure out how to plot an interaction effect between 2 level 2 variables in a MLM. I am having a bit of trouble as I am getting confused with the syntax.

Here is what I have

CLUSTER = clus;
MxN = M*N;


MODEL: %within%
Y on C D;
Y on M (beta1)
N (beta2)

LOOP(moderate, 5, 28, 1);
Y = beta1+beta2* moderate;

The model constraint and naming of the pathways is where I am confused. I need a plot with Y on the Y axis, N as the moderator and M on the X axis.

Any help would be very much appreciated. Thanks very much.
 Bengt O. Muthen posted on Tuesday, May 27, 2014 - 6:18 pm
Take a look at how it is done for UG ex 3.18 as shown on our Mediation page:

Just translate that to your Between-level statements.
 Laura Giurge posted on Thursday, April 30, 2015 - 4:33 am
Hi, I have a related question to the above discussion. I am running a twolevel random model with random intercepts and slopes. I wish to plot the cross over interaction but I get an error message: ' Error in parsing line:"LOOP (MOD,-1,1,0.1)"'

Here is the full syntax:
Missing are all (-99);
BETWEEN = gmx;
WITHIN = gmw;
s | sqy ON gmw;
sqy ON gmx;
[s] (a);
s ON gmx (b);
sqy WITH s;
LOOP (mod, -1,1,0.1);
crosslv1 = a+b*mod;

I cannot figure out what am I doing wrong. Thanks a lot in advance!
 Bengt O. Muthen posted on Thursday, April 30, 2015 - 6:24 pm
You don't show a colon after CONSTRAINT.
 Laura Giurge posted on Friday, May 01, 2015 - 7:44 am
Professor Muthen, thank you so much for the quick response! It was a very sloppy mistake on my side.
 Stefan Kamin posted on Wednesday, October 25, 2017 - 9:02 am
Dear all,

I would like to plot an interaction between X and M within the level 1 equation. The model has one covariate at level 1 (cov1) and another one at level 2 (cov2). In addition, I am interested in the simple slopes at different values of M (0/1). I adapted the example from UG ex 3.18 and would like to know whether my syntax is accurate:

s_x | y on x;
s_m | y on m;
s_xm | y on xm;
s_cov1 | y on cov1;

[y] (b0);
[s_x] (b1);
[s_m] (b2);
[s_xm] (b3);
y on cov2;
y with s_x s_m s_xm;

Model Constraint:
SS1 = b0 + b1*x + b3*0*x + b2*0;
SS2 = b0 + b1*x + b3*1*x + b2*1;

SS1 = b1+b3*(0);
SS2 = b1+b3*(1);

Thank you very much!
 Bengt O. Muthen posted on Wednesday, October 25, 2017 - 11:01 am
The syntax looks correct.
 S REN posted on Friday, February 23, 2018 - 3:29 am
Hi, could I ask how to create the xm IN mplus 9.2 EXAMPLE.
I don't really understand that 'The observed cluster-level covariate xm takes the value of the mean of x for each cluster'.

Does this mean
xm = (the group mean of X) * m

Or does this mean
xm = (groupmean centering X) * m

Thank you.
 S REN posted on Friday, February 23, 2018 - 3:55 am
Hi a follow-up question is for the example 9.2 in the UserGuide as below

is X (as specified as the within level) referring to the raw data of X?
Or is X (as specified as the within level) referring to the group mean centered raw data of X? Thanks.

VARIABLE: NAMES = y x w xm clus; WITHIN = x; BETWEEN = w xm; CLUSTER = clus;
 Bengt O. Muthen posted on Friday, February 23, 2018 - 4:38 pm
First post:

xm refers to "the x mean", that is what can be obtained using the Cluster_Mean option.

Second post:

x is the group-mean centered raw data of the observed x variable. This is what the Center x(groupmean) statement in the Define command accomplishes.
 S REN posted on Saturday, February 24, 2018 - 9:32 am
Much appreciated@
 Laura Froehlich posted on Friday, September 28, 2018 - 1:51 am
Dear all,

I am interested in a model containing an interaction between two L1-predictors and one L2-predictor. This is the model:

within = x w xw;
between = z;

y on x w;
s| y on xw;

y on z;
s on z;
y with s;

How can I plot the interaction and calculate simple slopes adapting the input from example 9.2b? I would like to calculate slopes for low/ high values of w and z.

Thank you.
 Bengt O. Muthen posted on Friday, September 28, 2018 - 11:09 am
Do you mean that you are interested in a 3-way interaction between x,w, and z?
 Laura Froehlich posted on Friday, September 28, 2018 - 11:51 am
yes, exactly.
 Bengt O. Muthen posted on Friday, September 28, 2018 - 1:09 pm
You can just play with the regression equations for your model:

y = a_j + b1*x + b2*w + b3_j*w + error

a_j = a + g1*z + error

b3_j = b + g2*z + error

Here a_j is your random intercept which appears as Y on Between and b3_j is your random slope s in the regression of y on the xw interaction. Plugging the last 2 equations into the first, you have

y = a + g1*z + b1*x + b2*w + (b + g2*z)*xw + error terms,

where the terms involving x can be summarized as

[b1 + (b + g2*z)*w]*x.

That would be the simple slope that can be evaluated as a function of x for different combinations of values of z and w - but you better check that I did the algebra right. This can be done like the plot of ex 9.2b where you just have a different simple slope formula as given above and you have not only 2 expressions you want to plot but perhaps 4 (low/high z combined with low/high w).
 Laura Froehlich posted on Friday, September 28, 2018 - 1:23 pm
Dear Prof. Muthen,

that is exactly what I was looking for, thank you very much!
 Silvia posted on Tuesday, October 30, 2018 - 6:12 am
Dear Prof. Muthen,

as in the previous post, I need to estimate the simple slopes for a three way interaction between x, w (both level 1) and z (level 2). I would like to know whether my syntax is accurate in labeling the terms for the simple slope formula you suggested ([b1 + (b + g2*z)*w]*x).

Y on X (b1);
Y on W C1 C2;
s | Y ON XW;

Y on Z;
[s] (b);
s on Z (g2);
y with s;

Thank you
 Bengt O. Muthen posted on Tuesday, October 30, 2018 - 5:11 pm
This looks correct.
 Timothy Allen posted on Thursday, May 09, 2019 - 3:20 pm

I am setting up a model that features a 3-way interaction between two L1 variables (x, w) and an L2 variable (z). I have two questions about the set up:

1. Should I include all constituent main effects and 2-way interaction terms as I typically would, or do I set it up more like the post above, with only the 3-way interaction specified?

2. I am using latent decompositon, so cannot cluster-mean center my L1 variables. Do I need to do any centering to deal with multicollinearity among the L1 vars?

Here is my setup currently, with all 2-way and main effects:

sw | y on w;
sxw | y on xw;
sx | y on x;

[sx]; !main effect x
[sw]; !main effect w

y ON z; !main effect z

[sxw]; !2-way xw

sx on z; !2-way
sw on z; !2-way
sxw on z; !3-way

 Tihomir Asparouhov posted on Friday, May 10, 2019 - 10:35 am
1. If the effects are significant you would want to keep these (as random or non-random effects depending on the significance of the mean and variance of the random effects sx sw sxw)

2. If you are not using the new methodology that we just released in 8.3 you should take a look at section 3.3
and examples
From the input you are providing I am not sure you are using latent centering correctly since X*W should have been defined with the XWITH command. If you want to use latent centering you should follow the scripts in Section 3.3. Alternatively and sufficiently good for cluster sizes >50 use observed centering for X and W and then form the interactions. Also see Table 5 & 6 for MLO estimation and the corresponding scripts.
 Timothy Allen posted on Saturday, May 25, 2019 - 3:25 pm
Hi Tihomir,

Thank you for directing us to this new material, it's been very helpful. Reading through the webnote and the examples, it looks as though the recommendation is to no longer use a random slope for Preacher's B1 hypothesis (cross-level interaction). I've been trying to adapt our own syntax to match the Section 3.3.5 example (B1 hypothesis, Table 10). Iíve started with a simpler 2-way cross-level interaction (rather than jumping into the 3-way I mention above) but the model doesn't converge and Iím wondering if I've made an error in setting it up (it has previously converged, using the random slope approach). We use a true factor at the between-level instead of a single indicator latent. Is this the appropriate way to set it up?

(no variables are declared as within or between)

xw BY x@1; x@.01;

s | y ON xw;
xz | xw XWITH NEG;
y ON xz;

NEG BY BECKns HAMns SCLINTns; !latent specification

y on NEG; ! added for "main effect" of NEG
!removed y on x, as it's not of interest

x with s@0;
NEG with s@0;
 Bengt O. Muthen posted on Sunday, May 26, 2019 - 5:15 pm
Please send your full output to Support along with your license number.
 Sarah Rosenbach posted on Friday, October 18, 2019 - 1:07 pm
I have a similar genre of questions. I'm interested in testing a 1x(1-1) model with other covariates using Bayes in Mplus 8.3. Some of the predictors are binary, including one of the predictors in the interaction.

1. Can I still use the XWITH command in this case? Both variables are observed, but I can't specify the within variance for the binary variable.

xw BY ImmDiAvg@1; ImmDiAvg@.01;
zw BY immi@1; !immi@.01; gives it issues
xzw | xw XWITH zw; xw WITH zw;

2. Is latent variable centering automatic in 8.3? Or should I be creating a latent variable behind every L1 predictor, including all the covariates? Or a subset of only the categorical/continuous covariates?

 Sarah Rosenbach posted on Friday, October 18, 2019 - 1:49 pm
And one other question for the above: multiple imputation seems to proceed normally, but then the model is not tested using the imputed datasets. Is this expected?

 Tihomir Asparouhov posted on Friday, October 18, 2019 - 3:53 pm
1. It is not possible with binary variables. Depending on your situation you might be able to use
xzw | xw XWITH immi;
You would need to drop the categorical specification for that variable and declare it as within only.
If that variable is needed elsewhere in the model you can make a duplicate copy of the variable that would be used in the XWITH. The interaction is based on the observed values 0/1 and no centering or underlying latent is used. It is probably your best bet. If clusters are large you can do observed centering and form the interactions from observed values rather than latent.

2. It is automatic if the variable appears on both levels. You don't need to create latent variables if the variables are not going into an XWITH statement.

3. I am not sure what testing you were expecting. When data is imputed we estimate the imputation model until convergence and then impute the variables by continuing to run the MCMC after the convergence is achieved. If you need to test a model - you would do that separately from the imputation.
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