Message/Author 


We did an Experience Sampling study and collected data (events, emotions, work engagement) from 55 people twice a day for nine working days (repeated measures design: daily measures are nested in individuals). We like to test a moderated mediation model with: Daily events > triggering emotional experiences (mediator) > influencing work engagement (DV) (Lower Level Mediation). The moderators are on Level 2 (they were measured once). Is it possible to test such a multilevel moderated mediation model with Mplus and how could I perform the analyis? Thanks a lot in advance! 


Yes, it is possible. Bauer, Preacher, & Gil (2006, pp. 153158) address this model. We have code in SAS, SPSS, and HLM for lowerlevel mediation models with the potential for moderation by level2 predictors (see quantpsy.org), but it is also easy to do in Mplus. Here is Mplus code that yields the same output: TITLE: 111 model from BPG article DATA: FILE IS bpg_example_data.dat; VARIABLE: NAMES ARE id x m y; CLUSTER IS id; ANALYSIS: TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% sa  m ON x; sb  y ON m; sc  y ON x; m y; %BETWEEN% sa sb sc m y; sa WITH sb(cab); sa WITH sc m y; sb WITH sc m y; sc WITH m y; m WITH y; [sa](sa); [sb](sb); [sc](sc); MODEL CONSTRAINT: NEW(ind); ind=sa*sb+cab; ! indirect effect OUTPUT: TECH1 TECH8; Bauer et al. use a parametric bootstrap to obtain a CI for the indirect effect. A modification of the R code here can be used to achieve the same goal using Mplus output. Ex.11.11 in the Mplus Users Guide will also be helpful. Bauer, D. J., Preacher, K. J., & Gil, K. M. (2006). Conceptualizing and testing random indirect effects and moderated mediation in multilevel models: New procedures and recommendations. Psychological Methods, 11, 142163. 


Thanks a lot! Especially the Mplus code was very helpful. 

Jeffrey Kahn posted on Wednesday, November 16, 2011  8:52 am



I have a 211 mediation model based on a diary study. Event rumination mediates the relation between attachment anxiety and event disclosure. Attachment avoidance is a level 2 covariate predicting event disclosure. Event intensity is a moderator of the b path between event rumination and event disclosure. My Mplus code is based on Preacher, Zypher, and Zang (2010): TITLE: Moderated mediation model DATA: FILE IS data.dat; VARIABLE: NAMES ARE code ev_int ev_disc ev_rumin attavoid attanx; USEVARIABLES ARE code ev_int ev_disc ev_rumin attavoid attanx; BETWEEN IS attanx attavoid; CLUSTER IS code; ANALYSIS: TYPE IS TWOLEVEL RANDOM; MODEL: %WITHIN% ev_rumin ev_disc; sb  ev_disc ON ev_rumin; %BETWEEN% attanx ev_rumin ev_disc attavoid; ev_rumin ON attanx(a); ev_disc ON ev_rumin(bb); ev_disc ON attanx attavoid; sb WITH attanx ev_rumin ev_disc attavoid; [sb](bw); MODEL CONSTRAINT: NEW(b indb); b=bb+bw; indb=a*b; OUTPUT: TECH1 TECH8 CINTERVAL; Did I handle the attavoid covariate properly? Also, how do I integrate the moderating effect of ev_int? Thanks. 


aatavoid is an observed betweenlevel covariate so I wouldn't mention its variance as you do. If it predicts sb I would add that ON statement instead of WITH. As for the moderator, first see if the sb variance is significant or if a fixed slope can be used. Generally speaking, with a continuous moderator, use Define to create the interaction. 


Thank you, Bengt. The sb variance is significant. I would like to see if ev_int (a level 1 variable) can predict the variance in sb. My intuition was to add the following statement in the %BETWEEN% section: sb ON ev_int; However, from your above comment it seems that I should use DEFINE to create an interaction term: DEFINE: interact=ev_int*ev_rum; Would I then include the following statement in the %BETWEEN% section? ev_disc ON ev_rumin(bb) ev_int interact; If it helps, my model can be viewed at: http://my.ilstu.edu/~jhkahn/Multilevel%20moderated%20mediation.gif 


With a significant sb slope your model specification in your first message gives an interaction between the withinlevel part of ev_rumin and the betweenlevel part of ev_disc. This, I think, is the moderation you talked about in your first message. See also slide 45 of our Topic 7 short course handout. 

Yan Liu posted on Monday, April 30, 2012  11:46 am



Hi, Bengt I am conducting some anlayses using the multilevel mediation models based on SEM framework introduced by Preacher, Zyphur, and Zhang (2010). I also read the paper "constructing covariates in multilevel regression" by Asparouhov and you (2007).I like this new approach a lot. However, I found that the model doesn't run for ordinal categorical outcome variable. I wonder if there is a way for me to use this approach for categorical outcome. The model I used has two outcomes (PAHome & PESch), one mediator (Enjoy) and one predictor (TT). The syntax is attached as follows. USEVARIABLES = idealindivid Enjoy PESch PAHome; CATEGORICAL = PESch; CLUSTER IS classid; MISSING = ALL(999); ANALYSIS:TYPE = TWOLEVEL; MODEL: %WITHIN% TTw BY idealindivid; Enjoy ON TTw (aw); PAHome ON Enjoy (b1w); PAHome ON TTw; PESch ON Enjoy (b2w); PESch ON TTw; %BETWEEN% TTb BY idealindivid; Enjoy ON TTb (ab); PAHome ON Enjoy (b1b); PAHome ON TTb; PESch ON Enjoy (b2b); PESch ON TTb; 


Please send your output and license number to support@statmodel.com. 

Yan Liu posted on Thursday, May 03, 2012  4:44 pm



Hi, Linda Thank you for your reply. I tried WLSMV estimator, then the model worked fine. Do you think if this is appropriate? If it is, I have further questions. First, as far as I know full information ML can handle missing data. Here I used WLSMV, how are the missing data handled using this estimator? Second, for my data set 20% missing on the mediator and two outcome variables. The missing values depend on gender and the predictor(a latent variable with four indictors). Is my understanding correct that I should include gender as a covariate to control for the gender differences on missingness (for both mediator and outcome variables)? Can I use gender as a moderator? I tried to create an interaction between gender and the predictor (latent variable), but it didn't work. Is there a way to do it? Thanks. Yan 


See the following technical appendix on the website: Weighted Least Squares Estimation with Missing Data Yes, you should include gender as a covariate. You can use the XWITH option to create an interaction between a latent an observed variable. 

Yan Liu posted on Wednesday, May 09, 2012  6:19 pm



Hi, Linda Thank you so much! So WLS estimator still uses FIML to treat missing values. What is the default for deleting missing values? I noticed the number of observations in the output is the same as the covariate, gender. I tried the interaction between "gender" and the latent predictor "TTw", but it seems WLSMV doesn't run for this moderated mediational model. The error message is "WLSMV is not allowed with TYPE=RANDOM". So do we have to use MLR estimator? Hence, I changed estimator to MLR, but it seems that the model didn't run if the outcome, "PESch", is defined as categorical. The error message is as follows. Observed variable on the righthand side of a betweenlevel ON statement must be a BETWEEN variable. Problem with: ENJOY I also tried to define the outcome "PESch" as a continuous variable, but it doesn't work well. If I have to treat outcome variables as continuous to run moderated mediational models, what strategies would you recommend? Thanks a lot! Here is part of my Mplus syntax. ANALYSIS:TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% TTw BY idealindivid; sexTT sex XWITH TTw; Enjoy ON TTw (aw); Enjoy ON sex sexTT; PAHome ON Enjoy (b1w); PAHome ON TTw sex sexTT; PESch ON Enjoy (b2w); PESch ON TTw sex sexTT; 


Missing data handling is not done in the same way for weighted least squares and maximum likelihood. Weighted least squares is described in the technical appendix I referred you to. Maximum likelihood is described in the Little and Rubin book cited in the user's guide. Missing data theory applies to dependent variables. Observations with missing data on one or more independent variables are not included in the analysis. Put a factor behind joy, for example, f BY enjoy@1; enjoy@0; use f instead of enjoy as the covariate. 

Yan Liu posted on Wednesday, May 16, 2012  12:27 pm



Hi, Linda Followed your suggestion, I put a factor behind enjoy, but it seems the model didn't work. Could you please take a look and see if my model is specified correctly. Thanks a lot! Yan ANALYSIS: TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% TTw BY idealindivid; sexTT sex XWITH TTw; fw BY enjoy@1; enjoy@0; fw ON TTw (aw); fw ON sex sexTT; PAHome ON fw (b1w); PAHome ON TTw sexTT; PESch ON fw (b2w); PESch ON TTw sexTT; %BETWEEN% TTb BY idealindivid; fb BY enjoy@1; enjoy@0; fb ON TTb (ab); PAHome ON fb (b1b); PAHome ON TTb; PESch ON fb (b2b); PESch ON TTb; idealindivid@0; Here is the error message. THE ESTIMATED WITHIN COVARIANCE MATRIX IS NOT POSITIVE DEFINITE AS IT SHOULD BE. COMPUTATION COULD NOT BE COMPLETED. THE VARIANCE OF TTW APPROACHES 0. FIX THIS VARIANCE AND THE CORRESPONDING COVARIANCES TO 0, DECREASE THE MINIMUM VARIANCE, OR SPECIFY THE VARIABLE AS A BETWEEN VARIABLE. 


The message says that the variance of ttw approaches zero. To investigate why, you could simplify the model to only include the ttw and ttb factors, that is, using only the variables idealindivid. If that does not show the same problem, then add variables into that model. Stepwise model building is always recommended. 

Ari Malka posted on Saturday, June 09, 2012  4:39 pm



Hello, We are testing a model wherein we have military personnel nested within teams. Each team also has a group of leaders (and a group of subordinates). We have hypothesized a moderatedmediation model wherein Leadership Team Cohesion > Subordinate Team Cohesion > Team Performance. We also hypothesized two first stage moderators: (1) subordinate level of agreement on the extent to which their leadership team forms a cohesive unit and (2) racioethnic similarity between the leadership and subordinate teams (in the same larger team). We want to use moderatedmediation wherein all variables are at level 2 and wherein all variables are at level 1 (except the moderators) all in the same model. In other words, we want to have 6 latent variables (3 team level and 3 individual level). Is this possible? 


Yes, you can have a model with 3 teamlevel and 3 individuallevel latent variables. 

ari malka posted on Saturday, June 30, 2012  12:00 pm



Hi Linda, Thanks for the response above (regarding the model with leadership team cohesion). I am having trouble figuring out the code for mediation (both levels 1 and 2)and the code for the two moderators. Would it help to see my model? What is the best way for me to show it to you? Any help would be greatly appreciated!! Ari 

ari malka posted on Saturday, June 30, 2012  12:01 pm



So far, this is my code: VARIABLE: NAMES ARE Cluster ClusSize Rank SubTeam Gender Race Age TeamEff1 TeamEff2 TeamEff3 TeamEff4 TeamCoh1 TeamCoh2 TeamCoh3 TeamCoh4 LeadCoh1 LeadCoh2 LeadCoh3 LeadCoh4 RaceSim rwgTCun rwgLCun; USEVARIABLES ARE ClusSize Rank SubTeam Gender Race Age TeamEff1 TeamEff2 TeamEff3 TeamEff4 TeamCoh1 TeamCoh2 TeamCoh3 TeamCoh4 LeadCoh1 LeadCoh2 LeadCoh3 LeadCoh4 RaceSim rwgTCun rwgLCun Cluster; MISSING ARE ALL (999); CLUSTER IS Cluster; ANALYSIS: TYPE IS TWOLEVEL; ESTIMATOR IS MLM; ITERATIONS = 1000; CONVERGENCE = 0.000001; Model: %Within% LTCi by LeadCoh1@1 LeadCoh2 LeadCoh3 LeadCoh4; TCi by TeamCoh1@1 TeamCoh2 TeamCoh3 TeamCoh4; TPi by TeamEff1@1 TeamEff2 TeamEff3 TeamEff4; TCi on LTCi; TPi on TCi; %Between% LTCg by LeadCoh1@1 LeadCoh2 LeadCoh3 LeadCoh4; TCg by TeamCoh1@1 TeamCoh2 TeamCoh3 TeamCoh4; TPg by TeamEff1@1 TeamEff2 TeamEff3 TeamEff4; TCg on LTCg; TPg on TCg; OUTPUT: SAMPSTAT RESIDUAL STANDARDIZED CINTERVAL TECH3 TECH4; SAVEDATA: FILE IS Diss Data for Mplus 6.22; FORMAT IS FREE; RECORDLENGTH = 1000; 


This looks okay. Please limit posts to one window. 

baozhenzhou posted on Friday, January 31, 2014  8:23 pm



Hello! We want to test a moderated mediation model just like the model 5 in the following paper (when the a and b paths are both moderated by w): Preacher, K. J., Rucker, D. D., & Hayes, A. F. (2007). Addressing moderated mediation hypotheses: Theory, methods, and prescriptions. Multivariate Behavioral Research, 42, 185227. Our model is perceived school climate (x) > deviant peers affiliation (m) > delinquency(y). The moderator is effortful control (w). Given we were analyzing clustered data (students are nested within 10 schools). Is it possible to test such a multilevel moderated mediation model with Mplus and how could I perform the analyis? Thanks a lot in advance! 


Ten schools is too few for multilevel modeling. You need at least 20 and many would suggest 3050. Instead create nine dummy variables and use those as covariates to control for nonindependence of observations. 

baozhenzhou posted on Saturday, February 01, 2014  6:32 pm



Linda, thanks for your help! The Mplus User's Guide has a description of how to refer the levels of a nominal dependent variables in the MODEL command but no description of how to create dummy variables for independent in the DEFINE command. I have searched the Mplus Discussion for the answers and found the following example. But I still can't understand how to write the syntax for the dummy variables of 10 schools? Could you help me? Thanks a lot! DEFINE; white = 0; if (raceth eq 1) then white = 1; black = 0; if (raceth eq 2) then black = 1; etc. 


The above DEFINE command is how you would create dummy variables. You should create k1 dummy variables where k is the number of categories. 

baozhenzhou posted on Sunday, February 02, 2014  5:48 pm



Thanks, Linda. Followed your suggestion, this is my code to define nine dummy variables for ten schools(sc). DEFINE: sc1 = sc == 1; sc2 = sc == 2; sc3 = sc == 3; sc4 = sc == 4; sc5 = sc == 5; sc6 = sc == 6; sc7 = sc == 7; sc8 = sc == 8; sc9 = sc == 9; Did I handle the dummy variables properly? Thank you very much! 


This does not look correct. You should have a cluster variable that takes on the values of 1 through 10. DEFINE: sc1=0; if cluster == 1 then sc1 = 1; sc2=0; if cluster == 2 then sc2 = 1; ETC. 


Hello, After a succesful multilevel mediation model (221), I'm looking for moderated mediation, using the Mplus codes that come with Preacher, Rucker and Hayes (2007) 'Addressing moderated mediation hypotheses'. I used model 2, where the a path is moderated by w (first stage moderation): MODEL: %WITHIN% y on l; %BETWEEN% y on m (b1) x w xw; m on x (a1) w xw (a3); MODEL CONSTRAINT: new (ind wmodval); wmodval = 1; ind=(a1+a3*wmodval)*b1; Your help would be appreciated in the complete and correct interpretation of the findings:  m is significant to y, x/w/xw are not  x and w are significant to m, xw is not  significant indirect effect 


There is no significant moderation, but the indirect effect is significant. 


Thanks for your reply! So if xw were significant to m, there would be significant moderation? Since x is not significant to y, there is full mediation? 


Right. 


In the above multilevel moderated mediation model with a categorical outcome, Mplus automatically uses Bayesian estimation. In a previous post in the 'CFA with Bayesian estimation' forum you mentioned that PPC for multilevel models has not been implemented yet. Is there a way to assess model fit here then? 


This has not yet been developed. So there is no way to assess fit. 


Thanks for your reply! In my 221 model, I want to combine moderated mediation and simple mediation for another variable in the same model. Is the following model correct? Are there any problems known with such model, except that model fit cannot be assessed? %BETWEEN% !moderated mediation y on m (b1) x1 w x1w; m on x1 (a1) w x1w (a3); !mediation y on x2; m on x2(a); MODEL CONSTRAINT: new (ind1 ind2 wmodval); wmodval = 0.125; ind1=(a1+a3*wmodval)*b1; ind2=a*b1; 


I don't see a problem. Note that you can use the LOOP option (see UG ex 3.18). 


Hi Dr. Muthen, I am wondering if mplus can test two moderators at different stages at the sometime, like model 21 in Hayes' new book "PROCESS". Basically, I want to test a model like this: x>m>y(y1, y2, y3), the relation between x and m is moderated by moderator 1, and m>Y relation is moderated by moderator2. In addition, I also have multiple dependent variables. Moreover, these y1, y2, y3 are measured by team leaders (all other variables are individual level), so I want to control for team level variance, so I specify a twolevel model,just no independent variables in level 2. So my questions are 1 can mplus test such a model? because I could use PROCESS macro in spss to test this moderated mediation, but PROCESS does not have multilevel functions. and it can only test one dv at a time. 2 if mplus can, can I use indirect to test the moderated mediation? Do I need to test each dv at a time? But can I use indirect to test two moderators at the same time? Thank you very much in advance for your reply! annebell 


Dear Dr. Muthen, I also have another model I am not quite sure. The model is a moderated mediation, x>m(m1, m2, m3)>Y(Y1, Y2, Y3), and the relation between x and m is moderated by a Moderator. All These variables are individual level, except for Y is measured by team leader, so i want to control for team level variance, but no IVs in team level. I have three mediators, and three dependent variables. I have used Bayes iterations, and the moderation is significant. However, if I just use regular iterations, the results are not significant. My question is what is the difference between the two? Which results should I use? Thank you a lot！ annebell 


