Multilevel Moderated Mediation (1-1-1 with level 1 moderator)

1,272 views
Skip to first unread message

Jacob Elder

unread,
Oct 29, 2019, 3:44:38 PM10/29/19
to lavaan
Hello,

I am trying to run a multilevel moderated mediation in lavaan with all level 1 variables. I have a response variable (Resp), a mediator (Med), a predictor (Pred), and a moderator (Mod), all nested within subjects.

I have found relevant resources on lavaan that have provided syntax for mediation, moderated mediation, and multilevel SEM, but not all of these things combined for moderated multilevel mediation. Some of such links are below:

I understand that the lavaan syntax for specifying multilevel SEM is '
level: 1
...
level
: 2
...
'
summary(... cluster = "cluster")


While all of this makes sense, it seems to require that you have some variables included in level 2. However, my multilevel moderated mediation is all level 1 variables. So when I try to run:
lavMed <- '
level: 1
  # direct effect
  Resp ~ c*Pred
  # mediator
  Med ~ a*Pred
  Resp ~ b*Med
  # indirect effect (a*b)
  ab := a*b
  # total effect
  total := c + (a*b)
level: 2
'

I unfortunately get an error that I need syntax at level 2.

I am not sure if this is correct but then I try just an intercept at level 2 since I am not using any level 2 variables in the model... Just nesting level 1 variables in subjects to account for non-independence/clustering.

lavMed <- '
level: 1
  # direct effect
  Resp ~ c*Pred
  # mediator
  Med ~ a*Pred
  Resp ~ b*Med
  # indirect effect (a*b)
  ab := a*b
  # total effect
  total := c + (a*b)
level: 2
 
subID ~ 1
'

fit
<- sem(lavMed,
           data
= medDf,
           
group = "Mod", cluster = "subID")
summary
(fit)



When I run this, I get:
Error in ov.names.l[[g]] : subscript out of bounds

I am pretty stumped now. Why am I getting this error? How can I run a multilevel moderated mediation in lavaan, that does not use any level 2 variables? Is the syntax on the right track? Any help would be greatly appreciated.

Jacob Elder

unread,
Oct 29, 2019, 3:52:48 PM10/29/19
to lavaan
It is a categorical, two-level moderator, by the way. Ideally, I'd like to do two-group SEM/mediation, and test differences in mediation effect between models

Terrence Jorgensen

unread,
Nov 2, 2019, 11:51:52 AM11/2/19
to lavaan
it seems to require that you have some variables included in level 2. However, my multilevel moderated mediation is all level 1 variables.

Right, and all Level-1 variables have Level-2 components (the cluster means), so you need to model them.  If you have no hypotheses at Level 2, you can just omit the Level-2 model to obtain cluster-robust SEs and test statistics.

If you do want to run a multilevel model, then your grouping variable needs to be a Level-2 variable, and you need to define a unique block of code for each level within each group:


Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Andreas G.

unread,
Jan 24, 2020, 2:50:49 AM1/24/20
to lavaan
Hello,

regarding the question if level 2 needs to be populated:
Rosseel writes: "

Important notes

  • note that in level: 1 the colon follows the level keyword; if you type level 1:, you will get an error

  • you must specify a model for each level; the following syntax is not allowed and will produce an error:

        model <- '
            level: 1
                fw =~ y1 + y2 + y3
                fw ~ x1 + x2 + x3
            level: 2
        '
    
  • if you do not have a model in mind for level 2, you can specify a saturated level by adding all variances and covariances of the endogenous variables (here: y1, y2 and y3):

        model <- '
            level: 1
                fw =~ y1 + y2 + y3
                fw ~ x1 + x2 + x3
            level: 2
                y1 ~~ y1 + y2 + y3
                y2 ~~ y2 + y3
                y3 ~~ y3
"  (http://lavaan.ugent.be/tutorial/multilevel.html)

@Professor Jorgensen:
could you please further elaborate in regard to this statement?

Thank you,

Andreas

Terrence Jorgensen

unread,
Jan 25, 2020, 3:56:22 AM1/25/20
to lavaan
could you please further elaborate in regard to this statement?

It means that if you do not specify a Level-2 model, you will only get cluster-robust SEs for your single-level model.  Perhaps that is all you want, but specifying a saturated model (i.e., freely estimate all Level-2 (co)variances).  If you hypothesize the same causal structure at both levels, you should specify the same model at both levels; then you could possibly test whether the paths are equivalent at both levels (which is unlikely) or calculate contextual effects.  Preacher and colleagues have written quite good articles explaining these issues in the context of multilevel mediation, most of which generalize to any SEM:


