Hi everyone,
I am trying to do a multilevel path model and I keep getting the error shown below. Any help on what is causing it would be appreciated. Here is a simplified reproducible example that creates it.
I also have my full model below in case that is helpful - perhaps I specified something wrong that is causing the error? If someone can check my logic for how I defined the model at the second level to see if that is reasonable, that would be appreciated too.
Background: I am only interested in the level 1 effects within each person, but because I have multiple responses per person (about 24) and about 100 people, I wanted to make sure I controlled for the clustering created by different people.
I therefore included the same model at level 2. Is this ok? I have seen others say to use a fully saturated level 2 model if you are not interested in it.
In my case I think it is reasonable to assume the same model might apply at level 2, but I do not really care about it for my questions, so I can simply not focus on these results?
Error message:
Error in lavsamplestats@cov[[g]] : subscript out of bounds
Reproducible example:
df_test = data.frame(similarity = rnorm(200), knowledge = rnorm(200), subjectid = rep(c(1:10), each=20))
test_model <- '
level: 1
similarity ~ knowledge
level: 2
similarity ~ knowledge
'
analysis <- sem( test_model, data=df_test, cluster = "subjectid")
Full model I want to run (gives same error):
mediation_mlm <- '
level: 1
similarity ~ a*knowledge_direct + b*knowledge_indirect
group_cert ~ c*knowledge
person_cert ~ d*similarity + e*group_cert + f*knowledge_direct + g*knowledge_indirect + h*knowledge
knowledge_direct ~~ knowledge_indirect
knowledge_direct ~~ knowledge
knowledge_indirect ~~ knowledge
#indirect effect (a*b)
indirect.kndir_sim := a*d
indirect.knindir_sim := b*d
indirect.kn_grcert := c*e
#total effect
total_knowdir := (a*d) +f
total_knowindir := (b*d) +g
total_know := (c*e) +h
level: 2
similarity ~ knowledge_direct + knowledge_indirect
group_cert ~ knowledge
person_cert ~ similarity + group_cert + knowledge_direct + knowledge_indirect + knowledge
knowledge_direct ~~ knowledge_indirect
knowledge_direct ~~ knowledge
knowledge_indirect ~~ knowledge
'
analysis <- sem( mediation_mlm, data=df3, cluster = "subjectid")