This is possible in Mplus, but you have to study up on what it means. It is straightforward to do twolevel moderated mediation in Mplus. In your case you just add a between part for the y variables by mentioning their variances. If Bayes gives significance and ML doesn't it can mean that the distribution of the estimate is not symmetric/normal. In this case Bayes is preferrable (bootstrap is an alternative for ML, but doesn't exist yet for twolevel). 

Yan Liu posted on Sunday, August 17, 2014  7:10 pm



Dear Dr. Muthen I am trying a 211 multilevel moderated mediational model. However, I always got a error message to ask me to define cluster, which I have included (teacher's id). Could you please take a look at my Mplus syntax? Thanks a lot! (w=moderator, x=predictor,m=mediator, Sex=covariate, y1& y2=outcome) DEFINE: xw=x*w; USEVARIABLES ARE x Sex w m y1 y2 tchid xw; MISSING=ALL(999); CLUSTER = tchid; BETWEEN= x xw; ANALYSIS: TYPE = TWOLEVEL RANDOM; STARTS=500; STITERATIONS=500; MODEL: %WITHIN% m y1 y2; y1 ON Sex m; y2 ON Sex m; %BETWEEN% x m y1 y2; mom ON Sex w x (a1) xw (a2); y1 ON Sex x xw w m (b1); y2 ON Sex x xw w m (b2); MODEL CONSTRAINT: NEW(ind1 ind2 wmodval); wmodval=1; ind1=(a1+a2*wmodval)*b1; ind2=(a1b+a2*wmodval)*b2; *** ERROR in VARIABLE command TYPE=TWOLEVEL requires specification for the CLUSTER option. 


Currently you have CLUSTER=tchid in the DEFINE section. You may want to move the command "DEFINE: xw=x*w;" outside the VARIABLE section. 

Yan Liu posted on Sunday, August 17, 2014  8:57 pm



Dear Dr. Preacher, Thank you so much! It works! I have one more question. I saw that wmodval is defined as 1 in an example (model 2) you provided in your paper (Preacher, K. J., Rucker, D. D., & Hayes, A. F. (2007). Addressing moderated Mediation hypotheses: Theory, methods, and prescriptions.) What is this wmodval? How should we give the value to it? Thanks! Yan 


wmodval is any value of the moderator at which you wish to estimate the effect of x on y. It could be the moderator's mean, the minimum or maximum, 1SD above the mean, etc.  anything. You should look into the LOOP command in Mplus; it makes probing interaction effects easier. 

Carolyn CL posted on Monday, August 25, 2014  9:15 am



I have one dependent level1 variable(y), one level1 independent variable(z), one level1 mediator(m1), two level2 mediators(m2_1, m2_2), and two level1 controls(age and sex). I include both crosslevel indirect pathways (111, 121, 221) and mediated moderation (interactions): USEVARIABLES ARE ID y z m1 m2_1 m2_2 age sex zXm1 m2_1Xm2_2 zXm2_1 m1Xm2_2; CLUSTER = ID; BETWEEN = m2_1 m2_2 m2_1Xm2_2; DEFINE: zXm1 = z*m1; m2_1Xm2_2= m2_1*m2_2; zXm2_1= z*m2_1; m1Xm2_2= m1*m2_2; ANALYSIS: TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% y z m1 zXm1; y ON z m1 zXm1 age sex; m1 ON z age sex; %BETWEEN% y z m1 m2_1 m2_2 zXm1 m2_1Xm2_2 zXm2_1 m1Xm2_2; y ON z(a); y ON m1(b); y ON m2_2(c); y ON m2_1(d); y ON age sex zXm1 m2_1Xm2_2 zXm2_1; y ON m1Xm2_2(j); m1 ON z(e); m1 ON m2_2(f); m1 ON m2_1(g); m1 ON age sex; m2_2 ON m2_1(h); m2_1 ON z(i); m1 WITH m1Xm2_2; MODEL CONSTRAINT: NEW(INDgb INDfb INDeb INDsf xmodval); INDgb=g*b; INDfb=f*b; INDeb=e*b; xmodval = 1; INDsf=f+(b+j*xmodval); Can you confirm that a sig coefficient for the m1Xm2_2(j) suggests a moderated mediated effect, but not an indirect effect (given nonsig INDfb term)? 


In your model, a significant j coefficient suggests a significant interaction between m1 and m2_2 in the 'between' model, not moderated mediation, and not an indirect effect. Also, instead of: INDsf=f+(b+j*xmodval); I think you mean: INDsf=f*(b+j*xmodval); ...which is the conditional indirect effect of m2_2 on y through m1, at the point where m2_2 = 1. 

Carolyn CL posted on Monday, August 25, 2014  3:54 pm



Thank you for this. A few follow up questions, if I may: 1) What can I make of a sig interaction, but no sig indirect or conditional indirect effects? 2) The estimated direct and indirect paths reflect unconflated estimates of within and between effects, with random intercepts? 3) Because I have very small cluster sizes (80% N =1, 20% N = 25), the within level of the model has very little power? 


1) A n.s. indirect effect means that there is no evidence that the indirect effect departs from zero. A n.s. conditional indirect effect means that the effect in question does not detectably differ from zero at the chosen value of xmodval (but it might at others). The interaction's significance pertains only to the two interacting variables, and does not necessarily reflect the presence or absence of moderated mediation. We discuss how to quantify and test for the presence of moderated mediation for some models, including this one, in Appx. A of this paper (see Scenario 1). In your case, you can obtain a CI for f*j. If the CI excludes zero, that is evidence for moderated mediation. 2) You have no within effect of m2_2 on m1, only a between effect (f). There are both within and between effects of m1 on y, and only a between effect of the interaction term m1Xm2_2 (j). j is a strictly between effect, so all effects of interest are at the between level, and occur among level2 variables and the random intercepts for the level1 variables. 3) It is difficult to say without knowing more about your design and your expected effects. You can run a power analysis in Mplus, but because you already have the data it is probably too late to glean anything useful from a power analysis. 

Carolyn CL posted on Wednesday, August 27, 2014  1:06 pm



Many thanks for this. To be clear, the model now includes: Y ON m1Xm2_2(j) !interaction effect INDfb = f*b !indirect effect effect of m2_2 on Y through m1 INDsf = f*(b+j*xmodval) !conditional indirect effect of m2_2 on Y, where effect through m1 depends on value of m2_2 INDjf = f*j !moderated mediation effect where strength of indirect effect of m2_2 on Y through m1 is moderated by m1 


That looks right to me. 

Carolyn CL posted on Wednesday, September 03, 2014  8:59 am



Dear Dr. Preacher, I would like to obtain predicted values for the significant interaction term in my model. I am unsure as to how to proceed in the MSEM framework and was hoping you would be able to provide me with a reference or formula to obtain predicted (fitted) values of y given specified values of x, and specified values for the interaction term. 


I am not sure how to do that with Mplus. It sounds like you want to compute predicted yvalues given your equation with interactions. If so, that can be done using methods developed for regular regression models, perhaps using a spreadsheet. 

Carolyn CL posted on Friday, September 05, 2014  12:37 pm



Thanks for this. In the end, given that there were no sig. conditional indirect effects nor moderated mediated effects, we decided to simply estimate the interaction term. However, I noticed that inclusion of the interaction term (m1Xm2_2) changes the direction of the m2_2 direct effect on y (without the interaction term B = .09, ns; with the interaction term B = .19,ns). 1) Is this likely a result of adjusting for the interaction term, or should I be concerned about potential multicollinearity? I also noticed that in fig. A (Model 1) in Preacher, Rucker & Hayes (2007) it appears as though the interaction term (xm) is allowed to correlate with both x and m, but the syntax for Model 1 in the appendix only specifies a correlation between xm and m. (2) Should only a correlation between xm and m be specified when estimating an interaction term? I ask in part because my coefficients (size) and their significance level change in somewhat meaningful ways depending on whether I specify a correlation between xm and m, or include an additional correlation between xm and x. 


1a. The coefficient has a different interpretation after including the product, and thus a different value. Prior to adding the product, c is the effect of m2_2 holding constant m1 (and all other predictors). After adding the product, c is the effect of m2_2 where m1 = 0 (holding constant all other predictors). 1b, 2. The code is outdated. I would add the covariance. Otherwise you risk introducing misfit. xm and m will almost certainly be correlated, and fixing this parameter to 0 can induce bias. 

Carolyn CL posted on Monday, September 08, 2014  7:20 am



1) To be clear, when you say 'I would add the covariance', you mean 'xm WITH m' and 'xm WITH x'? 2) Also, should I be concerned that when I run the model as a multiple linear regression (in SPSS) and include the interaction term (m1Xm2_2) I get a VIF > 5 for the m2_2 coefficient? 3) My understanding is that the traditional approach taken to deal with multicollinearity induced by interaction terms is to mean center variables before creating the product term, but that the MSEM approach does not require centering of variables. Is this correct? 


