parCov: Efficient calculation of covariance matrices for Raster*...

Description Usage Arguments Details Value See Also Examples

Description

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.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
)

Arguments

x

Raster* object, typically a brick or stack

y

NULL (default) or a Raster* object with the same extent and resolution as x

...

additional arguments, including any of the following:

w

optional Raster* object of weights for a weighted covariance matrix

sample

logical. If TRUE, the sample covariance is calculated with a denominator of $n-1$

progress

logical. If TRUE, messages and progress bar will be printed

parallel

logical. If TRUE then multiple cores are utilized

n

numeric. Number of CPU cores to utilize for parallel processing

cl

optional cluster object

keep.open

logical. If TRUE and parallel = TRUE, the cluster object will not be closed after the function has finished

Details

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.

Value

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.

See Also

cov, layerStats

Examples

1
2
3
4
5
6
7
8
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)

CENFA documentation built on Aug. 16, 2021, 9:06 a.m.