Mediation
Message/Author
 Scott C. Roesch posted on Tuesday, July 29, 2008 - 1:45 pm
Hi there:

I am trying to test a simple mediation model where a level-2 predictor (w) is an exogenous variable and a level-1 variable (y1) is the primary endogenous variable. Variables x1 and x2 (both level-1 variables) are hypothesized to be mediators of this relationship.

When I run the code below I get the following WARNING:

** WARNING in MODEL command
In the MODEL command, the following variable is a y-variable on the BETWEEN
level and an x-variable on the WITHIN level. This variable will be treated
as a y-variable on both levels: X1
*** WARNING in MODEL command
In the MODEL command, the following variable is a y-variable on the BETWEEN
level and an x-variable on the WITHIN level. This variable will be treated
as a y-variable on both levels: X2

However, despite this WARNING I do get an estimate of both the y1-x1 and y1-x2 relationship at the WITHIN level according to the output.

Should I be worried, or is there a better way to specify this mediation model?

VARIABLE: NAMES ARE y1 y2 x1 x2 w clus;

USEV ARE y1 x1 x2 w;

BETWEEN = w;

CLUSTER IS clus;

ANALYSIS: TYPE = TWOLEVEL;

MODEL:
%WITHIN%
y1 ON x1 x2;

%BETWEEN%
x1 x2 ON w;
 Linda K. Muthen posted on Tuesday, July 29, 2008 - 5:58 pm
It is just saying the x1 and x2 are being treated at dependent variables on both levels. This means distributional assumptions are made about them. If this is the model you want, this is how it is done.
 Philip Hastings posted on Wednesday, November 02, 2011 - 8:07 am
Hello, I am running a similar multilevel mediational path model [per Preacher et al (2011), a 2-1-1 model], yet with a 4-level categorical (ordinal) outcome (i.e. y1 above is ordinal). Mplus does not seem to allow this, with the message:

*** ERROR in MODEL command
Observed variable on the right-hand side of a between-level ON statement
must be a BETWEEN variable. Problem with: x1
Same message repeated for any mediating variables with both within and between level components.

Running with the outcome as continuous does work. Is there a different setup required, or is the multilevel ordinal logistic model with mediation impossible to test with Mplus? I realize the numerical integration makes it computationally problematic, but Mplus won't try to run it. Thanks, Phil
 Bengt O. Muthen posted on Wednesday, November 02, 2011 - 11:05 am
Try running it in WLSMV. If that doesn't do it, try putting a factor behind x1 and let that factor be on the right-hand side of the between-level ON.
 Philip Hastings posted on Friday, December 02, 2011 - 12:31 pm
Thanks Dr. Muthen. The workaround of creating the perfect factors separating within/between components did work.

As a followup question, I wonder if Mplus is able to model a weighted TWOLEVEL model with an ordinal outcome and mediators using MLR, to obtain an ordinal logistic model.

The model runs using WLSMV but not with MLR, and I receive this error:

THE ESTIMATED WITHIN COVARIANCE MATRIX COULD NOT BE INVERTED.
COMPUTATION COULD NOT BE COMPLETED IN ITERATION 1.
CHANGE YOUR MODEL AND/OR STARTING VALUES.

THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY DUE TO AN ERROR IN THE
COMPUTATION. CHANGE YOUR MODEL AND/OR STARTING VALUES.

The chapter 16 tables of estimators seems to indicate the MLR should work, but perhaps I've set this up incorrectly. I'd appreciate any suggestions you might have. The following post will show a simplified model that yields the error.
 Philip Hastings posted on Friday, December 02, 2011 - 12:36 pm
Here is the setup I've tried:
VARIABLE:
USEVARIABLES =
wt cl_num
ord1 cl_trt med1;
CLUSTER = cl_num ;
WEIGHT = wt ;
WTSCALE = unscaled ;
CATEGORICAL = ord1 ;
BETWEEN = cl_trt ;

ANALYSIS:
TYPE = TWOLEVEL ;
ESTIMATOR = MLR ;

MODEL:
%WITHIN%
! create perfect factors to separate within component
! (enables model to run, per suggestions from BM, KP)
med1_w by med1@1; med1@0;

! within model statements
ord1 ON med1_w ;

%BETWEEN%
! create perfect factors to separate between component
! (enables model to run, per suggestions from BM, KP)
med1_b by med1@1; med1@0;

! mediator relationship
med1_b ON cl_trt(a);

! outcome relationships
ord1 ON med1_b(b);
ord1 ON cl_trt;

MODEL CONSTRAINT:
! indirect effect
NEW(ie1);
ie1=a*b ; ! Between indirect
 Bengt O. Muthen posted on Friday, December 02, 2011 - 2:08 pm
Try

med1@0.01;

