New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PCA: Error: [princomp] the covariance matrix has missing values #1441
Comments
This can happen when any combination of two layers does not have cells with values in both layers. For example:
Is that the case with your data? |
Do you mean that all cells are NA within one layer or there are cells that are NA across all the layers? |
Neither. See my example. All pairs of layers must have cells that are not NA in both layers. |
Yes, this is my case. I did run
|
Then you need to remove some of these variables. Layers 1, 3, and 4 do not seem useful as they hardly have any areas with data that overlap with areas with data in the other layers. But the variation in |
Yes indeed, cleaning of those layers is needed! |
Hi @rhijmans,
I first added this as a comment to #1361, but did some additional checkups and I thought I had found a culprit in my dataset (although in some layers there are only a few pixels without NA, but when I tried to plot them, an error of empty raster showed up).
So, I created a new dataset, and checked it before PCA, but the
Error: [princomp] the covariance matrix has missing values
showed up again.Problem:
I do have a *.vrt of
dimensions: 1566, 1962, 90 (nrow, ncol, nlyr)
. There are NAs in each layer. I did a check usingfreq(is.na())
and there is no layer that consists only of NAs. (see attached results). Also, I plotted each layer to be sure there was no empty raster error.Using
pca <- princomp(vrt_r)
I get
Error: [princomp] the covariance matrix has missing values
Would it be due to the fact some cells are always NA (across all layers)?
NA_check_vrt.txt
I created a *.tif from *.vrt, uploaded it to my work onedrive, and added your gmail to access (cannot have open access):
https://michiganstate-my.sharepoint.com/:i:/g/personal/monikat_msu_edu/EY8K8bl37NNBjEa-W3X1DA8BLWfb8IlRONMTj3F-6FXbNw?email=r.hijmans%40gmail.com&e=W2qDyZ
Thanks!
The text was updated successfully, but these errors were encountered: