Calculate the coeffients for a focal ("moving window") OLS regression model.
# S4 method for SpatRaster
focalReg(x, w=3, na.rm=TRUE,
fillvalue=NA, expand=FALSE, filename="", ...)
SpatRaster with at leat two layers. The first is the "Y" (dependent) variable and the remainder are the "X" (independent) variables
window. The window can 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
logical. Should missing values be removed?
numeric. The value of the cells in the virtual rows and columns outside of the raster
logical. If TRUE
The value of the cells in the virtual rows and columns outside of the raster are set to be the same as the value on the border
character. Output filename
additional arguments for writing files as in writeRaster
SpatRaster
# NOT RUN {
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)
# }
Run the code above in your browser using DataLab