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

248 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!
Reply all
Reply to author
Forward
0 new messages