Hello everyone,
I believe I can use a little of your expertise with lavaan.
I am running this model in which I am evaluating the mediating effects (SE, OE, SMB and KSA) between intervention and outcomes (latent variables of physical and psychological).
I was pretty happy with my model in code 1. However I decided to change a little to make easier to see direct, indirect and total effect (Code 2) according to a code that i found in a book. The problem is that I am having now 2 different results with code 1 and code 2 (different fit and loading) and I believe they were suppose to be the same.
Code 1:
Intervention_all_mediators<- '
Psychological =~
SF.MentalHealth_T.3_rescale +
SF.RoleEmotional_T.3_rescale +
SF.SocFunct_T.3_rescale +
STAI_3months_TS_Rescale +
PHQ_3months_TS
physical =~
SF.PhysFunct_T.3_rescale +
SF.RolePhys_T.3_rescale +
SF.BodilyPain_T.3_rescale +
PCA_3months_Rescale
#SE portion
SE =~ SE_3Months
SE_3Months~~0*SE_3Months
SE ~ Psychological
SE ~ physical
#OE portion
OE =~ OE_3Months
OE_3Months~~0*OE_3Months
OE ~ Psychological
OE ~ physical
#SMB portion
SMB =~ SMB_dic_3Months_rescale
SMB_dic_3Months_rescale~~0*SMB_dic_3Months_rescale
SMB ~ Psychological
SMB ~ physical
#KSA portion
KSA =~ KSA_3Months_rescale
KSA_3Months_rescale~~0*KSA_3Months_rescale
KSA ~ Psychological
KSA ~ physical
# Intervention
Intervention =~ intervention_num
intervention_num ~~ 0*intervention_num
SE ~ Intervention
OE ~ Intervention
KSA ~ Intervention
SMB ~ Intervention
Psychological ~ Intervention
physical ~ Intervention
#Correlated error
SF.RolePhys_T.3_rescale ~~ PCA_3months_Rescale
SF.MentalHealth_T.3_rescale ~~ PHQ_3months_TS
SF.MentalHealth_T.3_rescale ~~ STAI_3months_TS_Rescale
SF.MentalHealth_T.3_rescale ~~ SF.SocFunct_T.3_rescale
SF.RoleEmotional_T.3_rescale ~~ SF.SocFunct_T.3_rescale
OE ~~ SE
KSA ~~ SE
Psychological ~~ physical
'
Intervention_out <- sem(Intervention_all_mediators, data = dataaim1
,ordered=c("Intervention"))
summary(Intervention_out, standardized=TRUE, fit.measures=TRUE, rsq=TRUE, modindices = TRUE)
resid(Intervention_out, type = "cor")
semPaths(Intervention_out, whatLabels = "est")
varTable(Intervention_out)
Code 2:
######direct, mediator, Indirect and total effect
model_DIT3M<- '
Psychological =~
SF.MentalHealth_T.3_rescale +
SF.RoleEmotional_T.3_rescale +
SF.SocFunct_T.3_rescale +
STAI_3months_TS_Rescale +
PHQ_3months_TS
physical =~
SF.PhysFunct_T.3_rescale +
SF.RolePhys_T.3_rescale +
SF.BodilyPain_T.3_rescale +
PCA_3months_Rescale
#SE portion
SE =~ SE_3Months
SE_3Months~~0*SE_3Months
#OE portion
OE =~ OE_3Months
OE_3Months~~0*OE_3Months
#SMB portion
SMB =~ SMB_dic_3Months_rescale
SMB_dic_3Months_rescale~~0*SMB_dic_3Months_rescale
#KSA portion
KSA =~ KSA_3Months_rescale
KSA_3Months_rescale~~0*KSA_3Months_rescale
# Intervention
Intervention =~ intervention_num
intervention_num ~~ 0*intervention_num
#Correlated error
SF.RolePhys_T.3_rescale ~~ PCA_3months_Rescale
SF.MentalHealth_T.3_rescale ~~ PHQ_3months_TS
SF.MentalHealth_T.3_rescale ~~ STAI_3months_TS_Rescale
SF.MentalHealth_T.3_rescale ~~ SF.SocFunct_T.3_rescale
SF.RoleEmotional_T.3_rescale ~~ SF.SocFunct_T.3_rescale
OE ~~ SE
KSA ~~ SE
Psychological ~~ physical
######direct, mediator, Indirect and total effect
#Direct effect
Psychological ~ e*Intervention
physical ~ d*Intervention
#Mediator
SE ~ a*Intervention
OE ~ f*Intervention
SMB ~ i*Intervention
KSA ~ l*Intervention
physical ~ b*SE
Psychological ~ c*SE
physical ~ g*OE
Psychological ~ h*OE
physical ~ j*SMB
Psychological ~ k*SMB
physical ~ m*KSA
Psychological ~ n*KSA
#Indirect effect
indirect_SE_Physical:= a*b
indirect_SE_Psychological:= a*c
indirect_OE_Physical:= f*g
indirect_OE_Psychological:= f*h
indirect_SMB_Physical:= i*j
indirect_SMB_Psychological:= i*k
indirect_KSA_Physical:= l*m
indirect_KSA_Psychological:= l*n
#Total effect
Total_SE_Physical:= d+(a*b)
Total_SE_Psychological:= e+(a*c)
Total_OE_Physical:= d+(f*g)
Total_OE_Psychological:= e+(f*h)
Total_SMB_Physical:= d+(i*j)
Total_SMB_Psychological:= e+(i*k)
Total_KSA_Physical:= d+(l*m)
Total_KSA_Psychological:= e+(l*n)
#Direct print
Direct_Psychological:= e
Direct_Physical:= d
#Mediator print
Mediator_Psychological:= c
Mediator_Physical:= b
Mediator_SE := a
Mediator_OE := f
Mediator_SMB := i
Mediator_KSA := l
'
fit_DIT3M <- sem(model_DIT3M, data = dataaim1)
summary(fit_DIT3M, standardized=TRUE, fit.measures=TRUE, rsq=TRUE, modindices = TRUE)
semPaths(fit_DIT3M, whatLabels = "est")