1. Yes. Or more simply, 'xm WITH m x'. 2, 3. These sound more like regressionrelated questions than Mplusspecific issues. But in general, centering has no effect on estimates or tests of interaction effects. You might pursue this topic on the SEMNET listserv. 

Yan Liu posted on Saturday, September 13, 2014  8:17 am



Dear Dr. Preacher, I conducted a multilevel moderated mediational model. MODEL: %WITHIN% m y1 y2; y1 ON Sex m; y2 ON Sex m; %BETWEEN% x m y1 y2; mom ON Sex w x (a1) xw (a2); y1 ON Sex x xw w m (b1); y2 ON Sex x xw w m (b2); The model is terminated normally. However, my model fit is bad. Do you think it's because my model doesn't fit the data well or because of cluster size or other issues? Thanks a lot! Model fit: ChiSquare Test of Model Fit Value 636.624 Degrees of Freedom 7 PValue 0.0000 RMSEA Estimate 0.286 CFI 0.677 TLI 0.244 SRMR Value for Within 0.235 Value for Between 0.021 


It is probably because there are 7 parameters constrained to zero in your model, and some of these are not reasonable in light of the data. This is not a softwarespecific question. You might get better help on a general listserv like SEMNET. 


I am trying to calculate a multilevel mediated moderation (analogous to model 2 in Preacher, Rucker & Hayes, 2007)where a third variable (Level 2) affects path a (Mediation is lower level). I wanted to build my models gradually, so I started off calculating my 111 mediation using Preachers' syntax from the top of this post. Yet I keep on getting the following error message: *** FATAL ERROR THERE IS NOT ENOUGH MEMORY SPACE TO RUN THE PROGRAM ON THE CURRENT INPUT FILE. THE ANALYSIS REQUIRES 5 DIMENSIONS OF INTEGRATION RESULTING IN A TOTAL OF 0.75938E+06 INTEGRATION POINTS. THIS MAY BE THE CAUSE OF THE MEMORY SHORTAGE. YOU CAN TRY TO REDUCE THE NUMBER OF DIMENSIONS OF INTEGRATION OR THE NUMBER OF INTEGRATION POINTS. Is there anything I can do about this? I also tried to specify sa and sc as random, only keeping sb fixed (following my hypotheses), sa  m ON x; y ON m(sb); sc  y ON x; (rest of the syntax being equal) yet somehow MPLUS does not recognize sb in this way. *** ERROR in MODEL command Unknown variable(s) in a WITH statement: SB What did I do wrong? Your help would be very much appreciated! 


You can try using INTEGRATION=MONTECARLO (5000); Five dimensions of integration is computationally heavy. You may want to try the random effects one at a time and estimate them as fixed if the variances are not significant. To change sb  y ON m; to a fixed effect, say y ON m; 

Yan Liu posted on Tuesday, November 11, 2014  5:02 am



Dear Dr. Muthen, I am trying a 211 multilevel moderated mediational model. My outcome is a count variable (minutes of phyical activities) with a long tail. If the outcome is treated as continuous, the model works, but the model fit is bad. However, the model won't run if the outcome is treated as count. Could you please give me some advice? Thanks! Yan (note. x=predictor, y=outcome, mod=moderator,med=mediator) USEVARIABLES ARE x covariate mod med y tchid x_mod; CLUSTER = tchid; BETWEEN= x ; COUNT ARE y (nb); DEFINE: x_mod = x*mod; ANALYSIS: TYPE = TWOLEVEL RANDOM; STARTS=500; STITERATIONS=100; ALGORITHM = INTEGRATION; INTEGRATION =GAUSSHERMITE; MCONVERGENCE = 0.01; MODEL: %WITHIN% Y ON covariate med; %BETWEEN% med ON covariate mod x (a1) x_mod (a2); y ON covariate x mod x_mod med (b1); MODEL CONSTRAINT: NEW(ind1 mod); mod=1; ind1=(a1+a2*mod)*b1; 


Please send the output and your license number to support@statmodel.com. 

Johanna Seiz posted on Wednesday, November 12, 2014  12:48 am



Dear Linda, thank you for the quick reply. If I use Montecarlo Integration (as you suggested), I always receive the error: *** FATAL ERROR THIS MODEL CAN BE DONE ONLY WITH MONTECARLO INTEGRATION. ..which I really don't understand, as I used it. Concerning the fixed effects, when I specify them as you suggested, how can I calculate the Model constraints/indirect effect if I do not give a label to the slope? (as it is a 111 Mediation?) Thanks again! 


Please send the output and your license number to support@statmodel.com. You can label the slope if you want to. If you have a problem with that, send the output. 


I am testing a ML moderated mediation with the mediation model at level 1 and the moderator at level 2. The level 2 moderator is categorical. Will Mplus allow me to dummy code this variable and include dummy variables as level 2 moderator? 


Yes. 

Cassie Suh posted on Monday, February 09, 2015  11:51 pm



Hello! I am trying to do a 111 multilevel mediation with a level 2 moderator that impacts path a (model2 moderated mediation) The code I wrote so far is: (m<y, h <m, q <x, u<w, and b,c,d,e are level 1 control variables) Variable: Names are a b c d e f g h i j k l m n o p q r s t u; Missing are all (99); usevariables are a b c d e h m q u; Cluster is a; Within are b c d e; Between are u; Analysis: Type=Twolevel random; Model: %WITHIN% sa  h(m) ON q(x) b c d e; sb  m(y) ON q(x) b c d e; sc  m(y) ON h(m); h m; %BETWEEN% sa sb h m q; [sa](a1); [sc](b1); m ON u(w); h ON u(w); sa ON u(w)(a3); sb ON u(w); MODEL CONSTRAINT: NEW(ind1 ind2 ind3); ind1= b1*(a1+a3*(2.66)); ind2= b1*(a1+a3*(0); ind3= b1*(a1+a3*2.66); Output: cinterval; It runs without problems but I'm not sure if its correct(especially the control variables part). Also, if it is correct, do the significant results of SA ON U tell me that there is a moderated mediation? Or as the CI results for IND1 IND2 IND3 all include 0 is there no interaction effect? Thank you. 

Cassie Suh posted on Tuesday, February 10, 2015  6:22 am



Hello again, I wanted to revise my question but I couldn't find an edit or delete function so I'm just adding on to above. I'm sorry for not being able to make it into one post. Along with wanting to know if the code in the above post is correct, again, assuming that the code above is correct, if SB ON U(interaction) is significant then I have read that there is moderated mediation. Is this correct? However, I have also read that looking that the conditional indirect effects per group, the CI intervals for some groups should include 0 while others do not(interpretation of PROCESS results). What does it mean if, as mentioned above, there is a significant interaction effect but 1) all the CI include 0s 2) all the CI don't include 0 and IND1, IND2 and IND3 are all significant. In other words, I would like to know how to interpret the results to see if there is indeed the effect I'm looking for. Thank you very much in advance. 


Your input %WITHIN% sa  h(m) ON q(x) b c d e; sb  m(y) ON q(x) b c d e; sc  m(y) ON h(m); is not correct. You can have only one slope on the right of the bar () so e.g. sa  h on q; And I don't know what the parenthetical x, m, y refer to  are they labels? Only one label before ; can be used. Also, your notation m<y, h <m, q <x, u<w is unclear to me  do you really mean for y to influence m, for instance? Mediation modeling uses x>m>y (typically going from left to right as I show). Let's straighten this out first. 

Cassie Suh posted on Wednesday, February 11, 2015  1:34 am



oh, i see that it could be confusing, i only used the < and () signs so that you could better follow what i named my variables. For instance, i only meant the q was what i named my x variable, m my y variable and so on. i know that () and stuff aren't used in mplus and the arrows have nothinf to do with my model. Therefore, excluding that i would say sa  h on q h on b c d e? what about my other questions? thank you! 


Please send your output to Support and explain exactly what you are asking about in the output. 


I have the exact same question as this thread started with (Antje Schmitt, Oct 27 2008). I have a 111 mediation model moderated by a level 2 variable (first stage moderation). I'm trying to find out three things: 1) How to estimate the mediation model in Mplus. I usually use the indirect model (IND) for this. Is this ok to use in a twolevel model? 2) I don't understand the syntax dr. Preacher gave as answer to the first post (to test the moderated mediation model). More specifically, where is the moderator variable in this syntax? Or, is the interaction effect estimated by using random slopes? If so, how do I know the random slopes are caused by my moderator? 3) If I have a binary variable for the level 2 moderator, is is possible to use multigroup analysis and compare the mediation models between two groups? Or is this not an optimal solution? Thank you! 


1) Yes. 2) See the handout and video for our Topic 7 short course, slides 6785. 3) It is a good solution. 


Thank you for your quick reply Bengt. I watched the video in which you go over the syntax briefly. Just to make sure I understand it correctly: this syntax is just to estimate the 111 mediation model and will show if the indirect effect varies on the between level, right? Because if there is no variance on level two, there is no need to explain this variance with a level 2 variable. I just ran the syntax separately for four x variables and the variances of sa, sb, sc and the indirect effect are all not significant except for one (sa for one x). Can I then conclude that the mediated model does not vary between groups? Thank you! 


