Multilevel path analysis error and model specification question

58 views
Skip to first unread message

Thalia Vrantsidis

unread,
Oct 12, 2018, 12:10:31 PM10/12/18
to lavaan
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") 

Thalia Vrantsidis

unread,
Oct 12, 2018, 6:57:30 PM10/12/18
to lavaan
Figured out my own issue - turns out I just hadn't updated lavaan!

Thalia Vrantsidis

unread,
Oct 12, 2018, 10:24:32 PM10/12/18
to lavaan
Updating solved the error, but I still have another version of my original conceptual question of how to specify my model properly.

I am only interesting in the level 1 effects, but I do not have enough degrees of freedom to fit the model specified in my original post.
The lavaan multilevel SEM help page says you cannot have a blank level 2 model, and suggests the following
"if you do not have a model in mind for level 2, you can specify a saturated level by adding all variances and covariances of the endogenous variables (here: y1, y2 and y3):" 
However, I do not have enough degrees of freedom for this either.

Are there any other principled ways to decide what to put in a level 2 model that you are not really interested in?
(I am rather new to path modelling/sem, so I may just not know about something obvious.)

Terrence Jorgensen

unread,
Oct 18, 2018, 7:12:45 AM10/18/18
to lavaan
you can specify a saturated level by adding all variances and covariances of the endogenous variables (here: y1, y2 and y3):" 
However, I do not have enough degrees of freedom for this either.

What do you mean?  A saturated model as df=0, but you can still estimate/fit the model to data.  Saturating level 2 simply means your df will all come from constraints at level 1.  As far as I can tell, the only constraint is that similarity ~~ 0*group_cert because you don't estimate that residual covariance.  Even if you estimate it, you would still have df=0, so you can fit your model and test individual estimates for significance.  You simply couldn't test fit.

Terrence D. Jorgensen
Postdoctoral Researcher, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Reply all
Reply to author
Forward
0 new messages