layerStats: Correlation and (weighted) covariance

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/layerStats.R

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

1
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:

See Also

cellStats, cov.wt, weighted.mean

Examples

1
2
3
4
5
6
7
8
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 documentation built on Nov. 17, 2017, 5:51 a.m.