Moderated Mediation with a continuous moderator in twin data

87 views
Skip to first unread message

Jesse McCrindle

unread,
May 10, 2023, 10:38:05 PM5/10/23
to lavaan
Hi everyone, 

I am running a moderated mediation analysis using lavaan and would like to keep the moderator as a continuous variable. I've not found a way to do so without losing the ability to account for the clustered data due to twins in my sample. My current script accounts for the twins but has dichotomized the moderator, Social Support (SS).

Would anyone know how I can adapt my script below to account for cluster = Family_ID AND make my moderator (SS) continuous? 


I have several two continuous covariates and one dichotomous covariate. My x, y, and med are all continuous variables which have been centred. 

mod4b <- '# a path

         Med.c ~ 1 + a1 * X.c + Age + Zygosity_Jan2019 + DASSTotal
         Med.c ~ a2 * SSdichot
         
         Med.c ~ a3 * SSdichotX

         # b paths

         Y ~ b1 * Med.c

 
         # c prime path

         Y ~ 1 + cp * X.c + Age + Zygosity_Jan2019 + DASSTotal
         Y ~ c2 * SSdichot
        Y ~ c3 * SSdichotX


         # index of moderated mediation and conditional indirect effects on path a

         b1a3 := b1 * a3
         aSS1ss := a1 + a3 * 1 # 1 = low SS; 2 = high SS
         aSS2ss := a1 + a3 * 2
         aSS1 := a1 * b1 + b1a3 * 1
         aSS2 := a1 * b1 + b1a3 * 2
         atotal := cp + b1a3


         # index of moderated mediation and conditional indirect effects on path c
       
         c1c3 := cp * c3
         cSS1ss := cp + c3 * 1 # 1 = low SS; 2 = high SS
         cSS2ss := cp + c3 * 2
         cSS1 := cp + c1c3 * 1
         cSS2 := cp + c1c3 * 2

         # indirect and total effects

         a1b1 := a1 * b1
         total := cp + a1b1'

# With bootstrapping

set.seed(1234)

sem.fit4b <- sem(mod4b, data = datamale, se = "robust.cluster",
                 
                 bootstrap = 10000, likelihood = "wishart", cluster = "Family_ID")

Terrence Jorgensen

unread,
May 12, 2023, 7:30:31 AM5/12/23
to lavaan
The script would work the same way for continuous SS, but you would simply choose meaningful levels of SS on its continuous scale (rather than 1 and 2 when it is binary).

Some other notes:
  • Not sure why you are using Wishart likelihood when you have a mean structure
  • Bootstrapping is not straight forward for clustered data.  I would recommend using semTools::monteCarloCI()

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


Reply all
Reply to author
Forward
0 new messages