focalReg | R Documentation |
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.
## S4 method for signature 'SpatRaster'
focalReg(x, w=3, fun="ols", ..., fillvalue=NA, filename="", overwrite=FALSE, wopt=list())
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 |
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 |
... |
additional arguments for |
fillvalue |
numeric. The value of the cells in the virtual rows and columns outside of the raster |
filename |
character. Output filename |
overwrite |
logical. If |
wopt |
additional arguments for writing files as in |
SpatRaster
focal, focal3D
, focalValues
r <- rast(ncols=10, nrows=10, ext(0, 10, 0, 10))
values(r) <- 1:ncell(r)
x <- c(r, init(r, runif) * r)
f <- focalReg(x, 3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.