Jeffrey Evans
Quantitative Methods in Spatial Ecology
Bivariate Moving Window Raster Correlation
PROGRAM
mwcor.R
USE
Calculates a bivariate moving window correlation on two rasters
REQUIRES
R >= 2.14, sp, spdep
ARGUMENTS
x X VARIABLE GRID OBJECT
y Y VARIABLE GRID OBJECT
dist WINDOW SIZE IN DISTANCE UNITS (DEFAULT IS "AUTO" AND IS CALCULATED AUTOMATICLY)
... ADDITIONAL ARGUMENTS TO PASS TO cor FUNCTION
VALUE
A SpatialGridDataFrame sp OBJECT WITH THE CORRLEATIONS
EXAMPLES
library(gstat)
library(sp)
library(spdep)
data(meuse)
data(meuse.grid)
coordinates(meuse) <- ~x + y
coordinates(meuse.grid) <- ~x + y
# GRID-1 log(copper):
v1 <- variogram(log(copper) ~ 1, meuse)
x1 <- fit.variogram(v1, vgm(1, "Sph", 800, 1))
G1 <- krige(zinc ~ 1, meuse, meuse.grid, x1, nmax = 30)
gridded(G1) <- TRUE
G1@data = as.data.frame(G1@data[,-2])
# GRID-2 log(lead):
v2 <- variogram(log(lead) ~ 1, meuse)
x2 <- fit.variogram(v2, vgm(.1, "Sph", 1000, .6))
G2 <- krige(zinc ~ 1, meuse, meuse.grid, x2, nmax = 30)
gridded(G2) <- TRUE
G2@data <- as.data.frame(G2@data[,-2])
# MOVING WINDOW CORRELATION AND PLOT RESULTS
gcorr <- mwcor(G1, G2, 40, method="spearman")
colr=colorRampPalette(c("blue", "yellow", "red"))
spplot(gcorr, col.regions=colr(100))