sample covariance matrix is (near) zero or negative.

862 views
Skip to first unread message

Omar Salim

unread,
Jan 31, 2021, 4:09:30 PM1/31/21
to lavaan



Hello
When the model is executed with Lavaan the following error appears in the covariance matrix and no results are shown
How can this problem be solved

> fit.bis <- sem(mode22.SPE, sample.cov = S, sample.mean =
+                    sample.mean, sample.th = sample.th, sample.nobs = sample.nobs,
+                WLS.V = WLS.V, NACOV = NACOV,,se="standard",test="standard", estimator ="ML")
Error in lavData(data = data, group = group, cluster = cluster, ov.names = OV.NAMES,  : 
  lavaan ERROR: at least one variance in the sample covariance matrix is (near) zero or negative.

balal izanloo

unread,
Jan 31, 2021, 7:41:00 PM1/31/21
to lav...@googlegroups.com


On Mon, 1 Feb 2021, 00:39 Omar Salim, <omarsal...@gmail.com> wrote:



Hello
When the model is executed with Lavaan the following error appears in the covariance matrix and no results are shown
How can this problem be solved

> fit.bis <- sem(mode22.SPE, sample.cov = S, sample.mean =
+                    sample.mean, sample.th = sample.th, sample.nobs = sample.nobs,
+                WLS.V = WLS.V, NACOV = NACOV,,se="standard",test="standard", estimator ="ML")

Look to the bule comma in the above command line
Error in lavData(data = data, group = group, cluster = cluster, ov.names = OV.NAMES,  : 
  lavaan ERROR: at least one variance in the sample covariance matrix is (near) zero or negative.

That error show that one of your variable in data has fixed value. Check yor data carfully.
 You have a covarince matrix as data input may be you have introduced it un correctly. 

--
You received this message because you are subscribed to the Google Groups "lavaan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lavaan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lavaan/2629cbbc-82b7-4283-acc5-6daebbfee841n%40googlegroups.com.

balal izanloo

unread,
Jan 31, 2021, 9:11:12 PM1/31/21
to lav...@googlegroups.com
On Mon, Feb 1, 2021 at 12:39 AM Omar Salim <omarsal...@gmail.com> wrote:



Hello
When the model is executed with Lavaan the following error appears in the covariance matrix and no results are shown
How can this problem be solved

> fit.bis <- sem(mode22.SPE, sample.cov = S, sample.mean =
+                    sample.mean, sample.th = sample.th, sample.nobs = sample.nobs,
+                WLS.V = WLS.V, NACOV = NACOV,,se="standard",test="standard", estimator ="ML")
 
look to the double comma in the above command line 
 
Error in lavData(data = data, group = group, cluster = cluster, ov.names = OV.NAMES,  : 
  lavaan ERROR: at least one variance in the sample covariance matrix is (near) zero or negative.

That error shows that at least one of your variables in data has fixed value. Check your data carefully. i think You have a covariance matrix as data input and so maybe you have introduced it incorrectly.

Omar Salim

unread,
Feb 1, 2021, 11:38:51 AM2/1/21
to lav...@googlegroups.com
Yes, my input is a covariance matrix computed from the array data. The values ​​are correct for input How do I solve the problem of this correlation close to zero Is there a way

balal izanloo

unread,
Feb 1, 2021, 12:17:33 PM2/1/21
to lav...@googlegroups.com
One of your variable has zero variance. the error is related to this problem. Check your data

Omar Salim

unread,
Feb 1, 2021, 12:41:46 PM2/1/21
to lav...@googlegroups.com
I used a robust correlation array for the input process, omit variables, but the same problem appears
The correlation matrix is
covfch

‫في الاثنين، 1 فبراير 2021 في 8:17 م تمت كتابة ما يلي بواسطة ‪balal izanloo‬‏ <‪b.ez...@gmail.com‬‏>:‬

balal izanloo

unread,
Feb 1, 2021, 9:33:29 PM2/1/21
to lav...@googlegroups.com
Salim,the problem is related to your data not to an estimation method that you have used for correlation matrix. to solve the problem, use raw data instead of correlation matrix as input, if the problem continues to exist paste all of your commands to the lavaan group along with data.

 



Tyler Moore

unread,
Mar 17, 2024, 9:17:52 PM3/17/24
to lavaan
I'm getting this same error:

lavaan ERROR: at least one variance in the sample covariance matrix is (near) zero or negative.

and my command is:

mod <- cfa(model, sample.cov=xcor, sample.nobs=11017, std.lv = FALSE, estimator="ULS")

I checked the correlation matrix and the diagonal is indeed 1.0 for all variables, so why would it think one of them is near-zero?  The only thing I can think of is that lavaan is glitching out because the corr matrix is 10000-by-10000.  Any ideas?

Thanks!!

Maxim

unread,
Apr 30, 2024, 11:28:58 AM4/30/24
to lavaan
I had the same issue. It seems tit was caused by my covariance matrix being a data.frame object, so after I converted it using as.matrix(), the error was gone. Perhaps a little bug in the lavaan.
Reply all
Reply to author
Forward
0 new messages