Error in lav_samplestats_icov(COV = cov[[g]], ridge = ridge, x.idx = x.idx[[g]], : lavaan ERROR:

856 views
Skip to first unread message

alex...@spedition-kern.com

unread,
Feb 25, 2018, 5:08:11 PM2/25/18
to lavaan
Can anyone help me with is error message. Can really figure out what it mean and how I can fix this:

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


library(lavaan)
model <- '
# measurement model
PEOU =~ PEOU1 + PEOU2 + PEOU3
PU =~ PU1 + PU2 + PU3
LN =~ LN1 + LN2 + LN3
A =~ A1 + A2
BI =~ BI1
# regressions
PU ~ PEOU
PEOU ~ LN
A ~ PU + PEOU
BI ~ A
'

myNames <- lavNames(sem(model))
myData <- Mappe1[myNames]
myData <- myData[complete.cases(myData), ] # unnecessary if no missing data
myCov <- cov(myData)
round(myCov, 2)
## check whether any correlations are perfect (i.e., collinearity)
myCor <- cov2cor(myCov)
noDiag <- myCor
diag(noDiag) <- 0
any(noDiag == 1)
## if not, check for multicollinearity (i.e., is one variable a linear combination of 2+ variables?)
det(myCov) < 0
## or
any(eigen(myCov)$values < 0)
lavaan::sem(model, data=Mappe1)

fit <- lavaan::sem(model, data=Mappe1)
summary(fit, standardized=TRUE)

Thanks :)

kma...@aol.com

unread,
Feb 25, 2018, 10:21:10 PM2/25/18
to lavaan
Alex,
  Perhaps it is the first part of the error that is confusing you.  This is not that important in this case and is simply telling you that the function lav_samplestats_icov().  The second part is the important part for your purposes.  It is fairly transparent in telling you that your sample covariance matrix cannot be inverted because it is not positive definite.  This is a data problem, not a syntax problem.

  Your later code should help identify the problem.  You tested that the determinant of the covariance matrix was non-negative.  My only suggestion would be to test for greater-or-equal to zero to better match the property of being positive definite.

  It is not necessary but only sufficient for being non-positive definte that one variable perfectly predicts another.  Another possibility is that two or more variables perfectly predict a third.  A convenient way to check for this is to use the rela package to run a classical item analysis on your variables.  Ignore all the output except the squared multiple correlation predicting each variable from the rest.  If any of these is 1, that variable is your problem.  Another possibility is that one of your columns of data is a constant instead of a variable, or becomes one when you address missing data.

Keith
------------------------
Keith A. Markus
John Jay College of Criminal Justice, CUNY
http://jjcweb.jjay.cuny.edu/kmarkus
Frontiers of Test Validity Theory: Measurement, Causation and Meaning.
http://www.routledge.com/books/details/9781841692203/

Reply all
Reply to author
Forward
0 new messages