bleutner/RStoolbox

Covariance matrix is not non-negative definite

frederikvand opened this issue · 1 comments

Error in princomp.default(covmat = covMat[[1]], cor = spca) :
covariance matrix is not non-negative definite

Error on PCA's of worldclim data. Tested on 6 different worldclim datasets and tested on 5 different machines (3 windows, 1 mac and 1 linux supercluster).

PCA_he45bi70 <- rasterPCA(he45bi70,spca=TRUE, nComp = 3, maskCheck = F)
Tested with maskcheck F and T.

1 solution would be to include the method of Rebonato and Jackel (2000), as elaborated by Brissette et al. (2007), to fix the eigenvalue matrix. The method advises to replace the negative eigenvalues with 0 (or a small positive number as Brissette et al. 2007 suggest), then normalize the new vector.

Another solution that worked is to work with nsamples.