Laura Stapleton and colleagues have also provided some great articles in the past few years focusing on multilevel CFAs, e.g., https://doi.org/10.3102%2F1076998616646200

Andreas G.

unread,
Jan 26, 2020, 5:47:34 AM1/26/20
to lavaan
Now I understand, thank you very much for explaining it further!

Юлия Музыченко

unread,
May 8, 2024, 1:18:30 PMMay 8
to lavaan
Dear  Terrence D. Jorgensen,

I have encountered a similar problem and I am not sure how to solve it.
I want to see if there is difference in how personality affects adjustment in a country and satisfaction with the educational program.
I believe that the last variable will be affected by the school a student is in at. That is why I want to use it as a cluster variable.

when I specify my model, I tried to apply advice from here and it didn't work.

Here is the model:


model_CLF_1 <- '
# measurement model
ES =~ es1 + es2 + es3 + es4 + es5 + es6 + es7 + es8 + 1*es9 + es10
                SOC =~ soc4 + soc5 + soc6 + soc8 + soc9
                        + soc11 + soc12 + soc13
                CCM =~ ccm1 + ccm2 + ccm3 + ccm4 + ccm5
                CCA =~ cca1 + cca2 + cca3
                AS =~ as1 + as2 + as3
method=~es1 + es2 + es3 + es4 + es5 + es6 + es7 + es8 + es9 + es10 +
soc4 + soc5 + soc6 + soc8 + soc9 + soc11 + soc12 + soc13 +
ccm1 + ccm2 + ccm3 + ccm4 + ccm5 + cca1 + cca2 + cca3 + as1 + as2 + as3
method~~0*ES
method~~0*SOC
method~~0*CCM
method~~0*CCA
method~~0*AS


level: 1
# regression
ES~ c11*gender
SOC~a*ES+c12*gender
CCA ~ b*ES   + c*SOC
+ c13*gender + c23*language + c33*ses + c43*exchProg + c53*cctraindue
AS ~ d* ES  + e*SOC + f*CCA
+ c14*gender + c24*language + c34*ses + c44*exchProg + c54*cctraindue

#idirect
indirect1 := b*f
indirect2 := c*f

#total
total1 := d +(b*f)
total2 := e +(c*f)

level: 2
School~~School
'

sem <- sem.mi(model_CLF_1, data = imp_list, meanstructure=TRUE, cluster= "School", estimator = "mlr")
summary(sem, standardized = TRUE, fit.measures = TRUE,ci=TRUE)

It works when without levels.
What I tried to specify in the level 2 so far and it didn't work:
1)School~~School
2)AS=~as1+as2+as3
3)as1~as2+as3
as2~as3
(this one I tried on all elements all at once as was recommended in one of this group's branches, it didn't work)

I hope you can advice me how to solve it!

суббота, 2 ноября 2019 г. в 18:51:52 UTC+3, Terrence Jorgensen:

Юлия Музыченко

unread,
May 8, 2024, 1:34:26 PMMay 8
to lavaan
P.S. method is common latent factor, I try to account for CMB with it and actually it also breaks the model. I am also considering to extract  factor scores without CLF but I am not sure how to make it all work without bias.

среда, 8 мая 2024 г. в 20:18:30 UTC+3, Юлия Музыченко:

Юлия Музыченко

unread,
May 8, 2024, 4:07:40 PMMay 8
to lavaan
P.P.S. when I checked one level model and included School as a covariate in a regression equation, it didn't have whatsoever effect on  satisfaction with the educational program, I guess I can keep it as a covariate then and don't stress to much about two-level sem, or shall I still be worried about it?

Best Regards,
Yulia

среда, 8 мая 2024 г. в 20:34:26 UTC+3, Юлия Музыченко:

Юлия Музыченко

unread,
May 8, 2024, 4:10:10 PMMay 8
to lavaan
Then CLF question is still very vital, how can I keep it and not break my model? in CFA it works very well, but not in SEM :( Shall I extract my factors so that they account for the covariance with CLF and model a path diagram(I know you think it's not the ideal solution from the comments in other threads, but what would be then)? 

среда, 8 мая 2024 г. в 23:07:40 UTC+3, Юлия Музыченко:
Reply all
Reply to author
Forward
0 new messages