Closed cwliu007 closed 1 year ago
Hi
Thanks for this!
I think this is an issue with the lavaan model fit: if you do summary(fit, std=TRUE)
of your laffan fit
object, the estimated variance of g ist negative and then the standardized parameters are NA
. So you may want to change something in the simulated data as this data structure seems to lead to problems when fitting the model.
But we should add some check of this, such that this is captured in the SL()
function and a more helpful warning or error is returned (actually this error stems from the SL()
print method, which is not where this is supposed to pop up.
Hope this helps!
Hello,
I run a second-order CFA model and the SL() function got an error message like this:
Error in if (abs(i[kk]) < cutoff) { : missing value where TRUE/FALSE needed
The simulated data and code are as follows:
` set.seed(1234)
library("mvtnorm")
people = 10000 # sample size
D = 5 mu = rep(0,D) Sigma = diag(D)
xi = rmvnorm(n = people, mu, Sigma) # latent variables
itemnum = 6*D error = rmvnorm(n = people, rep(0,itemnum), diag(itemnum))
lambda = matrix(0,itemnum,D) lambda[1:6,1] = c(1, 0.82, 1.20, 0.95, 0.88, 1.15) lambda[7:12,2] = c(1, 1.05, 1.25, 1.05, 0.95, 0.70) lambda[13:18,3] = c(1, 1.06,0.88,0.9,1.31,0.85) lambda[19:24,4] = rep(1,6) lambda[25:30,5] = rep(1,6)
y = xi %*% t(lambda) + error
library("lavaan") library("EFAtools")
mod <- 'F1 =~ V1 + V2 + V3 + V4 + V5 + V6 F2 =~ V7 + V8 + V9 + V10 + V11 + V12 F3 =~ V13 + V14 + V15 + V16 + V17 + V18 F4 =~ V19 + V20 + V21 + V22 + V23 + V24 F5 =~ V25 + V26 + V27 + V28 + V29 + V30 g =~ F1 + F2 + F3 + F4 + F5' fit <- lavaan::cfa(mod, data = y, estimator = "ml")
SL_lav <- SL(fit, g_name = "g") `