1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
\name{localFun}
\docType{methods}
\alias{localFun}
\alias{localFun,RasterLayer,RasterLayer-method}
\title{Local functions}
\description{
Local functions for two RasterLayer objects (using a focal neighborhood)
}
\usage{
\S4method{localFun}{RasterLayer,RasterLayer}(x, y, ngb=5, fun, filename='', ...)
}
\arguments{
\item{x}{RasterLayer or RasterStack/RasterBrick}
\item{y}{object of the same class as \code{x}, and with the same number of layers}
\item{ngb}{integer. rectangular neighbourhood size. Either a single integer or a vector of two integers c(rows, cols), such as c(3,3) to have a 3 x 3 focal window}
\item{fun}{function}
\item{filename}{character. Output filename (optional)}
\item{...}{additional arguments as for \code{\link{writeRaster}}}
}
\note{The first two arguments that \code{fun} needs to accept are vectors representing the local cells of RasterLayer \code{x} and \code{y} (each of length \code{ngb * ngb}). It also must have an ellipsis (\code{...}) argument}
\value{
RasterLayer
}
\seealso{ \code{\link{corLocal}}, \code{\link{localFun}} }
\examples{
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)
\dontrun{
# 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)
}
}
\keyword{methods}
\keyword{spatial}
|