When you say "group" in your last sentence, do you mean "cluster/level2 units"? 


I think I should have said, "can I then conclude that the mediated model does not vary between level2 units". The level 2 units are persons (we have five days clustered in persons). We'd like to know if the mediation model differs between persons with and without children, so that is a level2 variable. That's why I said groups, referring to people with children as group 1 and people without children as group 2. But I guess I can only say that the mediation model does not vary between people, which indirectly means it also does not vary between people with and without children. Is that correct? 


Right. 

Dan R. posted on Wednesday, May 20, 2015  8:10 am



If I have a level 1 mediation model, but the mediator is best described as a moderation (i.e., mediator variable * dummy coded condition), what is the best way to include the main effects in the within level? For example: M*C ON X; Y ON M*C; Y ON X; 1) I presume I should also include Y ON M and Y ON C, no? 2) If the main effects are included at the within level, should the moderation M*C and Y be the only variables with between level variance? If any articles or information comes to mind regarding this unique 'moderated effect as a mediator' situation, I'd love to read further. Thank you for your help! 


I think what you are saying is that you want the regression slope of Y on M to be different for (moderated by) different values of C. Then you say y on x m c mc; m on x; There may be substantive reason to regress m not only on x, but also on c. Note that the inclusion of the mc interaction variable throws off the chisquare testing and it should be ignored. See Preacher et al.'s (2007 Model 3. 

Tao Yang posted on Tuesday, June 02, 2015  3:34 pm



Hello, I have a 211 model with a level1 moderator for the firststage mediation. x was measured at level2. m,y,and w(moderator) were measured at level1 and had variance at level2. If I understand correctly, the moderated mediation would operate at level2 so I computed level2 mean of w as the moderator. Below is my syntax. VARIABLE: NAMES = y x m w w_mean clus; !w_mean is level 2 mean of w USEVARIABLE = y x m w_mean xw; BETWEEN = x w_mean xw; CLUSTER = clus; MISSING = .; DEFINE: CENTER x w_mean (GRANDMEAN); xw = x * w_mean; ANALYSIS: TYPE = TWOLEVEL; MODEL: %WITHIN% ! no hypothesis at within level %BETWEEN% y ON m (b) x (cp) w_mean xw; m ON x (a1) w_mean xw (a3); MODEL CONSTRAINT: NEW(ind_l ind_h tot_l tot_h); ! betweenlevel conditional indirect effect and total effect ind_l = b*(a1+a3*2);! suppose 1SD of w_mean is 2 ind_h = b*(a1+a3*2); ! suppose +1SD of w_mean is 2 tot_l = cp+ind_l; tot_h = cp_ind_h; Can I have your suggestion on: (1) Was model specification and conditional indirect effect correct? (2) Was it necessary to have "y ON w_mean xw" under %BETWEEN%? Thanks!! 


1. The Between looks fine, but you want to make sure that m, y and w are allowed to at least correlate on Within. And if you have m> y on Between, why wouldn't that hold also on Within? 2. It sounds like your main focus was on moderating the x> path, but often that moderator and its interaction also influence y. I don't think it is always substantively necessary to include that, but practically speaking it may be a good idea. 

Tao Yang posted on Tuesday, June 02, 2015  10:52 pm



Thank you, Bengt! This is very helpful! I realized that m, y and w also had variances on another level2 cluster. So x was on level2b. m, y, and w on level1 and had variances on level2a and level2b. My focus was w moderating the first stage of the 211 mediation on level2b. Syntax below. VARIABLE: NAMES = y x m w w_mean2a w_mean2b level2a level2b; ! w is original value ! w_mean2a is mean w on level2a ! w_mean2b is mean w on level2b USEVARIABLE = y x m w_mean2a w_mean2b w_c xw; CLUSTER = level2b level2a; WITHIN = w_c; BETWEEN = (level2a) w_mean2a (level2b) x w_mean2b xw; DEFINE: w_c = w  w_mean2a  w_mean2b; xw = x * w_mean2b; ANALYSIS: TYPE = CROSSCLASSIFIED; MODEL: %WITHIN% y ON m; ! m > y holds on Within w_c WITH m y; %BETWEEN level2a% y ON m; ! m > y holds on level2a w_mean2a WITH m y; %BETWEEN level2b% y ON m (b) x (cp) w_mean2b xw; m ON x (a1) w_mean2b xw (a3); (1) Does %BETWEEN level2b% portion look right? (2) To correlate w, m, and y on Within and Level2a, I decomposed w into mean on level2a, mean on level2b, and w on Within. Is it the right approach in crossclassified data? Okay to compute w on Within as "w  w_mean2a  w_mean2b"? Thanks!! 


Looks reasonable. 

Tao Yang posted on Thursday, June 04, 2015  6:33 am



Thank you, Bengt! 

tom norton posted on Wednesday, August 05, 2015  11:12 pm



Hi Bengt I'm attempting to run a level1 mediation with two level2 moderators. W moderates the XM path only, and V moderates the MY path only: VARIABLE: NAMES = ID X M W V Y; USEVARIABLES = ID X M W V Y; CLUSTER IS ID; MISSING ARE ALL(99); BETWEEN ARE W V; WITHIN ARE X; ANALYSIS: TYPE = TWOLEVEL RANDOM; ALGORITHM = INTEGRATION; INTEGRATION = MONTECARLO; MITERATIONS = 1000; MODEL: %WITHIN% X M Y; sa  M ON X; sb  Y ON M; sc  Y ON X; %BETWEEN% sa sb sc M Y; sa WITH sc M Y; sa WITH sb(cab); sb WITH sc M Y; sc WITH M Y; Y ON V (b2); M ON W (a2); sa ON W (a3); sb ON V (b3); [sa](sa); [sb](sb); [sc](sc); OUTPUT: TECH1 TECH8 CINTERVAL; I am confronted with the error message: THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY DUE TO A NONZERO DERIVATIVE OF THE OBSERVEDDATA LOGLIKELIHOOD. THE MCONVERGENCE CRITERION OF THE EM ALGORITHM IS NOT FULFILLED. CHECK YOUR STARTING VALUES OR INCREASE THE NUMBER OF MITERATIONS. Would you suggest increasing the MITERATIONS further, or making changes elsewhere? Regards Tom Norton 


I would try the suggestion of increasing the number of MITERATIONS as a first step. The default is 500. 

tom norton posted on Sunday, August 09, 2015  6:07 pm



Hi Linda, I increased the number of MITERATIONS to 2000, and received the following error message: THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY DUE TO A CHANGE IN THE LOGLIKELIHOOD DURING THE LAST E STEP. AN INSUFFICENT NUMBER OF E STEP ITERATIONS MAY HAVE BEEN USED. INCREASE THE NUMBER OF MITERATIONS OR INCREASE THE MCONVERGENCE VALUE. ESTIMATES CANNOT BE TRUSTED. SLOW CONVERGENCE DUE TO PARAMETER 20. THE LOGLIKELIHOOD DERIVATIVE FOR THIS PARAMETER IS 0.14395229D+00. What would you suggest as a next step? 


Try integration = montecarlo(5000); Ask for tech8 and make sure you don't have negative abs changes which would point to poor precision. Also look to see how many dimensions of integration you have  the more you have, the more integration points you need. Alternatively, you can introduce one random slope at a time and see if it is needed, that is, if it really has a substantial variance; most don't. 

tom norton posted on Wednesday, August 12, 2015  12:55 am



Hi Bengt, I ran the model with montecarlo(5000) and 2000 MITERATIONS with the following message: THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY DUE TO A NONZERO DERIVATIVE OF THE OBSERVEDDATA LOGLIKELIHOOD. THE MCONVERGENCE CRITERION OF THE EM ALGORITHM IS NOT FULFILLED. CHECK YOUR STARTING VALUES OR INCREASE THE NUMBER OF MITERATIONS. ESTIMATES CANNOT BE TRUSTED. THE LOGLIKELIHOOD DERIVATIVE FOR THE FOLLOWING PARAMETER IS 0.31927547D+00: Parameter 14, %BETWEEN%: SA I found negative abs changes for approx 1600 MITERATIONS 


If you don't have more than say 4 dimensions you can stay with the default integ = 15 and get good precision without neg abs changes. 