If that doesn't help, send materials to support.
 Philip Hastings posted on Sunday, December 04, 2011 - 7:38 pm
Thanks Dr. Muthen, adding back that little bit of variance allowed the model to work under MLR. I appreciate your prompt suggestions. Very best regards, Phil
 Andy Luse posted on Wednesday, August 01, 2012 - 11:08 am
I have a 1-2-1 mediation model where the two within IVs (rotate, healthy) are dicotomous, the 2nd level mediator is latent-continuous (Imp), and the 1st level DV (choice) is also dichotomous. I am trying to test for indirect effects for each of the two IVs through the mediator. I tried using your suggestions above, but I get the same error when setting @0 and when I set it @0.01 it just keeps running.
 Andy Luse posted on Wednesday, August 01, 2012 - 11:11 am
Here is the syntax...

USEVARIABLES ARE id choice rotate healthy Imp_1 Imp_2 Imp_3 Imp_4 Imp_5 Imp_7 Imp_9;

CLUSTER IS id;

BETWEEN ARE Imp_1 Imp_2 Imp_3 Imp_4 Imp_5 Imp_7 Imp_9;

CATEGORICAL = choice;

ANALYSIS:
TYPE IS TWOLEVEL;
ESTIMATOR = MLR;

MODEL:
%WITHIN%
e1_w BY rotate@1;
rotate@0;
e2_w BY healthy@1;
healthy@0;
e1_w WITH e2_w@0;

choice ON e1_w e2_w;

%BETWEEN%
Imp BY Imp_1 Imp_2 Imp_3 Imp_4 Imp_5 Imp_7 Imp_9;

e1_b BY rotate@1;
rotate@0;
e2_b BY healthy@1;
healthy@0;
e1_b WITH e2_b@0;

Imp ON e1_b(a_1);
Imp ON e2_b(a_2);
choice ON Imp(b);
choice ON e1_b;
choice ON e2_b;

MODEL CONSTRAINT:
NEW(indb_1);
indb_1 = a_1 * b;

NEW(indb_2);
indb_2 = a_2 * b;

OUTPUT:
TECH1 TECH8 CINTERVAL;
 Linda K. Muthen posted on Thursday, August 02, 2012 - 11:22 am

 Andy Luse posted on Friday, August 03, 2012 - 10:06 am
Ok, I have broken it down to where I am just trying to estimate the direct effect at each level with a single dichotomous IV (rotate) and a single dicotomous DV (choice), but I get the error "THE ESTIMATED WITHIN COVARIANCE MATRIX COULD NOT BE INVERTED. COMPUTATION COULD NOT BE COMPLETED IN ITERATION 1. CHANGE YOUR MODEL AND/OR STARTING VALUES." I'm trying to use the method above.

%WITHIN%
e1_w BY rotate@1;
rotate@0;

choice ON e1_w;

%BETWEEN%
e1_b BY rotate@1;
rotate@0;

choice ON e1_b;
 Linda K. Muthen posted on Friday, August 03, 2012 - 12:00 pm
There is no difference between saying

%WITHIN%
e1_w BY rotate@1;
rotate@0;
choice ON e1_w;

or

choice ON rotate;

Use the second approach.
 Andy Luse posted on Friday, August 03, 2012 - 12:20 pm
When I change the within section to choice on rotate I get "SERIOUS PROBLEM IN THE OPTIMIZATION WHEN COMPUTING THE POSTERIOR DISTRIBUTION. CHANGE YOUR MODEL AND/OR STARTING VALUES."
 Linda K. Muthen posted on Friday, August 03, 2012 - 1:41 pm
You should change within and between in the same way.
 Andy Luse posted on Friday, August 03, 2012 - 2:26 pm
When I try that, I get the following error and it doesn't run "Unrestricted x-variables in TWOLEVEL analysis with ALGORITHM=INTEGRATION must be specified as either a WITHIN or BETWEEN variable. The following variable cannot exist on both levels: ROTATE"
 Linda K. Muthen posted on Saturday, August 04, 2012 - 11:12 am
With numerical integration, the latent variable decomposition of a individual variable is not allowed. You need to create a between-level variable for rotate. You can do this using the CLUSTER_MEAN option of the DEFINE command.
 Andy Luse posted on Saturday, August 04, 2012 - 12:21 pm
Ok, I made a new cluster-level variable for rotate using the CLUSTER_MEAN command and then specified rotate as a within variable and the new variable (rotate_b) as a between variable. Now I am getting the following error...

*** ERROR
One or more variables have a variance of zero.
Check your data and format statement.

Continuous Number of
Variable Observations Variance

CHOICE 864 0.000
ROTATE 864 0.250
**ROTATE_B 864 0.000

