Focal regression
focalReg.Rd
Calculate values for a moving-window by comparing the value in one layers with the values in one to many other layers. A typical case is the computation of the coefficients for a focal linear regression model.
Usage
# S4 method for class 'SpatRaster'
focalReg(x, w=3, fun="ols", ..., fillvalue=NA, filename="", overwrite=FALSE, wopt=list())
Arguments
- x
SpatRaster with at least two layers. The first is the "Y" (dependent) variable and the remainder are the "X" (independent) variables
- w
numeric or matrix to define the focal window. The window an be defined as one (for a square) or two numbers (row, col); or with an odd-sized weights matrix. See the Details section in
focal
. Note that if a matrix with numbers other than zero or one are used, the values are used as weights. For this to work,fun
must have an argumentweights
- fun
a function with at least two arguments (one for each layer). There is a built-in function "ols" for both the weighted and unweighted Ordinary Least Square regression. This function has an additional argument
na.rm=FALSE
andintercept=TRUE
- ...
additional arguments for
fun
- fillvalue
numeric. The value of the cells in the virtual rows and columns outside of the raster
- filename
character. Output filename
- overwrite
logical. If
TRUE
,filename
is overwritten- wopt
additional arguments for writing files as in
writeRaster