sample covariance matrix is not positive-definite

456 views
Skip to first unread message

Jassmyn

unread,
Sep 16, 2019, 10:07:17 AM9/16/19
to lavaan
Hello,

I'm an absolute beginner with R and try to do a SEM.
I had first warnings because of a high variance in my data. I performed a z-standardization and now I have the error
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  : 
  lavaan ERROR: sample covariance matrix is not positive-definite
.
But I dont know, how to fix that.

Has somebody a suggestion?

I use the following code:


###------------------------
### Loading packages
###------------------------

library(lavaan)
library(lme4)
library(nlme)
library(reshape)
library(robustbase)
library(robustlmm)
library(WRS2)
library(psych)
library(MASS)
library(reshape2)
library(robmed)
library(semPlot)

###------------------------
### PATH MODEL
###------------------------

sem.MODELL28 <- '
ZMEAN_Spende_2 ~ ZMEAN_Schutzbereitschaft + ZMEAN_PMT_Barrieren + ZMEAN_PMT_response_efficacy + ZMEAN_PMT_self_efficacy + ZMEAN_PMT_ ethical_emotions + ZMEAN_PMT_Vulnerability + ZMEAN_PMT_Severity + ZMean_Einstellungen_gesamt + Summe_Quiz_richtig_falsch + PA01 + PA29_01 + PA07
ZMEAN_Schutzbereitschaft ~ ZMEAN_PMT_Barrieren + ZMEAN_PMT_response_efficacy + ZMEAN_PMT_self_efficacy + ZMEAN_PMT_ ethical_emotions + ZMEAN_PMT_Vulnerability + ZMEAN_PMT_Severity + ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_Barrieren ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_response_efficacy ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_self_efficacy ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_ ethical_emotions ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_Vulnerability ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMEAN_PMT_Severity ~ ZMean_Einstellungen_gesamt + ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
ZMean_Einstellungen_gesamt ~ ZSumme_Quiz_richtig_falsch + ZPA01 + ZPA29_01 + ZPA07
'

# fit the model

fitsem <- sem(sem.MODELL28, data=SPSS_DATEI_umbenannte_variablen_gekuerzt_ohne_divers_13_09_gekuerzt_Standardisierte_Variablen, estimator="MLR", test = "bootstrap")

# display summary output

summary(fitsem.MODELL28, fit.measures=TRUE, standardized = TRUE, rsquare = TRUE)


Terrence Jorgensen

unread,
Sep 17, 2019, 5:18:59 AM9/17/19
to lavaan
I had first warnings because of a high variance in my data. I performed a z-standardization

Bad idea, that biases your SEs and inflates Type I error rates.


Divide or multiply by a constant (e.g., a factor of 10 or 100) instead of by a sample-based estimate.  

now I have the error
Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]],  : 
  lavaan ERROR: sample covariance matrix is not positive-definite

If your sample covariance matrix is NPD, there are either redundant variables or some variables with no variance.  This should have nothing whatsoever to do with standardizing/transforming your variables.   Does this occur when you use test = "standard"?  If not, then it probably happens when a bootstrap sample is drawn that coincidentally has all the same values for a particular variable, or in some way produces a NPD matrix.  If it does still occur without bootstrapping, the problem is in your original data, so I recommend investigating the correlation matrix among your modeled variables.

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

Reply all
Reply to author
Forward
0 new messages