Lavaan ERROR: sample covariance matrix is not positive-definite

280 views
Skip to first unread message

Lena GebSchnau

unread,
Aug 3, 2020, 9:38:58 AM8/3/20
to lavaan
Hi,

I tried my model with example variables and it all worked. After that, I wanted to calculate the model with the real variables. I actually only reduced the number of participants (327 to 316) and in the model the variable names to the new ones. But since then I get the error: "sample covariance matrix is not positive-definite" when giving the sem() order...

What did I do wrong? What does the error mean?


Patrick (Malone Quantitative)

unread,
Aug 3, 2020, 9:51:35 AM8/3/20
to lav...@googlegroups.com
Lena,

The classic cause is a linear redundancy among the variables.

But it's also likely to do with missing data. A covariance matrix based on pairwise deletion (the most common strategy for missing) can be NPD.

Do you have missing? How much? How did you direct sem() to handle it?

Pat

--
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/74c39942-bcfd-4d8a-b1d9-dc285df7d198o%40googlegroups.com.


--
Patrick S. Malone, Ph.D., Malone Quantitative
NEW Service Models: http://malonequantitative.com

He/Him/His

Lena GebSchnau

unread,
Aug 3, 2020, 10:01:27 AM8/3/20
to lavaan
I dont have missings. I had one but I did a multiple imputation.

If there was redundancy shouldnt the model before lead to an error as well? Because I didn't change the model only the number of participants.

I use centered variables because of a interaction effect. Could that have anything to do with it?

Patrick (Malone Quantitative)

unread,
Aug 3, 2020, 10:28:45 AM8/3/20
to lav...@googlegroups.com
Hmm. No, centering wouldn't affect it.

What's the sem() function call look like?

--
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.

Sunday Ogbu

unread,
Aug 3, 2020, 12:42:41 PM8/3/20
to lav...@googlegroups.com
I have a similar problem: Lavaan ERROR: sample covariance matrix is not positive-definite, even when the same data could be analyzed in other softwares.

Lena GebSchnau

unread,
Aug 3, 2020, 1:03:36 PM8/3/20
to lavaan
It's :
fit.perfect.EN <- sem(Model_Perfect.Lavaan.EN, data = data.Perfect.EN)
my data.frame might be relevant too, its:

data.Perfect.EN <- data.frame(EN.EN = EN.EN, SOP.c.EN = SOP.c.EN, SPP.c.EN = SPP.c.EN, TP.c.EN = TP.c.EN, SOP.c.ENxTP.c.EN = SOP.c.EN*TP.c.EN, SPP.c.ENxTP.c.EN = SPP.c.EN*TP.c.EN)


Am Montag, 3. August 2020 16:28:45 UTC+2 schrieb Patrick (Malone Quantitative):
Hmm. No, centering wouldn't affect it.

What's the sem() function call look like?

On Mon, Aug 3, 2020 at 10:01 AM Lena GebSchnau <leeen...@gmail.com> wrote:
I dont have missings. I had one but I did a multiple imputation.

If there was redundancy shouldnt the model before lead to an error as well? Because I didn't change the model only the number of participants.

I use centered variables because of a interaction effect. Could that have anything to do with it?

--
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 lav...@googlegroups.com.

Lena GebSchnau

unread,
Aug 3, 2020, 1:08:47 PM8/3/20
to lavaan

It also says: 
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  :

Yves Rosseel

unread,
Aug 4, 2020, 8:13:05 AM8/4/20
to lav...@googlegroups.com
This is a problem with your data. Before you call lavaan, first compute
the covariance matrix of your data, eg

COV <- cov(Data)

Then, you can use the eigen() function to check if the matrix is of full
rank:

eigen(COV)$values

All eigenvalues should be strictly positive. If not, you may have one or
more variables are a linear combination of the others. To find out,
first compute the correlation matrix:

COR <- cor(Data)

to check for very high correlations (>0.90). If any, remove one of the
two variables, and try again.

If not, you may have to remove variables, one-by-one, until you have
found the one that is causing the trouble.

Yves.

Lena GebSchnau

unread,
Aug 4, 2020, 9:13:41 AM8/4/20
to lavaan

That worked. 


THANK YOU SO MUCH!!!!!!!! 
Reply all
Reply to author
Forward
0 new messages