Message/Author 


Hi there: I am trying to test a simple mediation model where a level2 predictor (w) is an exogenous variable and a level1 variable (y1) is the primary endogenous variable. Variables x1 and x2 (both level1 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 yvariable on the BETWEEN level and an xvariable on the WITHIN level. This variable will be treated as a yvariable on both levels: X1 *** WARNING in MODEL command In the MODEL command, the following variable is a yvariable on the BETWEEN level and an xvariable on the WITHIN level. This variable will be treated as a yvariable on both levels: X2 However, despite this WARNING I do get an estimate of both the y1x1 and y1x2 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; 


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. 


Hello, I am running a similar multilevel mediational path model [per Preacher et al (2011), a 211 model], yet with a 4level 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 righthand side of a betweenlevel 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 


Try running it in WLSMV. If that doesn't do it, try putting a factor behind x1 and let that factor be on the righthand side of the betweenlevel ON. 


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. 


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 


Try med1@0.01; If that doesn't help, send materials to support. 


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 121 mediation model where the two within IVs (rotate, healthy) are dicotomous, the 2nd level mediator is latentcontinuous (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; 


Please send the two outputs and your license number to support@statmodel.com. Please keep your posts to one window. 

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; 


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." 


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 xvariables 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" 


With numerical integration, the latent variable decomposition of a individual variable is not allowed. You need to create a betweenlevel 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 clusterlevel 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. 


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? 


If you don't have an uptodate support contract, you are not eligible for support. 


Hello, Suppose 221 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; 


Yes, seems right to me. 


Thanks for your help. I've included country dummy variables and findings are identical to those of a threelevel model. 


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 XY 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; 


Looks ok. But I don't know why you groupmean 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 betweenlevel 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 


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 


I want to estimate a 121 ML SEM. Y adn m1 are categorical. m2 and Z are continuous. I developed following syntax. USEVARIABLES ARE x m1 m2 z y x_mean; CATEGORICAL ARE m1 y; WEIGHT IS weight; CLUSTER IS district; DEFINE: x_mean = cluster_mean (x); ANALYSIS: TYPE = twolevel random; ESTIMATOR = MLR; INTEGRATION = MONTECARLO (1000); MODEL: %WITHIN% y ON x; Y ON m1 (a); Y ON m2 (b); m1 ON x (c); m2 ON x (d); %BETWEEN% y ON x_mean; y ON Z (e); Z ON xmean (f); MODEL CONSTRAINT: NEW(ind1 ind2 ind3); ind1=a*c; ind2=b*d; ind3=e*f; Some questions regarding this model: 1) Is this syntax correct? 2) Does the model provide logit parameters for the categorical endogenous variables m1 and y and linear regression parameters for the effect of X on m2 and X_mean on Z are? 3) I also tried the model using a BAYES estimator. If I choose this estimator, are my estimates for m1 and Y still logits? 4) Which estimator is to be preferred? Bayes are MLR? 5) How do I interpret the indirect effect ind2, which is the multiplication of a linear regression (d) and a logit (b) parameter? Is it correct to multiply these coefficients? Thank you so much! 


Because your mediation model has categorical variables, you should read these 2 articles as a first step: Muthén, B. & Asparouhov T. (2015). Causal effects in mediation modeling: An introduction with applications to latent variables. Structural Equation Modeling: A Multidisciplinary Journal, 22(1), 1223. DOI:10.1080/10705511.2014.935843 Click here to download the paper. Nguyen, T.Q., WebbVargas, 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, 368383 DOI: 10.1080/10705511.2015.1062730 See also our book: Muthén, B., Muthén, L. & Asparouhov, T. (2016). Regression And Mediation Analysis Using Mplus. Los Angeles: Muthén & Muthén. More specifically, your ind1 = a*b expression which involves the categorical M1 is in question. With WLSMV and Bayes, the prediction of the outcome from this mediator is from M1*, the cont's latent response variable behind the observed M1. And the outcome is considered as Y*, not Y. This makes a*b correct. With ML, M1 itself is predicting Y (or Y*) and a*b is not correct. If you are interested in M1 or M predicting Y, you should use counterfactuallydefined causal effects as in the references above. 


Thank you very much for this helpful response. I have read the material. The Nguyen et al. paper, however, states that the counterfactuallydefined causal effects method is not yet tested for a multilevel setting. Would it be applicable for this model? But if I understand correctly, if I use a WLSMV or Bayes estimator, the above syntax for my model is correct? The indirect effects are then interpreted as the effect of X on the latent response variable Y, via M1. Thanks again! 


