Lavaan: Adding covariates to multilevel mediation model

756 views
Skip to first unread message

Alex Smalley

unread,
Dec 15, 2021, 10:37:00 AM12/15/21
to lavaan

Hello everyone,

I have a multilevel mediation model I’m building in Lavaan that I need some help with, if possible.

It’s a parallel mediation model with two mediators and single DV, each continuous. Condition is categorical and binary, 0 = control and 1 = treatment. It looks like this:


Mediation model.jpg

This was a repeated measures design and clustering is according to individual participants, identified by the variable ‘ID’.

Without a model initially in mind for level:2, it’s been saturated as recommended here https://lavaan.ugent.be/tutorial/multilevel.html

My model, which appears to be running correctly, is then:

model <- '

level:1
# direct effects
DV ~ b*M1 + c*M2 + d*CON

# mediator models
M1 ~ a1*CON
M2 ~ a2*CON

# indirect effects
indirect1 := a1*b
indirect2 := a2*c

# total effects
total := d + (a1*b) + (a2*c)

# covariances
M1 ~~ M2

level:2
DV ~~ DV + M1 + M2
M1 ~~ M1 + M2
M2 ~~ M2
'

fit.model <- sem(model = model,
                  data = data,
                  missing = "ml",
                  cluster = "ID")



But now I’d like to include demographic covariates, such as age (C1), gender (C2), and income (C3). But these are between participant characteristics and I’m coming unstuck trying to add them into the model. I think they have to go in level:2 but I can’t find an example where this has been done and I’m unclear on the syntax required.

Any help would be very gratefully appreciated.

Many thanks!

Alex

Terrence Jorgensen

unread,
Dec 20, 2021, 4:13:40 AM12/20/21
to lavaan
But now I’d like to include demographic covariates, such as age (C1), gender (C2), and income (C3).

That contradicts what you said above about not having a subject-level model in mind.  Clearly you do, if you want to control for these effects.  I would fit the same model at both levels.  This will allow you to see how the parameters differ across levels (although the usual "contextual effect" would have an odd interpretation in the context of repeated-measures of the same subjects).   The these covariates simply enter the Level-2 model, at which point the slopes are no longer comparable across levels.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
http://www.uva.nl/profile/t.d.jorgensen

Alex Smalley

unread,
Dec 20, 2021, 8:58:37 AM12/20/21
to lavaan
Many thanks for such a quick response Terrence, I'll add the covariates into level 2 as suggested.

Very best,

Alex

Reply all
Reply to author
Forward
0 new messages