## S3 method for class 'RasterLayer,RasterLayer':
corLocal(x, y, ngb=5,
method=c("pearson", "kendall", "spearman"), test=FALSE, filename='', ...)
## S3 method for class 'RasterStackBrick,RasterStackBrick':
corLocal(x, y,
method=c("pearson", "kendall", "spearman"), test=FALSE, filename='', ...)
x
, and with the same number of layers"pearson"
, "kendall"
, or "spearman"
TRUE
, return a p-valuewriteRaster
cor
, cor.test
set.seed(0)
b <- stack(system.file("external/rlogo.grd", package="raster"))
b[[2]] <- flip(b[[2]], 'y') + runif(ncell(b))
b[[1]] <- b[[1]] + runif(ncell(b))
x <- corLocal(b[[1]], b[[2]] )
plot(x)
# only cells where the p-value < 0.1
xm <- mask(x[[1]], x[[2]] < 0.1, maskvalue=FALSE)
plot(xm)
# for global correlation, use the cor function
x <- as.matrix(b)
cor(x, method="spearman")
# use sampleRegular for large datasets
x <- sampleRegular(b, 1000)
cor.test(x[,1], x[,2])
# RasterStack or Brick objects
y <- corLocal(b, flip(b, 'y'))
Run the code above in your browser using DataLab