Hi,
I was trying to use sem as below:
mediation_model3 <- '
#direct effects
MVPA ~ a1 * BIP_PRS + Sex + Age + PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 + PC9 + PC10
#LST ~ a2 * BIP_PRS + Sex + Age + PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 + PC9 + PC10
Healthy_Food ~ a3 * BIP_PRS + Sex + Age + PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 + PC9 + PC10
Meat ~ a4 * BIP_PRS + Sex + Age + PC1 + PC2 + PC3 + PC4 + PC5 + PC6 + PC7 + PC8 + PC9 + PC10
BMI ~ c * BIP_PRS + b1 * MVPA + b3 * Healthy_Food + b4 * Meat
#indirect effect (a * b)
indirect1 := a1 * b1
#indirect2 := a2 * b2
indirect3 := a3 * b3
indirect4 := a4 * b4
#total effect (c + indirect)
total := c + indirect1 + indirect3 + indirect4
#MVPA ~~ LST
MVPA ~~ Healthy_Food
MVPA ~~ Meat
#LST ~~ Healthy_Food
#LST ~~ Meat
Healthy_Food ~~ Meat
'
setwd('Desktop/zillur/work/body-brain/physical_activity/sem/')
df1=fread('processed_data1.csv',data.table = F)
df2 = df1[,-1]
mediation_results4 <- sem(mediation_model3, data = df2, cluster = "Meat",
verbose = TRUE, optim.method = "em", em.iter.max = 9000000,
em.fx.tol = 1e-08, em.dx.tol = 1e-04)
summary(mediation_results4, standardized = TRUE, fit.measures = TRUE)
Gives me the above mentioned error:
> mediation_results4 <- sem(mediation_model3, data = df2, cluster = c("MVPA","Healthy_Food","Meat"),
+ verbose = TRUE, optim.method = "em", em.iter.max = 900000,
+ em.fx.tol = 1e-08, em.dx.tol = 1e-04)
lavoptions ... done.
lavdata ... done.
Number of observations 270288
Number of clusters [MVPA] 2
Number of clusters [Healthy_Food] 270288
Number of clusters [Meat] 2
lavpartable ... done.
lavsamplestats ... done.
lavh1 ... start:
lavh1 ... done.
lavpartable bounds ... done.
lavstart ... done.
lavmodel ... done.
lavoptim ... start:
Error in lav_lavaan_step11_estoptim(lavdata = lavdata, lavmodel = lavmodel, :
lavdata@nlevels > 1L is not TRUE