Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

layerStats

Correlation and (weighted) covariance


Description

Compute correlation and (weighted) covariance for multi-layer Raster objects. Like cellStats this function returns a few values, not a Raster* object (see Summary-methods for that).

Usage

layerStats(x, stat, w, asSample=TRUE, na.rm=FALSE, ...)

Arguments

x

RasterStack or RasterBrick for which to compute a statistic

stat

Character. The statistic to compute: either 'cov' (covariance), 'weighted.cov' (weighted covariance), or 'pearson' (correlation coefficient)

w

RasterLayer with the weights (should have the same extent, resolution and number of layers as x) to compute the weighted covariance

asSample

Logical. If TRUE, the statistic for a sample (denominator is n-1) is computed, rather than for the population (denominator is n)

na.rm

Logical. Should missing values be removed?

...

Additional arguments (none implemetned)

Value

List with two items: the correlation or (weighted) covariance matrix, and the (weighted) means.

Author(s)

Jonathan A. Greenberg & Robert Hijmans. Weighted covariance based on code by Mort Canty

References

For the weighted covariance:

  • Canty, M.J. and A.A. Nielsen, 2008. Automatic radiometric normalization of multitemporal satellite imagery with the iteratively re-weighted MAD transformation. Remote Sensing of Environment 112:1025-1036.

  • Nielsen, A.A., 2007. The regularized iteratively reweighted MAD method for change detection in multi- and hyperspectral data. IEEE Transactions on Image Processing 16(2):463-478.

See Also

Examples

b <- brick(system.file("external/rlogo.grd", package="raster"))
layerStats(b, 'pearson')

layerStats(b, 'cov')

# weigh by column number
w <- init(b, v='col')
layerStats(b, 'weighted.cov', w=w)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.