raster.deviation: Raster local deviation from the global trend

View source: R/raster.deviation.R

raster.deviationR Documentation

Raster local deviation from the global trend

Description

Calculates the local deviation from the raster, a specified global statistic or a polynomial trend of the raster.

Usage

raster.deviation(
  x,
  type = c("trend", "min", "max", "mean", "median"),
  s = 3,
  degree = 1,
  global = FALSE
)

Arguments

x

A terra SpatRaster object

type

The global statistic to represent the local deviation options are: "trend", "min", "max", "mean", "median"

s

Size of matrix (focal window), not used with type="trend"

degree

The polynomial degree if type is trend, default is 1st order.

global

Use single global value for deviation or cell-level values (FALSE/TRUE). Argument is ignored for type="trend"

Details

The deviation from the trend is derived as [y-hat - y] where; y-hat is the Nth-order polynomial. Whereas the deviation from a global statistic is [y - y-hat] where; y-hat is the local (focal) statistic. The global = TRUE argument allows one to evaluate the local deviation from the global statistic [stat(x) - y-hat] where; stat(x) is the global value of the specified statistic and y-hat is the specified focal statistic.

Value

A SpatRaster class object representing local deviation from the raster or the specified global statistic

Author(s)

Jeffrey S. Evans <jeffrey_evans@tnc.org>

References

Magee, Lonnie (1998). Nonlocal Behavior in Polynomial Regressions. The American Statistician. American Statistical Association. 52(1):20-22

Fan, J. (1996). Local Polynomial Modelling and Its Applications: From linear regression to nonlinear regression. Monographs on Statistics and Applied Probability. Chapman and Hall/CRC. ISBN 0-412-98321-4

Examples

library(terra)
elev <- rast(system.file("extdata/elev.tif", package="spatialEco"))

# local deviation from first-order trend, global mean and raw value
r.dev.trend <- raster.deviation(elev, type="trend", degree=1) 
r.dev.mean <- raster.deviation(elev, type="mean", s=5)
r.gdev.mean <- raster.deviation(elev, type="mean", s=5, global=TRUE)

opar <- par(no.readonly=TRUE)
par(mfrow=c(2,2))
  plot(elev, main="original")
  plot(r.dev.trend, main="dev from trend")
  plot(r.dev.mean, main="dev of mean from raw values")
  plot(r.gdev.mean, main="local dev from global mean")
par(opar)


spatialEco documentation built on Nov. 18, 2023, 1:13 a.m.