Help with Lavaan syntax to fit a multilevel mediation model

1,128 views
Skip to first unread message

Marie jeanne Buscot

unread,
Mar 20, 2019, 10:10:16 PM3/20/19
to lavaan
Hi Everyone, 

I was hoping that someone here could help me with specifying the lavaan syntax for a multiple mediation model on clustered data. I have used multilevel in R before but this is my first attempt at running a full mediation analysis in the SEM framework. It is a steep leaning curve ! The goal of my study is to determine whether a treatment ( "group" in my data) predicts intent to quit smoking ("intent_scale"). We aim to measure the effect indirect and total effect considering two mediators : self efficacy (se_centred_scale) and vulnerabiliy (vuln_scale). The difficulty arises because there is repeated observations of these variables daily (day_r) within subjects, so I would need to be able to consider a random effect of subject (1|subject in lmer() syntax) and/or a random intercept + slope model (1+day_r|subject).
 I have read  all I could find about multilevel SEMs, and how to specify them in lavaan using either the wide data format, either the '"cluster" option, but I am struggling to see how to use this information to specify my own model. I don't think I understand how to structure my model at level 1 and level 2 with the lavaan syntax. At the moment, i have managed to write the syntax for model I am trying to fit. It is running fine but totally ignores the clustered natures of the data.

 Ideally I would like to find a way to specify the same model considering a subject-level random effect ( or a random intercept-slope model). I would greatly appreciate your input! Below is the first few rows of my data, my current multiple mediation model, and the corresponding path.

Thanks again for your help!

Marie-Jeanne 
Post-doctoral fellow
Menzies Institute for Medical Research Univeristy of Tasmania, Australia

multipleMediationNOcovariate <- '
 intent_scale ~ b1 * vuln_scale_centred + b2 * se_scale_centred + c * group
vuln_scale_centred ~ a1 * group
se_scale_centred ~ a2 * group 
indirect1 := a1 * b1
indirect2 := a2 * b2
total    := c + (a1 * b1) + (a2 * b2)
vuln_scale_centred ~~se_scale_centred # residual covariance between the 2 mediators
'

Screen Shot 2019-03-21 at 12.23.17 pm.png
Screen Shot 2019-03-21 at 12.36.26 pm.png



Marie jeanne Buscot

unread,
Mar 20, 2019, 11:48:34 PM3/20/19
to lavaan
Hi again everyone, I just had a go at specifying the two-levels. See syntax below this post . Am I on the right track? 
- At the deepest level ( level 1 (repeated measure level ), I only considered an intercept and a linear slope (day_r).
- I put all the predictors of between-subject variability in intent (outcome) at level 2.

model1 <- '
level: 1
intent_scale ~  1+ sl * day_r # within-person model with no predictor ( day-r is numeric, so "sl" is a linear slope parameter)

level: 2
intent_scale ~ b1 * vuln_scale_centred + b2 * se_scale_centred + c * group # between-person model with predictors of between-subject difference in outcome
vuln_scale_centred ~ a1 * group
se_scale_centred ~ a2 * group 
vuln_scale_centred ~~ vuln_scale_centred
se_scale_centred~~se_scale_centred
indirect1 := a1 * b1
indirect2 := a2 * b2
total    := c + (a1 * b1) + (a2 * b2)
vuln_scale_centred ~~se_scale_centred # residual covariance between the 2 mediators

'

Is this the correct way to proceed, or should I have predictors in the level1 part of the model as well?
Also LAVAAN returns and estimate =0 for the intercept of the level 1 model. How do I get the model to estimate  the random effect variance and covariance components between intercept and slope at level 1?

Thanks again for your help!

Terrence Jorgensen

unread,
Mar 21, 2019, 7:03:46 AM3/21/19
to lavaan
should I have predictors in the level1 part of the model as well?

lavaan will not make any assumptions for you.  You need to specify the model you want at each level.

Also LAVAAN returns and estimate =0 for the intercept of the level 1 model.

Intercepts are zero by definition at level 1; they are the residuals at level 2.


How do I get the model to estimate  the random effect variance and covariance components between intercept and slope at level 1?

The intercept variance is the variance being explained in the Level 2 model.  

lavaan cannot yet model random slopes.  Mplus can.

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

Reply all
Reply to author
Forward
0 new messages