second-order cfa model working for lavaan but not for blavaan

42 views
Skip to first unread message

Lang Lang

unread,
Aug 15, 2024, 3:41:00 PM8/15/24
to blavaan
Hi,

I am fitting the following second order factor model, where constraints were added on latent variable variances for identification:

model <- '
  F1 =~ NA*X1 + X2 + X3 + X4
  F2 =~ NA*X5 + X6 + X7
  F3 =~ NA*X8 + X9 + X10
  G =~ NA*c1*F1 + c2*F2 + c3*F3
 
  F1 ~~ var_F1*F1
  F2 ~~ var_F2*F2
  F3 ~~ var_F3*F3

  var_F1 == 1 - c1^2
  var_F2 == 1 - c2^2
  var_F3 == 1 - c3^2
 
  G ~~ 1*G
'

It works fine with cfa function from lavaan, but when I use the exact same model with bcfa I got the following error: 

Error in prisplit[[1]] : subscript out of bounds

I spent some time in the source code but still have no clue why this happen or how to fix it.

Thanks in advance for any suggestions or comments.

Ed Merkle

unread,
Aug 15, 2024, 3:46:04 PM8/15/24
to blavaan
I think this happens because of the constraints on var_F1 to var_F3. The default estimation method (target = "stan") cannot handle these constraints. It should work with target = "jags", though. (And the error message could also be improved here.)

One other thing: instead of manually fixing the variance of G to 1, it is better to use std.lv = TRUE. This is because, with std.lv = TRUE, blavaan will do some things to try to ensure model convergence (i.e., one loading per latent variable needs to be sign-constrained during estimation).

Ed

Lang Lang

unread,
Aug 15, 2024, 6:20:52 PM8/15/24
to blavaan
Hi Ed, thanks for your comments. I tried jags but somehow it still doesn't work. I am guessing that this might also be due to cross-matrix constraint? since c1-c3 are loadings while  var_F1 to  var_F3 are from the variance matrix.

The reason I did not use the  std.lv = TRUE is that this will set all of my lv to variance 1 (both first order and second order lvs). The identification constraints I applied here is to have a marginal variance of onefor latent variables, could there be alternative ways to set up the constraints maybe?

Thank you so much!
Lang

Ed Merkle

unread,
Aug 16, 2024, 6:14:27 PM8/16/24
to Lang Lang, blavaan
I believe the problem is that var_F1 to var_F3 can potentially become negative, which are the "invalid" parent values. The constraints below might work with target = "jags":

var_F1 == max(.01, 1 - c1^2)
var_F2 == max(.01, 1 - c2^2)
var_F3 == max(.01, 1 - c3^2)

but then it seems there is a further blavaan problem after that. I will need to look at it some more.

Ed
--
You received this message because you are subscribed to the Google Groups "blavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blavaan+u...@googlegroups.com.

Ed Merkle

unread,
Aug 16, 2024, 10:39:58 PM8/16/24
to Lang Lang, blavaan
Lang,

I just made a small fix to the github version of blavaan so that target="jags" works, see installation instructions at the bottom of this page:


I think you want the syntax below (separating the "NA" and parameter label on the "G =~" line, with std.lv = FALSE). You might also consider mildly informative priors on the loadings and latent variances to help ensure that the total variance does not go above 1 (though, if your data are standardized, maybe it is not an issue).

Ed


model <- '
F1 =~ NA*X1 + X2 + X3 + X4
F2 =~ NA*X5 + X6 + X7
F3 =~ NA*X8 + X9 + X10
G =~ NA*F1 + c1*F1 + c2*F2 + c3*F3
F1 ~~ NA*var_F1*F1
F2 ~~ NA*var_F2*F2
F3 ~~ NA*var_F3*F3

var_F1 == max(.01, 1 - c1^2)
var_F2 == max(.01, 1 - c2^2)
var_F3 == max(.01, 1 - c3^2)
G ~~ 1*G
'




On Thu, 2024-08-15 at 15:20 -0700, Lang Lang wrote:
--

Lang Lang

unread,
Aug 19, 2024, 3:02:41 PM8/19/24
to blavaan
Thank you so much Ed, it works perfectly now!
Reply all
Reply to author
Forward
0 new messages