Efficient calculation of covariance matrices for Raster* objects
parCov
efficiently calculates the covariance of Raster* objects,
taking advantage of parallel processing and pulling data into memory only as
necessary. For large datasets with lots of variables, calculating the covariance
matrix rapidly becomes unwieldy, as the number of calculations required grows
quadratically with the number of variables.
parCov(x, y, ...) ## S4 method for signature 'Raster,missing' parCov( x, w = NULL, sample = TRUE, progress = FALSE, parallel = FALSE, n = 1, cl = NULL, keep.open = FALSE ) ## S4 method for signature 'Raster,Raster' parCov( x, y, w = NULL, sample = TRUE, progress = FALSE, parallel = FALSE, n = 1, cl = NULL, keep.open = FALSE )
x |
Raster* object, typically a brick or stack |
y |
NULL (default) or a Raster* object with the same extent and resolution
as |
... |
additional arguments, including any of the following: |
w |
optional Raster* object of weights for a weighted covariance matrix |
sample |
logical. If |
progress |
logical. If |
parallel |
logical. If |
n |
numeric. Number of CPU cores to utilize for parallel processing |
cl |
optional cluster object |
keep.open |
logical. If |
This function is designed to work similarly to the
cov
and the layerStats
functions, with two major differences. First, parCov
allows you to
calculate the covariance between two different Raster* objects, whereas
layerStats
does not. Second, parCov
can (optionally) compute
each element of the covariance matrix in parallel, offering a dramatic
improvement in computation time for large Raster* objects.
The raster layer of weights w
should contain raw weights as values,
and should not be normalized so that sum(w) = 1
. This is
necessary for computing the sample covariance, whose formula contains
sum(w) - 1
in its denominator.
Returns a matrix with the same row and column names as the layers of
x
. If y
is supplied, then the covariances between the layers
of x
and the layers of codey are computed.
mat1 <- parCov(climdat.hist) # correlation matrix Z <- parScale(climdat.hist) mat2 <- parCov(Z) # covariance between two Raster* objects mat3 <- parCov(x = climdat.hist, y = climdat.fut)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.