While using princomp()
function in R, the following error is encountered : "covariance matrix is not non-negative definite"
.
I think, this is due to some values being zero (actually close to zero, but becomes zero during rounding) in the covariance matrix.
Is there a work around to proceed with PCA when covariance matrix contains zeros ?
[FYI : obtaining the covariance matrix is an intermediate step within the princomp()
call. Data file to reproduce this error can be downloaded from here - http://tinyurl.com/6rtxrc3]
stats:::princomp.default
you'll see that the error occurs when you have negative eigenvalues in the covariance matrix. – Dovevcv <- matrix(c(1, 2, 2, 1), nrow = 2); princomp(covmat = cv)
reproduces the error. Don't know how relevant it is to your dataset. – Dovevprincomp()
function), I usually replaceNA's
to0's
first and then add the transpose of the matrix to original matrix (some thing like this -matrix <- matrix + t(matrix)
) – Buttonball