Can lavaan conduct a CFA or SEM with two crossed random effects?

95 views
Skip to first unread message

David Sidhu

unread,
Jun 23, 2020, 4:28:17 PM6/23/20
to lavaan
Lets imagine I have the following data: 20 participants each rated 10 items on five different dimensions.

set.seed(123)
library
(data.table)
library
(psych)

ppt
<- rep(1:20, each = 10)
item
<- rep(1:10, times = 20)

dim_a
<- rnorm(200)
dim_b
<- rnorm(200)
dim_c
<- rnorm(200)
dim_d
<- rnorm(200)
dim_e
<- rnorm(200)

d
<- as.data.table(cbind(ppt, item, dim_a, dim_b, dim_c, dim_d, dim_e))

Lets say I'd like to conduct a CFA with dims a-c on one factor, and dims d-e on another. I believe I can do so with something like this.

twofactor <- ' f1 =~ dim_a + dim_b + dim_c
f2 =~ dim_d + dim_e '



fit
<- cfa(twofactor, data = d)

However, I would like to account for the fact that ratings are nested in both participants and items. Is there a way to account for this? If I were running a regression the terminology would be that I would like to add a random intercept for participants and items.

It seems like I can do one by adding a cluster argument...

fit <- cfa(twofactor, data = d, cluster = "ppt")

But is it possible to do both participants and items? Note that participants and items are not nested but crossed.

Terrence Jorgensen

unread,
Jun 25, 2020, 4:16:57 AM6/25/20
to lavaan
Lets imagine I have the following data: 20 participants each rated 10 items on five different dimensions.

What makes the first item on Dimension 1 the "same" item as the first on Dimensions 2-5?  
 

I would like to account for the fact that ratings are nested in both participants and items. Is there a way to account for this?

CFA / SEM handles nesting of responses within items the same way it handles nesting of repeated measures within subjects in a latent growth model: by putting the different responses into wide format (dim_a_item1, dim_a_item2, etc.).  You would of course need a lot more subjects for a model with 5*10 = 50 variables, but that is just how CFA works.  The "nesting" issue then disappears because all responses for a subject are within a single row, and dependence among them is accounted for in the model's covariance structure.  

In this case, you would want to read about bifactor or multitrait-multimethod (MTMM) models.  You would have a factor for each dimension ("trait factors"), and if the 10 items are indeed matched across dimensions (e.g., they use similar wordings or themes), then you would also have "method factors" (one factor onto which each "item1" loads, another onto which each "item2" loads, etc.).  Once the trait and method factors are all specified, then you can specify any higher-order factor structure you like among the 5 dimensions.  However, MTMM models are notorious for not converging, so good luck.

 
If I were running a regression the terminology would be that I would like to add a random intercept for participants and items.

It seems like I can do one by adding a cluster argument...

fit <- cfa(twofactor, data = d, cluster = "ppt")

But is it possible to do both participants and items?

No, lavaan can only handle a single cluster variable.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam
 
Reply all
Reply to author
Forward
0 new messages