[R-sig-Geo] pca on raster layers with NA's

Robert J. Hijmans r.hijmans at gmail.com
Tue Jul 23 22:43:25 CEST 2013


César, I think you can do princomp(na.omit(values(s)), cor=TRUE)
For large objects, also see the pca example in ?raster::predict
Robert

On Tue, Jul 23, 2013 at 10:42 AM, César Capinha <nrevistada at yahoo.co.uk> wrote:
> Dear all,
> I have a set of 7 overlaying rasters for which I want to perform a principal components analysis and subsequently extract the corresponding maps of the two or three principal components (i.e. the scores).
> I've been trying to do this for a while, but I keep getting stuck in the beginning with this error message: "Error in cov.wt(z) : 'x' must contain finite values only"
> I think this is related to the presence of NA's in the raster layers but I'm not being able to figure out a way to solve this issue .
>
> Any suggestions ?
>
>
> #code begin
> library(raster)
> elev <- raster("elev.asc")
> expo <- raster("expo.asc")
> wind <- raster("wind.asc")
> pop <- raster("pop.asc")
> prec <- raster("prec.asc")
> temp <- raster("temp.asc")
> access <- raster("access.asc")
>
> s <- c("elev", "expo", "wind", "pop", "prec", "temp", "access")
> pca<-princomp(s, cor=T)
>
> #code end
>
>
> Many thanks in advance.
> Edward Correia
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list