Jesse McCrindle
unread,May 10, 2023, 10:38:05 PM5/10/23Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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")