# When a CFA model has a “covariance matrix was not positive definite” problem, is it due to the dataset or the model?

I am testing several CFA measurement models with Lavaan in R. The questionnaire that I am investigating has been shown to be composed of 1-factor, 3-factor, and 4-factor.

In the dataset, I found that the 1-factor and 3-factor fit okay, but the 3-factor fits best (lowest AIC).

However, the 4-factor model could not be tested because the "covariance matrix was not positive definite". A closer look revealed that one of the factors has an above one correlation with another factor.

My question is, why is it that the covariance matrix was not positive definite in the 4-factor model in my dataset? Is this problem unique to my dataset?

I am still a beginner, so I might miss some important details.

Thank you very much for the fast response everyone! Update: The sample is 904 participants and there are 28 observed variables (items) in the model.

• It won't be the data, the data are what they are; with the one exception of possible insufficient sample size. Keep in mind maximum likelihood (which I assume is the estimation being used) has sample size guidelines for proper convergence. If you have 4 factors and they are all allowed to be correlated you can be looking at a lot of parameters to estimate. Can you update your post with the sample size and number of items. Also, were any of the variances negative? Were any of the eigenvalues negative? You can retrieve all of that with R and lavaan. – robin.datadrivers Jan 21 '15 at 14:50
• FYI there is a lavaan google group which I highly recommend joining, the developer of lavaan answers a lot of questions there. – robin.datadrivers Jan 21 '15 at 14:50

The covariance matrix of the data is always non-negative definite, there is no doubt about that. However, the model-implied covariance matrix may not be when some parameters take values outside their natural ranges. In turn, this may happen for a number of reasons.

1. Your 4-factor model may be misspecified, i.e., does not fit the data right.
2. Your model is OK, it's just that the sample that you are dealing with favors high values of the correlation parameter. To distinguish between 1 and 2, you need to find a way to test whether the correlation in question is significantly greater than 1, which is not a trivial endeavor (doi: 10.1177/0049124112442138): few packages computed the standard errors properly at the time that paper was written, and I don't know if the current version of lavaan does.
3. lavaan computes numeric derivatives (as any other software) by taking parameter $\pm$ a small step, and while the current value of the parameter is kosher, the step may throw it over the limit and produce a matrix that is not positive definite. (Analytic derivatives are available for the multivariate normal case, but binary/ordinal variables require numeric integration over the distributions of latent variables, and do not lend themselves to analytic differentiation. So this depends on your model.)

I think you can argue that, due to lack of convergence, your 4-factor model does not work well, and is not a contender in your model selection.

• Hi, I was wondering if you knew wheter or not the Lavaan estimates are still valid if this NPD warning occurs, assuming the NPD is a result of high correlation and small sample size? – Amonet Mar 25 '18 at 15:18

The reasons are summarised well by @StasK. And I will show some ways to fix this errors. It may suffer from your model building. Use function summary, you will find there are some correlations between your latent variables you define out of bound. I mean $$|\rho| > 1$$ or $$|\rho|$$ is near 1.

If you find it is true, one way to solve it is to collapse the not-good latent variables into one latent variable and their manifest variables. For example,

 latent1 =~ v1 + v2 latent2 =~ v3 + v4 latent3 =~ v5 + v6 

latent1 is good and the other two are bad. Change in this way,

 letent1 =~ v1 + v2 letent2and3 ~= v3 + v4 + v5 + v6 

And find whether there is a better result. The idea is from Erin Buchanan, you can check her tutorial for SEM on DataCamp.

Reference

• Summary function cannot be use when lavaan "throws out" "lavaan ERROR: sample covariance matrix is not positive-definite". – Elias Estatistics Mar 1 '19 at 21:06