Error message in multiple-group ordinal CFA: Error in if (any(dCOV < 0)) { : missing value where TRUE/FALSE needed

95 views
Skip to first unread message

Yu Liu

unread,
Sep 21, 2019, 6:59:27 PM9/21/19
to lavaan
Hello,

I am using lavaan to fit a multiple-group ordinal CFA, and got the following error message: Error in if (any(dCOV < 0)) { : missing value where TRUE/FALSE needed.

However, when I use lavaan to fit a one-factor CFA to each group's data separately, the models ran fine. Can someone provide some insight on what may be the cause of the issue/ what I should do to get around this issue?

Thanks!

Yu

Pasted below are the scripts that I am using.

library(lavaan)
print(sessionInfo())


#####################################################
# Set up: C = 3
#####################################################
######### Configural Invariance Model
Configural.1.C3 <-"
## LOADINGS:

F =~ c(1, 1)*X1 + c(lambda.1_1.g1, lambda.1_1.g2)*X1
F =~ c(NA, NA)*X2 + c(lambda.2_1.g1, lambda.2_1.g2)*X2
F =~ c(NA, NA)*X3 + c(lambda.3_1.g1, lambda.3_1.g2)*X3
F =~ c(NA, NA)*X4 + c(lambda.4_1.g1, lambda.4_1.g2)*X4
F =~ c(NA, NA)*X5 + c(lambda.5_1.g1, lambda.5_1.g2)*X5
F =~ c(NA, NA)*X6 + c(lambda.6_1.g1, lambda.6_1.g2)*X6
F =~ c(NA, NA)*X7 + c(lambda.7_1.g1, lambda.7_1.g2)*X7
F =~ c(NA, NA)*X8 + c(lambda.8_1.g1, lambda.8_1.g2)*X8
F =~ c(NA, NA)*X9 + c(lambda.9_1.g1, lambda.9_1.g2)*X9
F =~ c(NA, NA)*X10 + c(lambda.10_1.g1, lambda.10_1.g2)*X10

## THRESHOLDS:

X1 | c(NA, NA)*t1 + c(X1.thr1.g1, X1.thr1.g2)*t1
X1 | c(NA, NA)*t2 + c(X1.thr2.g1, X1.thr2.g2)*t2
X2 | c(NA, NA)*t1 + c(X2.thr1.g1, X2.thr1.g2)*t1
X2 | c(NA, NA)*t2 + c(X2.thr2.g1, X2.thr2.g2)*t2
X3 | c(NA, NA)*t1 + c(X3.thr1.g1, X3.thr1.g2)*t1
X3 | c(NA, NA)*t2 + c(X3.thr2.g1, X3.thr2.g2)*t2
X4 | c(NA, NA)*t1 + c(X4.thr1.g1, X4.thr1.g2)*t1
X4 | c(NA, NA)*t2 + c(X4.thr2.g1, X4.thr2.g2)*t2
X5 | c(NA, NA)*t1 + c(X5.thr1.g1, X5.thr1.g2)*t1
X5 | c(NA, NA)*t2 + c(X5.thr2.g1, X5.thr2.g2)*t2
X6 | c(NA, NA)*t1 + c(X6.thr1.g1, X6.thr1.g2)*t1
X6 | c(NA, NA)*t2 + c(X6.thr2.g1, X6.thr2.g2)*t2
X7 | c(NA, NA)*t1 + c(X7.thr1.g1, X7.thr1.g2)*t1
X7 | c(NA, NA)*t2 + c(X7.thr2.g1, X7.thr2.g2)*t2
X8 | c(NA, NA)*t1 + c(X8.thr1.g1, X8.thr1.g2)*t1
X8 | c(NA, NA)*t2 + c(X8.thr2.g1, X8.thr2.g2)*t2
X9 | c(NA, NA)*t1 + c(X9.thr1.g1, X9.thr1.g2)*t1
X9 | c(NA, NA)*t2 + c(X9.thr2.g1, X9.thr2.g2)*t2
X10 | c(NA, NA)*t1 + c(X10.thr1.g1, X10.thr1.g2)*t1
X10 | c(NA, NA)*t2 + c(X10.thr2.g1, X10.thr2.g2)*t2

## INTERCEPTS:

X1 ~ c(nu.1.g1, nu.1.g2)*1 + c(0, 0)*1
X2 ~ c(nu.2.g1, nu.2.g2)*1 + c(0, 0)*1
X3 ~ c(nu.3.g1, nu.3.g2)*1 + c(0, 0)*1
X4 ~ c(nu.4.g1, nu.4.g2)*1 + c(0, 0)*1
X5 ~ c(nu.5.g1, nu.5.g2)*1 + c(0, 0)*1
X6 ~ c(nu.6.g1, nu.6.g2)*1 + c(0, 0)*1
X7 ~ c(nu.7.g1, nu.7.g2)*1 + c(0, 0)*1
X8 ~ c(nu.8.g1, nu.8.g2)*1 + c(0, 0)*1
X9 ~ c(nu.9.g1, nu.9.g2)*1 + c(0, 0)*1
X10 ~ c(nu.10.g1, nu.10.g2)*1 + c(0, 0)*1

## UNIQUE-FACTOR VARIANCES:

X1 ~~ c(1, 1)*X1 + c(theta.1_1.g1, theta.1_1.g2)*X1
X2 ~~ c(1, 1)*X2 + c(theta.2_2.g1, theta.2_2.g2)*X2
X3 ~~ c(1, 1)*X3 + c(theta.3_3.g1, theta.3_3.g2)*X3
X4 ~~ c(1, 1)*X4 + c(theta.4_4.g1, theta.4_4.g2)*X4
X5 ~~ c(1, 1)*X5 + c(theta.5_5.g1, theta.5_5.g2)*X5
X6 ~~ c(1, 1)*X6 + c(theta.6_6.g1, theta.6_6.g2)*X6
X7 ~~ c(1, 1)*X7 + c(theta.7_7.g1, theta.7_7.g2)*X7
X8 ~~ c(1, 1)*X8 + c(theta.8_8.g1, theta.8_8.g2)*X8
X9 ~~ c(1, 1)*X9 + c(theta.9_9.g1, theta.9_9.g2)*X9
X10 ~~ c(1, 1)*X10 + c(theta.10_10.g1, theta.10_10.g2)*X10

## LATENT FACTOR MEANS/INTERCEPTS:

F ~ c(alpha.1.g1, alpha.1.g2)*1 + c(0, 0)*1

## COMMON-FACTOR VARIANCES:

F ~~ c(NA, NA)*F + c(psi.1_1.g1, psi.1_1.g2)*F
"


( dir <- "C:/")
# import one imputed dataset for both groups
( file.imputed <- "imp_lavaan_error.csv" )
( file.imputed.path <- paste(dir, file.imputed, sep = "/") ) # absolute path to imputed data
imputed.dat <- read.table(file.imputed.path, sep = ",",header = T)
list.of.CAT.items <- paste0("X",1:10)

FittedModels.Configural.1 <- lavaan(model = Configural.1.C3, 
                                 data = imputed.dat,
                                 ordered = list.of.CAT.items,
                                 parameterization = "theta",
                                 group = "Group", 
                                 estimator = "ulsmv")
# Error in if (any(dCOV < 0)) { : missing value where TRUE/FALSE needed


# Analyze data from each group separately
GroupA<-imputed.dat[imputed.dat$Group == 1,]
GroupB<-imputed.dat[imputed.dat$Group == 2,]

OneFactorCFA.C3 <-"
## LOADINGS:

F =~ 1*X1 + X2 + X3 + X4 + X5 + X6 + X7 + X8 + X9 + X10

## THRESHOLDS:

X1 | t1 + t2
X2 | t1 + t2
X3 | t1 + t2
X4 | t1 + t2
X5 | t1 + t2
X6 | t1 + t2
X7 | t1 + t2
X8 | t1 + t2
X9 | t1 + t2
X10 | t1 + t2

## INTERCEPTS:

X1 ~ 0*1
X2 ~ 0*1
X3 ~ 0*1
X4 ~ 0*1
X5 ~ 0*1
X6 ~ 0*1
X7 ~ 0*1
X8 ~ 0*1
X9 ~ 0*1
X10 ~ 0*1

## LATENT FACTOR MEANS/INTERCEPTS:

F ~ 0*1

## UNIQUE-FACTOR VARIANCES:

X1 ~~ 1*X1 
X2 ~~ 1*X2 
X3 ~~ 1*X3 
X4 ~~ 1*X4 
X5 ~~ 1*X5 
X6 ~~ 1*X6 
X7 ~~ 1*X7 
X8 ~~ 1*X8 
X9 ~~ 1*X9 
X10 ~~ 1*X10 

## COMMON-FACTOR VARIANCES:

F ~~ F
"
FittedModels.GroupA <- lavaan(model = OneFactorCFA.C3, 
                              data = GroupA,
                              ordered = list.of.CAT.items,
                              parameterization = "theta",
                              estimator = "ulsmv")
FittedModels.GroupA 
parameterEstimates(FittedModels.GroupA)

FittedModels.GroupB <- lavaan(model = OneFactorCFA.C3, 
                              data = GroupB,
                              ordered = list.of.CAT.items,
                              parameterization = "theta",
                              estimator = "ulsmv")
FittedModels.GroupB
parameterEstimates(FittedModels.GroupB)
imp_lavaan_error.csv

Sarah Alsaadi

unread,
May 4, 2020, 2:55:35 AM5/4/20
to lavaan
Dear all,

I also have the same problem. So I am also interested if anyone knows how to deal with this.

Best,

Sarah

Terrence Jorgensen

unread,
May 15, 2020, 10:33:03 AM5/15/20
to lavaan
I am also interested if anyone knows how to deal with this.

Does it still occur in lavaan 0.6-6 (now on CRAN)?

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

Hugo Harada

unread,
Jun 5, 2020, 10:50:17 AM6/5/20
to lavaan
Hi, Yu, Sarah,

Could you check if this error goes away with Terrence and Yves replies to the thread below?


Yves released a patch to dCov < 0 issue that might help you.

Thanks for providing a reproducible example. This is now fixed in dev
lavaan 0.6-7.1565 which you can install by typing in R:

install.packages("lavaan", repos = "http://www.da.ugent.be", type =
"source")

Yves.

Regards,

Hugo
Reply all
Reply to author
Forward
0 new messages