Hi all,
I am trying to fit (what I think) is a moderated mediation model with 2 moderators to correspond with the attached diagram. However, I'm relatively new to both R and lavaan and could really do with some help trying to build my model.
I have attached the code I have generated below. I guess my main question is whether I have specified the model correctly. Any help or guidance would be very much appreciated!
I also had a question regarding using a latent variable as a moderator. I found some questions regarding indProd function (in this group) but I am a little confused of how to generate such a code. I was hoping to use the variable ELAS (which consists of 4 items with 4 levels) as a moderator variable. At the moment I've just used a total score as I having a lot of difficulty trying to find a way to use this as a latent variable.
#moderated mediation
moderated_mediation <-'
#latent variable
IQ=~ in1 + in2 + in3
#regressions
TBV~ a1*gene
IQ~ b1*TBV
TBV~ a2*ELAS
TBV~a3*gene_ELAS
IQ~ b2*eduageS
IQ~ b3*TBV_eduageS
IQ~ cdash*gene
#covariates
TBV~ totalB + Sex + Age
#mean of centered moderators (for use in simple slopes)
ELAS ~ ELA.mean*1
eduageS ~eduage.mean*1
#variance of moderators
ELAS ~~ ELA.var*ELASS
eduageS ~~ eduage.var*eduageS
#index of moderated mediation
imm1 := a1*b3
imm2 := b1*a3
#indirect effects conditional on moderators
indirect1.SDbelow := a1*b1* + a3*-sqrt(ELA.var)*b1
indirect1.mean := a1*b1 + a3*ELA.mean*b1
indirect1.SDabove := a1*b1 + a3*sqrt(ELA.var)*b1
indirect2.SDbelow := a1*b1 + a1*-sqrt(eduage.var)*b3
indirect2.mean := a1*b1 + a1*eduage.mean*b3
indirect2.SDabove := a1*b1 + a1*sqrt(eduage.var)*b3
'
#fit model
sem <- sem(model= moderated_mediation, data= df, fixed.x = FALSE, missing ='fiml')
#fit measures
summary(sem, fit.measures= TRUE, standardize= TRUE, rsquare= TRUE)
Many thanks again,
Emma