I'm not sure why choice is listed as a continuous variable as I have specified it as categorical in the variable portion. It makes sense that rotate_b would have a variance of zero as it is the mean of the within subjects dichotomous experimental condition rotate.
 Linda K. Muthen posted on Saturday, August 04, 2012 - 1:40 pm
You will need to send this to support. It is not possible to diagnose it without further information.
 Andy Luse posted on Monday, August 06, 2012 - 9:42 am
Does this mean I'll need to purchase a new support contract?
 Linda K. Muthen posted on Monday, August 06, 2012 - 9:56 am
If you don't have an up-to-date support contract, you are not eligible for support.
 luk bruyneel posted on Monday, February 22, 2016 - 12:45 am
Hello,
Suppose 2-2-1 multilevel mediation model for about 400000 patients in 300 hospitals in 9 countries. Random intercepts for the hospital, no random slopes. Countries are not chosen at random and n is only 9. One possibility is multiple group (i.e. country) multilevel (i.e. hospital) mediation model, which for these data is too computationally demanding. I have also not seen examples of this in the literature. An often suggested proxy is to put country in as a fixed effect. In a mediation model, would country then have to be included in both the a as well as the b path?
CLUSTER = hosp;
BETWEEN = ctrptn ctreduc pes beds0 bedsmiss tech0 techmiss teac0 teacmiss clinical country;
WITHIN = age sex er drg ermiss charlson;
CATEGORICAL = d30;
analysis: TYPE= twolevel; ESTIMATOR = BAYES; BITERATIONS = (1000); PROCESS=2;
model:
%BETWEEN%
d30 on ctrptn ctreduc beds0 bedsmiss tech0 techmiss teac0 teacmiss country;
d30 on clinical (b);
clinical on ctrptn (a);
clinical on pes country;
%WITHIN%
d30 on age sex er ermiss drg charlson;
MODEL CONSTRAINT:
NEW(ind);
ind=a*b;
 Bengt O. Muthen posted on Monday, February 22, 2016 - 5:53 pm
Yes, seems right to me.
 luk bruyneel posted on Tuesday, February 23, 2016 - 4:13 am
Thanks for your help. I've included country dummy variables and findings are identical to those of a three-level model.
 Sharon Sheridan posted on Wednesday, March 02, 2016 - 8:25 am
Does my code & calculation of the indirect effects look correct for specifying a sequential mediation model with all paths fixed? Thanks
USEVARIABLES ARE ID X M2 M1 Y;
MISSING ARE ALL (-999);
CLUSTER IS ID; !GROUPING VARIABLE IS ID
WITHIN = X M2 M1;!LEVEL 1 VARIABLES
BETWEEN = ;
DEFINE: CENTER X M2 M1 (GROUPMEAN);!GROUP MEAN CENTER
Analysis: TYPE = TWOLEVEL RANDOM;
MODEL:
%WITHIN%
Y ON M1 (b1); !path b1
Y ON M2 (b2); !path b2
Y ON X (cdash); !Direct effect X-Y
M1 ON X (a1); !path a1
M2 ON X (a2); ! path a2
M2 ON M1 (d1); ! path d1
%BETWEEN%
Y; ! no predictors of intercept
MODEL CONSTRAINT:
NEW(a1b1 a2b2 a1d1b2);
a1b1 = a1*b1; !Specific indirect effect of X on Y via M1
a2b2 = a2*b2; !Specific indirect effect of X on Y via M2
a1d1b2 = a1*d1*b2; !Specific indirect effect of X on Y via M1 and M2
OUTPUT: TECH1 TECH8 CINTERVAL;
 Bengt O. Muthen posted on Thursday, March 03, 2016 - 6:29 pm
Looks ok. But I don't know why you group-mean center the mediator.
 Ted Fong posted on Monday, July 16, 2018 - 1:40 am
I understand that ALGORITHM=INTEGRATION is needed for ML multilevel modeling on a binary outcome. After reading the new technical report on latent variable centering, I have the following three quick queries that I hope you could confirm.

1) Is latent variable decomposition of predictors X still not feasible for ML estimation in Mplus 8.1 when numerical integration is involved?

2) If I stay with MLR estimation, must I create a between-level component for X using CLUSTER_MEAN, which would then deviate from the latent variable centering technique?

3) Is Bayes the only feasible estimation for using latent variable centering in multilevel mediation analysis with both categorical outcome and random slope?

A lot of thanks
 Bengt O. Muthen posted on Monday, July 16, 2018 - 2:46 pm
1) Right. Unless you add a factor behind the variable but that complicates things.

2) That's a reasonable alternative.

3) Practically speaking, yes.
 Ted Fong posted on Monday, July 16, 2018 - 8:05 pm
Dear Prof. Muthen,

Many thanks for your prompt reply and insights on this matter. This helps a lot!

Best regards,
Ted