Q1: It's true that the multilevel setting has not been explicated. My conjecture is that her paper is applicable to your case. Q2: Yes, the effect of X on the latent response variable of Y via the latent response variable of M1. 

Sandra Ohly posted on Tuesday, March 19, 2019  12:01 am



I am running a 211 model with 7 binary mediators, and contiuous dependent and indpendet variable. Is the approach described in Muthén & Asparouhov (2015) suitable in this case? 


No, that article is relevant only for one mediator and singlelevel analysis. Our mediation web page http://www.statmodel.com/Mediation.shtml refers to work by Ngyuen et al for more than one mediator but not multilevel settings. 

Sandra Ohly posted on Wednesday, March 20, 2019  2:17 am



Thank you for the quick response. I had a look at th Ngyuen paper and wonder if it is relevant because it deals with binary outcomes, but not binary mediators. Furthermore I wonder if this approach can be implemented in a multilevel setting at all? So far, I tried to combine Chris Stride's approach of adjusting the between level effects of the mediators before calculating indirect effects with the MSEM approach by Preacher. However, this resulted in a number of problems. 1. When stating that the mediators are categorical, the model won't run because variances for categorical outcomes are not allowed on the within level. 2. When ignoring that the mediators are categorial, the model will run, but the standard errors are not trustworthy. Any suggestions on how to implement a 211 mediation with binary mediators? Thank you in advance. 


Actually, your X is on level 2 where the binary mediators are represented by their continuous latent intercepts  so you have the usual effect formulas on level 2. 


Yes, I understand that the indirect effect is calculated using the level2 effects. But following Preachers 211 approach I need to model the effects on the lower level as well, I believe. Is this correct? 


Because your M and Y exist on both levels, you should say something about their bivariate distribution, such as Y on M; or Y with M; 


Dear Prof. Muthen, Following Preacher's et al. (2011) 1(11)1 model with one random slope (MSEM), we create a Mplus syntax to assess a 1(1,1,1)1 model: one continuous predictor, three mediators in parallel, and one continuous criterion. The syntax works properly but we want to know your opinion about this model. Thank you in advance. MODEL: %WITHIN% y on m1(bw1); y on m2(bw2); y on m3(bw3); c  y on x; m1 WITH m2 m3; m1 on x(aw1); m2 on x(aw2); m3 on x(aw3); %BETWEEN% c m1 m2 m3 y; c WITH m1 m2 m3 y; y on m1 (bb1); y on m2 (bb2); y on m3 (bb3); y on x; m1 WITH m2 m3; m1 on x (ab1); m2 on x (ab2); m3 on x (ab3); [c]; MODEL CONSTRAINT: NEW(abw1 abw2 abw3 abb1 abb2 abb3 conw1 conb1 conw2 conb2 conw3 conb3); abw1 = aw1*bw1; abw2 = aw2*bw2; abw3 = aw3*bw3; abb1 = ab1*bb1; abb2 = ab2*bb2; abb3 = ab3*bb3; conw1= abw1abw2; conb1 = abb1abb2; conw2= abw1abw3; conb2 = abb1abb3; conw3= abw2abw3; conb3 = abb2abb3; 


1. I would recommend using estimator=bayes which would use the latent centering for X. The ML estimator would be using the hybrid method. See http://www.statmodel.com/download/CenteredMediation.pdf 2. You would need a slight modification of the model to use full variance covariance matrices MODEL: %WITHIN% y on m1(bw1); y on m2(bw2); y on m3(bw3); c  y on x; m1 WITH m2 m3; m2 WITH m3; m1 on x(aw1); m2 on x(aw2); m3 on x(aw3); %BETWEEN% c m1 m2 m3 y; c WITH m1 m2 m3; y on m1 (bb1); y on m2 (bb2); y on m3 (bb3); y on x c; m1 WITH m2 m3; m2 WITH m3; m1 on x (ab1); m2 on x (ab2); m3 on x (ab3); [c]; 3. If you prefer to use the ML estimator then I would recommend observed centering, i.e., two separate variables XW and XB See http://www.statmodel.com/download/LatentCentering.zip Table 14 directory has examples observed.inp 


Dear Dr.Asparouhov, I greatly appreciate your recommendations and the information provided. I assume that your recommendation to use estimator=bayes also applies to other multilevel mediation models (MSEM) that use one or two level1 mediators, is it right? Thanks for your support! 


