Created
August 16, 2012 12:45
-
-
Save jlehtoma/3369870 to your computer and use it in GitHub Desktop.
Calculate Kendall rank-correlation coefficietn between 2 rasters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(raster) | |
library(dismo) | |
# Sample both raster with the same points | |
sample.points <- randomPoints(raster1, 500000) | |
# Extract raster values at sample point locations | |
sample.raster1 <- extract(raster1, sample.points,method='simple', na.rm=TRUE) | |
sample.raster2 <- extract(raste2, sample.points,method='simple', na.rm=TRUE) | |
# use="complete.obs" needed here, beacause raster2 might have NA where raster1 hasn't which will propagate as NA otherwise | |
correlation <- cor(sample.raster1, sample.raster1, method="kendall", use="complete.obs") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment