Learn R Programming

raster (version 2.3-40)

localFun: Local functions

Description

Local functions for two RasterLayer objects (using a focal neighborhood)

Usage

## S3 method for class 'RasterLayer,RasterLayer':
localFun(x, y, ngb=5, fun, filename='', ...)

Arguments

x
RasterLayer or RasterStack/RasterBrick
y
object of the same class as x, and with the same number of layers
ngb
neighborhood size. Either a single integer or a vector of two integers c(nrow, ncol)
fun
function
filename
character. Output filename (optional)
...
additional arguments as for writeRaster

Value

  • RasterLayer

See Also

corLocal, localFun

Examples

Run this code
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)

# 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