Sorry Dr. Asparouhov, I performed the analyses following your recommendations: 1.When I tested a 111 (MSEM) model using estimator=bayes the syntax works correctly, showing very similar results to that ones that I found using estimator=MLR (number of clusters in my database is 115 and cluster size is around 36) 2. However, when I tested a MSEM model with more than one level1 mediators (2 and 3) using estimator=bayes, the following error message appeared: *** ERROR in MODEL command Unrestricted xvariables for analysis with TYPE=TWOLEVEL and ESTIMATOR=BAYES must be specified as either a WITHIN or BETWEEN variable. The following variable cannot exist on both levels: x Then, as my predictor(x) is a level1 variable I defined the predictor as a level1 variable (within=x) and I center the predictor at groupmean level. But, when you specified a variable as within the program can't use this variable at between level, and I can't compute the between indirect effects. So, it seems that your recommendation of using estimator=bayes it works for models with a single mediator but not for models with two o more mediators. What would you recommend in this case? Thanks in advance for your expertise opinion. 


We need to see your full output  send to Support along with your license number. 

Gene Maguin posted on Wednesday, September 09, 2020  9:06 am



I am doing a 1111 (X>M1>M2>U) mediation in which the second mediator (M2) and the outcome are dichotomous. There are random intercepts but not random slopes. Questions: 1) My reading of the documentation for model indirect is that the IND subcommand will compute indirect effect. True? 2) I planned to get CIs by bootstrapping; however, my reading of Bootstrap is the bootstrapping is not available for Type=TwoLevel. Have i missed something and bootstrapping actually is available? 3) Is my plan flawed in computation or method? Thank you. 


To get nonsymmetric CIs, you don't have to use Bootstrapping. Bayes will do it automatically. 

Gene Maguin posted on Sunday, September 13, 2020  1:28 pm



Bengt, thank you for your recommendation to use Bayes. The model is a 1111 mediation with X, M1, and M2 being continuous and Y being binary. The senior author and I are both very Bayesnaïve and we have several questions but these two probably are the most important. 1) Estimation terminated normally. Stopping criterion was met at iteration 3100 (PSR=1.057). I increased Fbiterations to 16000 and reran. From 3100 to 16000, the PSR values increased to 1.373 and then decreased to 1.022. I don’t know how to interpret this variation. Is this variation evidence that the model did not converge? 2) The 95% CI for the Difference Between the Observed and the Replicated ChiSquare Values was significant. I assume the CI for the difference was 357 and 406). How do I interpret this result? Thank you, Gene Maguin 


1) No, it just means that it didn't truly converge at 3100. See our video and handout for the Bayes section of Topic 11. 2) The CI should cover zero for good model fit. 

Gene Maguin posted on Monday, September 14, 2020  7:20 am



Thank you. I thought that might be true but wanted to ask. I'd like to ask one further question. I've run the same model using the MLR estimator and the model converged. Bayes was attractive because the I could use the model constraint command to compute the product of coefficients and get a confidence interval. In a Bayes analysis is there a way to identify the cause or causes of the nonconvergence? Thank you, Gene Maguin 


The Tech8 screen output shows the number of the parameter that is the slowest to converge (Tech1 tells you which one it is). That is the parameter that that the data has the least information about given the model. If the PSR stays stubbornly high, you should stop the run. The way to explore the problem is to simplify the model  often by turning some random slopes into regular ones  and then extend it step by step. Typically, if ML can do it, Bayes can do it too with quite similar results. But there are many situations where Bayes can do what ML can't. 

Gene Maguin posted on Tuesday, October 13, 2020  7:32 pm



I'm having problems getting the level 2 part of a 111 mediation model (Preacher et al.'s 2010 Model I) to run. Model I shows this: usevariables=ownuseA ownintx anyasslt; categorical anyasslt; cluster=studyid; analysis: type=twolevel; estimator=mlr; model: %within% ownintx on ownuseA; anyasslt on ownintx; %between% anyasslt ownintx ownuseA; ownintx on ownuseA; anyasslt on ownintx; output: tech1; tech8; The error message is this: Observed variable on the righthand side of a betweenlevel ON statement must be a BETWEEN variable when using ML estimators. I have to have to made a mistake in my syntax but I do not know where it is at or why. Would you point out my error please? Thank you, Gene Maguin 


Typically, as in UG ex 9.1, part 2, this would work fine, giving an automatic latent variable decomposition of the predictors. But you have a categorical variable which means that algo = int is used and then you don't have access to the latent variable decomposition  unless you use Bayes or put fake latent variables behind. 

Back to top 