Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created August 16, 2012 12:45
Show Gist options
  • Save jlehtoma/3369870 to your computer and use it in GitHub Desktop.
Save jlehtoma/3369870 to your computer and use it in GitHub Desktop.
Calculate Kendall rank-correlation coefficietn between 2 rasters
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