Dear Dr(s) Muthen, I have 111 multilevel mediation model, with moderator on level 2. Also, I need a model with nonlinear moderator.Is it possible to test such a multilevel model with Mplus and how could I perform the analyis? I created this sintax: TITLE: two level nonlinear moderated mediation; Data: file is C:/NJ.txt; Variable: names = id y x m w; Usevariables = id y x m w xw z xz; WITHIN = x m; BETWEEN = w z; CLUSTER = id; DEFINE: xw=x*w; z=w*w; xz=z*x; !nonlinear interaction Analysis: TYPE= TWOLEVEL RANDOM; ESTIMATOR=MLR; ALGORITHM=INTEGRATION; Model: %WITHIN% m ON x(aw); ! regress m on x, call the slope "aw" y ON m(bw); ! regress y on m, call the slope "bw" y ON x; ! regress y on x y ON m x; s  m ON x; %BETWEEN% m w xw z xz; s ON w s ON xw; s ON z; s ON xz; MODEL CONSTRAINT: NEW(indw); indw=aw*bw; Output:sampstat stdyx TECH1 TECH8 CINTERVAL; Thanks a lot in advance! 


Are you asking about a nominal moderator or a nominal mediator. In your support question you say a nominal mediator. 


Dear Linda, I am asking about nonlinear (squared) moderator. 


You regress s on that squared moderator on Between. 


I want to know does this look correct? Thank you. 


I see s on z; on between, so that looks correct for capturing a quadratic effect of your betweenlevel variable w. But you also have s ON xw; The xw variable has variation on both within and between, but you don't include it on within so I worry that no variance for xw is estimated on within. If you don't want to deal with xw on within you can create a cluster mean version of x and then create xw and work with it on between only. 


Hi Linda, I am running multilevel moderated mediation (you can find it here: https://mulmodmed.files.wordpress.com/2015/09/document2.jpg All variables are level1. It is a diary study (the clustering variable is persons' "id"). I have tried to adapt the code posted by Kristopher Preacher on Oct 27, 2008. I understand the original code does not include the moderator effect, so I added it, as far as I understand it on the basis of your forum. I am new to Mplus and there must be something wrong. My code is now as follows: CLUSTER = CodigT1; DEFINE: xw = x*w; ANALYSIS: TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% x m w xw y; sa  m ON x; sb  y ON m; sc  y ON x; sw  sa ON xw; sw1  m ON w; %BETWEEN% sa sb sc sw1 m y xw; sa WITH sb(cab); sa WITH sc m y xw sw1; sb WITH sc m y xw sw1; sc WITH m y; m WITH y; [sa](sa); [sb](sb); [sc](sc); [sw](sw); [sw1](sw1); MODEL CONSTRAINT: NEW(ind); ind=sa*sb+cab; ! indirect effect OUTPUT: TECH1 TECH8; Could you please help me to identify the problem and suggest any change in the code so it works for my model? I will appreciate a lot your help! 


Please send the output and your license number to support@statmodel.com. 

Dirk Pelt posted on Wednesday, September 23, 2015  9:57 am



Dear Linda and Bengt, I am using an example by Hayes (and Preacher). However, I want to add moderation by X (level 2) of the Y>M relation (level 1). Here is the syntax: DATA: file is doctors.txt; VARIABLE: names are docid patient volinfo ppart length size training doccond ppartmn trainmn; usevariables are docid volinfo ppart doccond; cluster is docid; between is doccond; ANALYSIS: TYPE = random twolevel; MODEL: %WITHIN% s_bvolinfo on ppart; %BETWEEN% [s_b] (bw); ppart on doccond (a); volinfo on ppart (bb); volinfo on doccond (cp); !freely estimate covariances between intercepts and b slopes; s_b with ppart volinfo; MODEL CONSTRAINT: new (direct indirect); indirect = a*(bw+bb); direct = cp; Adding the moderation is pretty straigthforward I guess, in the BETWEEN part: s_b on doccond (cp2) However, what will the new direct and indirect effects be? I am guessing something like: indirect = a*((bb+bw)*doccond); direct = cp+((bb+bw)*ppart); Is this correct? With kind regards, Dirk Pelt 


Hi Dirk. Your main code looks correct, and you are right to use the sum (bw+bb) to represent the 'between' effect of ppart on volinfo. However, s_b is the 'within' effect of ppart on volinfo, and thus does not participate in the indirect effect. With respect to mediation, it should not matter whether you regress s_b on doccond, so the direct and indirect effects remain as you had them originally. Just be aware that if you do regress s_b on doccond, this will change your estimate of bw, and hence your estimate of the 'between' effect bb+bw, so proceed with caution. If you instead believe that the 'between' effect of ppart on volinfo is moderated by doccond, you could create a product of doccond and the 'between' component of ppart using XWITH, and add that product as a predictor of volinfo in the 'between' model, leaving the 'within' model alone. 

Dirk Pelt posted on Thursday, September 24, 2015  9:57 am



Dear prof Preacher, thank you for your answer, I get it. When you state 'if you do regress s_b on doccond, this will change your estimate of bw', is this because it is conditional on X now? I.e. MPlus prints out the effect where X=0 (as in standard OLS regression)? I am currently working with my own data, and everything seems to work out fine. I noticed that the s_b variance was significant in previous models (e.g. Y>M, controlling for X). However, in the full moderated mediation analysis it is not significant anymore. Can I conclude that adding X has 'explained away' the variance in the Y>M slope? Kind regards, Dirk 


The bw slope becomes conditional when you add a moderator. The new bw is the 'within' effect of ppart on volinfo when doccond = 0. And it does sound like you've explained some variance in the random slope. 

Kevin Liu posted on Thursday, September 24, 2015  11:50 am



Dear Prof Preacher, I am trying to run a 111 moderated mediation. w is moderator which moderate the path a. Is this code right? VARIABLE: NAMES ARE id x m y w; CLUSTER IS id; ANALYSIS: TYPE = TWOLEVEL RANDOM; MODEL: %WITHIN% sa  m ON x; sb  y ON m; sc  y ON x; m y; %BETWEEN% sa sb sc m y; sa WITH sb(cab); sa WITH sc m y; sb WITH sc m y; sc WITH m y; m WITH y; y ON w; m ON w; sa ON w; [sa](sa); [sb](sb); [sc](sc); 


See the handout on our website for our short course Topic 7, slides 8083. 

Dirk Pelt posted on Tuesday, September 29, 2015  12:07 pm



Dear Prof. Preacher (and others), thanks for the help so far. I have a question on centering in a 211 model. Am I correct that group mean centering of M is virtually impossible, given that it is the dependent variable in path A? As X does not vary within groups, when M is group mean centered the coefficients in the M>X part turn out to be 0 and the model does not run. So I guess I am left with an uncentered or grandmean centered M. However, as I stated in a previous question, I am interested in moderation of the YM relation by X (crosslevel interaction). Theoretically I expect that X moderates the within relation between YM, therefore I would want M to be group mean centered. Are there any other options? Thank you, Dirk 


You are correct in saying that X cannot affect the group mean centered M. However, it can affect the clusterlevel portion of M (whether you use a latent variable / random intercept or an observed cluster mean to represent it). X can moderate the 'within' effect of M on Y (a crosslevel interaction, as you note), but this 'within' M>Y effect  whether or not it is moderated by the level2 X  cannot be part of an indirect effect initiated by X. 

Dirk Pelt posted on Thursday, October 01, 2015  12:08 pm



Thank you again, this really is of great help. Unfortunately it creates some more confusion for me and actually brings me back to my very first question.. Using your syntax from the supplemental material from Preacher, Zyphur & Zhang (2010) (using latent variables): sb  y ON m; %BETWEEN% x m y; m ON x(a); y ON m(bb); y ON x; sb WITH x m y; [sb](bw); MODEL CONSTRAINT: NEW(b indb); b=bb+bw; indb=a*b; However, as you replied on Sept 24th 's_b is the 'within' effect of x on y, and thus does not participate in the indirect effect.' Shouldn't the latter part then be changed into: MODEL CONSTRAINT: NEW(b indb); totalb=bb+bw; indb=a*bb; ? 


Hi Dirk. I believe both statements are correct. The 2010 syntax is correct. The Sept. 24th comment looks odd because bw is in the formula for the 'between' effect of M on Y. However, what you really want here is the purely level2 or 'between b' effect, and in this specific model the way to compute that purely level2 'b' effect is to sum bw and bb. What we've been calling bb above is actually the contextual effect, or the difference between the levelspecific 'within' and 'between' effects: b.contextual = b.between  b.within We want b.between: b.between = b.contextual + b.within ...and the result is purely level2. If we instead did as you suggest above, 'a' would be multiplied by the contextual effect, not the purely level2 'b'. 


Hi, The above post was really helpful. I have a question in regards to the last few posts. If I were to include a moderation of a level 2 variable into the above statement sb  y ON m; %BETWEEN% x m y w; m ON x(a); y ON m(bb); y ON x; sb WITH x m y w; [sb](bw); sb on w(b3); y on w; MODEL CONSTRAINT: NEW(b indblo indbhi); b=bb+bw; indblo=a*(b+b3+low); indbhi=a*(b+b3+high); and use b to have the purely level 2 effect, would it be correct to have b3 (as it should only have between variance) in the modmed? Also, how would I go about turning this into a serial moderated mediation, meaning if I wanted to add a 11 c path at the end? Is it only possible to do the 11 path as a random slope as it has been done for b? As if I would have it as a fixed within effect, 'a' would affect the within of this relationship and not the between. Your help would be highly appreciated! Thanks 


Preacher and I are discussing this because the answer isn't obvious. 


Hi Bengt, Many thanks for taking the time. Best, Kristin 


Just to let you know, I also tried the latent factor XWith approach that Preacher developed, but can't get MPlus to run it if I include any control variable. This is probably down to my sample size. Hence, this approach is not really an option. 


From briefly looking through the formulas it seems to me that your moderated indirect effect should be: a*(bb+bw+b3*W); where W contains the moderator value you are interested in. 


Thank you! 


Hi, I am running a 111 model with random slopes (MSEM), using the syntax provided by Preacher, Zyphur, & Zhang (2010). The model runs fine until I try to add my covariates (control variables). When I add them, I receive the lengthy error message below. I would be grateful for some guidance on how to deal with this, as well as an example of how to include a covariate in the syntax, to ensure that I'm doing it correctly. THE ESTIMATED WITHIN COVARIANCE MATRIX IS NOT POSITIVE DEFINITE AS IT SHOULD BE. COMPUTATION COULD NOT BE COMPLETED. THE VARIANCE OF OPEN APPROACHES 0. FIX THIS VARIANCE AND THE CORRESPONDING COVARIANCES TO 0, DECREASE THE MINIMUM VARIANCE, OR SPECIFY THE VARIABLE AS A BETWEEN VARIABLE. THE MODEL ESTIMATION DID NOT TERMINATE NORMALLY DUE TO AN ERROR IN THE COMPUTATION. CHANGE YOUR MODEL AND/OR STARTING VALUES. A MATRIX COULD NOT BE INVERTED DURING THE H1 MODEL ESTIMATION. THE ESTIMATED WITHIN COVARIANCE MATRIX IS NOT POSITIVE DEFINITE AS IT SHOULD BE. COMPUTATION COULD NOT BE COMPLETED. THE VARIANCE OF OPEN APPROACHES 0. FIX THIS VARIANCE AND THE CORRESPONDING COVARIANCES TO 0, DECREASE THE MINIMUM VARIANCE, OR SPECIFY THE VARIABLE AS A BETWEEN VARIABLE. THE H1 MODEL ESTIMATION DID NOT CONVERGE. CHISQUARE TEST AND SAMPLE STATISTICS COULD NOT BE COMPUTED. 


Please send the output and your license number to support@statmodel.com. 


Dear Dr Preacher, I am running a 111 MSEM with random slopes using Model J to accompany Preacher, Zhang, & Zyphur. In the same time, as in my model (https://mulmodmed.files.wordpress.com/2015/09/document2.jpg) I have a level1 moderator of the path a, I combined it with the Model 2 from Preacher Rucker& Hayes,2007. My syntax is: MODEL: %WITHIN% sa  m ON x; sb  y ON m; sc  y ON x; sw  m ON xw; %BETWEEN% sa sb sc x m y w xw; sa WITH sc x m y w xw; sa WITH sb(cab); sa WITH sw(caw); sb WITH sc x m y w xw; sc WITH x m y w xw; m ON x(ab); m ON w; m ON xw(db); y ON m(bb); y ON x; y ON w; y ON xw; [sa](aw); [sb](bw); [sw](dw); MODEL CONSTRAINT: NEW(a b d indb indw wmodval); wmodval = 1; a=aw+ab; b=bw+bb; d=dw+db; indw=((aw+dw*wmodval)*bw+caw); indb=((a+d*wmodval)*b); Did I do well by estimating the "caw" level2 covariance of sa and sw and then by using the "caw" in the MODEL CONSTRAINT section, instead of "cab", when calculating the within conditional indirect effect? Do you see any problem with this syntax? Thank you for your help! 


I don't think anyone has yet done the math to know how to deal with caw in a model like this. I think you would still need to include cab, however. In any event, I think I would not treat the product xw this way (that is, by creating a product and splitting it into 'within' and 'between' components). See p. 7 of: http://quantpsy.org/pubs/preacher_zhang_zyphur_(in.press).pdf ...where we argue that it makes more sense to split x into its component 'between' and 'within' parts first, and then create products of those components. You might see Models 15 and 16 in the syntax appendix here as a place to start: http://quantpsy.org/pubs/preacher_zhang_zyphur_2015_(code.appendix).pdf The code is not for moderated mediation, but we think it handles interactions in a reasonable way, and your y variable could be added to the code. 

Dirk Pelt posted on Wednesday, December 02, 2015  3:24 pm



Dear prof Preacher, I have another question on moderated mediation in a 211 model. I understand that conceptually 's_b is the 'within' effect of x on y, and thus does not participate in the indirect effect.' This implies that moderation of the x and y relation by M also does not participate in the indirect effect. However, in the syntax and mathematically, it does of course (through the mean of s_b). Taking a numerical example: [s_b] = .7 bb (contextual effect) = .1 M on s_b = .2 M on x (a) = .3 Thus, if M = 0, the indirect effect of x on y is .3 * (.7 + .1) = .24 If M = 1, the indirect effect of x on y is .3 * ((.7  .2) + .1) = .18 This implies that in fact we can speak of moderated mediation in a 211 design. Is this correct? Regards, Dirk 

Nükhet Agar posted on Saturday, December 05, 2015  3:23 am



Hi Everyone, My work is on hedonic adaptation. I have 2 manipulations prior to the experiment (A and B), and I repeatedly measure participants' enjoyment (DV). Afterwards, I ask them perceived variety of the category, which is the mediator. Here is what I have so far: proc mixed data=rearrange asycov covtest noclprint method=reml maxiter=100; class dv; model Z = Svariety Svariety*ManipulationA Svariety*ManipulationB Svariety*ManipulationA*ManipulationB Senjoyment Senjoyment*Variety Senjoyment*Variety Senjoyment*ManipulationA Senjoyment*ManipulationB Senjoyment*ManipulationA*ManipulationB /noint solution ddfm=kr covb; random Senjoyment Senjoyment*Variety Senjoyment*ManipulationA Senjoyment*ManipulationB Senjoyment*ManipulationA*ManipulationB/g gcorr type=un subject=subject; repeated / sp (pow) (time) group=dv subject=subject; ods output covb=acovfix asycov=acovrand solutionf=estfix covparms=estrand convergencestatus=converge; run; Given that my mediator does not change, it does not generate random effects, which is why it is not added to the random part of the equation. Am I on the right track? Could you help me identify what I am doing wrong? 


This is an Mplus discussion forum. 

Nükhet Agar posted on Saturday, December 05, 2015  6:32 am



My apologies for the SAS syntax. Given that the article originally is written in the code, and this group is able to help as far as I could see, I wanted to try and get your opinions. Though I do not currently use Mplus, I do have access to it.So any help in code for this particular program would also be appreciated. So let me try to reiterate what I was saying: There is one IV and one moderating variable, both manipulated and do not change within participants, only between participants. Their enjoyment ratings is measured 2 times, which id the DV. (in another experiment, it is measured 6 times). And the mediator is also measured once, after their enjoyment ratings. In sum: IV and MODERATOR: manipulated once, between subjects DV: Repeated measures (within subject) MEDIATOR: Measured once (changing across subjects depending on the IV and MODERATOR) With only one repeated measures variable (which is the DV), can I fashion a repeated moderated mediation model, and if so how? Thanks in advance. 


With 2 repeated DVs Y1, Y2 as an example you could arrange the variables in a wide form like: IV Moderator Mediator Y1 Y2 If the moderator for example moderates the regression of Mediator on IV you can define the interaction: Define: inter = IV*Moderator; and use the model: Model: y1 y2 on mediator IV; mediator on iv moderator inter; The Y's are then correlated due to common predictors and also a residual covariance. With more repeated measures you may want to formulate a growth model for the Y's so that they correlate that way. 

Nükhet Agar posted on Sunday, December 06, 2015  1:00 am



Thank you so much! 


Regarding Dirk Pelt posting of Dec 2  we will get back on this. 

Nükhet Agar posted on Monday, December 07, 2015  7:37 am



Hi again, First off, thank you again for your help. We have run the analysis according to your guidelines, which worked out perfectly. I do have one minor follow up question regarding this analysis. You have indicated that I need to formulate a growth model when I have more than two Ys. That being the case, we have tried the analysis you have written out above with multiple Ys (6 to be exact). The program ran this analysis without any problems, and also gave a significant result. So, my follow up question is: Is it correct to run this type of analysis with more than two Ys as well, or is this result unreliable? 


It is fine with several Y's. A growth model is not necessary. 


I would like to include a level2 moderator (called z) in a 111 mediation model described in Preacher, Zhang, & Zyphur (2011). The moderator is called z. I am unsure, whether the code is correct so far and how I need to specify the constraint for the moderated indirect path. %WITHIN% sa  m ON x; sb  y ON m; sc  y ON x; %BETWEEN% sa sb sc x m y z; sa WITH sc x m y; sa WITH sb(cab); sb WITH sc x m y z; sc WITH x m y z; m ON x(ab); y ON m(bb); y ON x; y ON z; z WITH x m; [sa](aw); [sb](bw); sa ON z (mod); MODEL CONSTRAINT: NEW(a b indb indw); a=aw+ab; b=bw+bb; indw=aw*bw+cab; indb=a*b; Many thanks in advance! 


You are on the right way, but note that [sa] (aw); is no longer the mean but the intercept of sa given that you have sa ON z; 


Thanks, Bengt! Am I on the right track with this? %WITHIN% sa  m ON x; sb  y ON m; sc  y ON x; %BETWEEN% sa sb sc x m y z; sa WITH sc x m y; sa WITH sb(cab); sb WITH sc x m y z; sc WITH x m y z; m ON x(ab); y ON m(bb); y ON x; y ON z; z WITH x m; [sa](aw); [sb](bw); [z](zmean); sa ON z (mod); MODEL CONSTRAINT: NEW(a b samean indb indw zlo zhi); a=aw+ab; b=bw+bb; samean=aw+mod*zmean; zlo=1; zhi=1; indb=a*b; indw=aw*bw+cab; indwlo=(samean+mod*zlo)*bw+cab; indwhi=(samean+mod*zhi)*bw+cab; 


I think so, but I don't have time to look at the details. 


Dear Dr. Preacher, I am approaching you with a question not actually related to MPlus, but to Model 1 of moderated mediation in Preacher, Rucker & Hayes (2007), because I am not sure how to formulate my hypothesis about this. My research approach is to investigate how 3 variables are linked to each other. Therefore, I am testing a mediation in hypothesis 1 and a moderation in hypothesis 2. Those hypotheses result in a model as stated in Model 1: I have an independent variable which might also works as a moderator of the relation between its mediator and the dependent variable. I just found one (German) study about the investigation of Model 1. The hypothesis there ist that, depending on the IV, the mediator and the DV are either positively or negatively correlated. This seems not to fit to my ideas up to now. Therefore I would like to know if the hypothesis could also be that, depending on the IV, the effect of the mediator on the DV ist either strong or weak? I intend to test this hypothesis with the SPPS macro PROCESS later on. Thank you and kind regards! 


Carolin  This forum is only for Mplusrelated questions. I will reply offlist. 


I am running a 111 model day=level1,persons=level2 %WITHIN% sc  Y ON X_c (sc); sb  Y ON M_c (sb); sa  M_c ON X_c (sa); %BETWEEN% sa sb sc X_c M_c Y; sa WITH sc X_c M_c Y; sa WITH sb(cab); sb WITH sc X_c M_c Y; sc WITH X_c M_c Y; M_c ON X_c (ab); Y ON M_c(bb); Y ON X_c; [sa](aw); [sb](bw); MODEL CONSTRAINT: NEW(a b indb indw); a=aw + ab; b=bw + bb; indw=aw*bw+cab; indb=a*b; I receive the following warning message: THE MODEL ESTIMATION HAS REACHED A SADDLE POINT OR A POINT WHERE THE OBSERVED AND THE EXPECTED INFORMATION MATRICES DO NOT MATCH. AN ADJUSTMENT TO THE ESTIMATION OF THE INFORMATION MATRIX HAS BEEN MADE. THE CONDITION NUMBER IS 0.187D02. THE PROBLEM MAY ALSO BE RESOLVED BY DECREASING THE VALUE OF THE MCONVERGENCE OR LOGCRITERION OPTIONS OR BY CHANGING THE STARTING VALUES OR BY USING THE MLF ESTIMATOR. THE STANDARD ERRORS OF THE MODEL PARAMETER ESTIMATES MAY NOT BE TRUSTWORTHY FOR SOME PARAMETERS DUE TO A NONPOSITIVE DEFINITE FIRSTORDER DERIVATIVE PRODUCT MATRIX. THIS MAY BE DUE TO THE STARTING VALUES BUT MAY ALSO BE AN INDICATION OF MODEL NONIDENTIFICATION. THE CONDITION NUMBER IS 0.108D12. PROBLEM INVOLVING THE FOLLOWING PARAMETER: Parameter 9, %BETWEEN%:[ X_C ] 


Please send the output and your license number to support@statmodel.com. 


111 with a level 2 moderation of X>M MODEL: %WITHIN% Y ON C; ! fixed effect control b1  M ON X; ! Random Path A b2  Y ON X; ! Random Direct Effect c' b3  Y ON M_c; ! Random Path B %BETWEEN% Y; ! no predictors of intercept [b1](a); ! mean of b1, call it a [b3](b); ! mean of b3, call it b M ON W; ! main effect for W b1 ON W (a2); ! crosslevel interaction b2; ! no predictor of slope b3; ! no predictor of slope M WITH b1 b2 b3; ! covary intercept and slope Y WITH b1 b2 b3; ! covary intercept and slope M WITH Y; ! covary y and m b2 WITH b1 b3; ! covary the slope b1 WITH b3(cab); ! covary a&b, call it cab MODEL CONSTRAINT: PLOT (cind); LOOP (modval, 1.54, 1.57, .1); !+ 2 std dev of W NEW(ind); ind=a*b+cab;!compute indirect effect cind = b*(a+a2*modval); !compute conditional indirect effect PLOT: TYPE = PLOT2; OUTPUT: TECH1 TECH8 CINTERVAL; Is code correct for the cond indirect effect w/95% CIs? I don't see cind in my output, how do I obtain it? The plot shows bands surrounding cind contain positive values and exclude zero up to .1 of my moderator but then cross zero at values greater than .1. Can I conclude sig positive cond indirect effects exist? Thanks 


You need to mention cind in NEW. 


Thank you, when I added cind to the New statement I received the following error message: *** ERROR in MODEL CONSTRAINT command A parameter label has been redeclared in MODEL CONSTRAINT. Problem with: CIND 


Please send the output and your license number to support@statmodel.com. 

Dirk Pelt posted on Monday, March 14, 2016  4:01 am



Dear Bengt, on Dec 2nd I posted the following question: I understand that conceptually 's_b is the 'within' effect of x on y, and thus does not participate in the indirect effect.' This implies that moderation of the x and y relation by M also does not participate in the indirect effect. However, in the syntax and mathematically, it does of course (through the mean of s_b). Taking a numerical example: [s_b] = .7 bb (contextual effect) = .1 M on s_b = .2 M on x (a) = .3 Thus, if M = 0, the indirect effect of x on y is .3 * (.7 + .1) = .24 If M = 1, the indirect effect of x on y is .3 * ((.7  .2) + .1) = .18 This implies that in fact we can speak of moderated mediation in a 211 design. Is this correct? On Dec 6th you replied "Regarding Dirk Pelt posting of Dec 2  we will get back on this." Is there any update on this matter? Thanks, Dirk 


I don't know the answer to this question and it would take me too long to try to sort it out at this point. You can try Preacher again but I think he didn't know either. You can try on Multilevelnet. 


I am trying to model two mediators in a series, all level1 (model 6 in Stride et al., 2015) with a level2 moderator of M2Y (labeled V). I have a couple of questions: 1. Would you suggest any modifications to this code? 2. How would I add the betweenperson effect of X and M1 on Y at level 2? 3. How do I obtain confidence intervals for the indirect effects? Thank you! USEVARIABLES = X M1 M2 V Y; Cluster is ID; Between = V; Within = X M1 M2 Y; DEFINE: CATEGORICAL = Y M2; ANALYSIS: TYPE = Twolevel random; ESTIMATOR = ML; MODEL: %WITHIN% Y ON X (c); Y ON M1 (b1); Y ON M2 (b2); M1 ON X (a1); M2 ON X (a2); M2 ON M1 (d1); S  Y on M2; %BETWEEN% Y S on V; S with Y; MODEL CONSTRAINT: NEW(a1b1 a2b2 a1d1b2 TOTALIND TOTAL); a1b1 = a1*b1; Ora1b1 = exp(a1*b1); a2b2 = a2*b2; Ora2b2 = exp(a2*b2); a1d1b2 = a1*d1*b2; Ora1d1b2 = exp(a1*d1*b2); TOTALIND = a1*b1 + a2*b2 + a1*d1*b2; TOTAL = a1*b1 + a2*b2 + a1*d1*b2 + c; OUTPUT: STAND; 


You should not have both fixed and random regression for Y ON M2 (b2); S  Y on M2; 


Thanks, great catch! Can you also provide help on these questions: How would I add the betweenperson effect of X and M1 on Y at level 2? How do I obtain confidence intervals for the indirect effects? 


Don't specify X and M1 as Within variables and then just say on level2: Y on x M1; 


I should clarify, I want to model the withinperson effects, as this is a model of two mediators in a series all at level 1. However, I want to account for the personlevel means at level 2, to partition the variance at the within and between person level. So I would retain the portion of code at the within level, but how is that written at the between level? 


Yes, retain the level1 model as is and add for level2: %BETWEEN% Y S on V; Y on X M1; S with Y; And, perhaps you also want M2 on level2, dealing with it the same way as M1. 

Back to top 