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

6,103 views
Skip to first unread message

Dev c

unread,
Mar 9, 2017, 4:25:29 AM3/9/17
to lavaan
Dear Colleagues
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


mod_s<- '
          # latent variables
            Clim_t=~ bio5+ bio8+ bio4+ bio7+ bio6
            clim_p=~ WrHMI+ bio14+ bio13+ AHM
            OrgL=~ pHAufl +Naufl+ cnaufl
            MinSoil=~pH010 +N010 +cn010+ bs010+ cec010+ Boden_fein_proz
            SoilWater=~ fieldcapac_real+ fieldcapac_tot
            Climate=~Clim_t+ clim_p
            Soil=~OrgL+MinSoil+SoilWater

          # correlations 
            clim_p~~ SoilWater
          # regression
            meanH15cl~ Climate+ Soil

    '
# Step 2: Estimate model
fit2soil<-sem(mod_s, data=data_cl)
summary(fit2soil, standardized=T, modindices = F, fit.measures=T)

I am doing some factorial analysis to understand relative influence of soil  and climate on tree growth

thanks and regards
Dev


Terrence Jorgensen

unread,
Mar 9, 2017, 4:42:07 AM3/9/17
to lavaan
  lavaan ERROR: sample covariance matrix is not positive-definite

Because you are providing raw data, this probably means that there is linear dependency among your variables (at least, when calculated using complete observations).  You can check the covariance matrix of variables in your data set like this:

myNames <- lavNames(sem(mod_s))
myData
<- data_cl[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)

If you have linear dependency among your variables, then there is redundant information (because one variable is already a combination of other variables, without error).  So you would need to use a subset of nonredundant variables in your analysis.

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


D Chakraborty

unread,
Mar 9, 2017, 5:17:08 AM3/9/17
to lav...@googlegroups.com
Dear  Terrence
Thanks a lot for your help. I did some variable selection based on multi collinearity, I agree some variables are correlated linearly, but the model should converge anyways right? and there should have been some warning in 

Maybe I will try  to use only the uncorrelated ones and see what happens
Thanks a lot
regards
Dev


--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/nFMleMpCXbg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+unsubscribe@googlegroups.com.
To post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.



--
Dr. Debojyoti Chakraborty
Bundesforschungs- und Ausbildungszentrum für Wald, Naturgefahren und Landschaft
Austria, 1131 Wien, Seckendorff-Gudent-Weg 8
Ph: Vienna +43 660 508 6480 (m), 43 187838 2220
debojyoti....@boku.ac.at

Terrence Jorgensen

unread,
Mar 10, 2017, 4:24:42 AM3/10/17
to lavaan
but the model should converge anyways right? 

This error occurs before convergence is even relevant, because the model cannot even begin to be fit to the data if the data have linear dependencies. 

luisa....@googlemail.com

unread,
Sep 17, 2021, 9:03:50 AM9/17/21
to lavaan
Hi Terrence,
then how do I find out which variables are redundant after `det(myCov)<0` comes back TRUE?
Reply all
Reply to author
Forward
0 new messages