set.seed(0)
b <- stack(system.file("external/rlogo.grd", package="raster"))
x <- flip(b[[2]], 'y') + runif(ncell(b))
y <- b[[1]] + runif(ncell(b))
f <- localFun(x, y, fun=cor)
if (FALSE) {
# local regression:
rfun <- function(x, y, ...) {
m <- lm(y~x)
# return R^2
summary(m)$r.squared
}
ff <- localFun(x, y, fun=rfun)
plot(f, ff)
}
Run the code above in your browser using DataLab