Skip to contents

Computes the (centered) log-ratio covariance matrix (see below).

Usage

covariance(x, ...)

# S4 method for CompositionMatrix
covariance(x, center = TRUE, method = "pearson")

# S4 method for ALR
covariance(x, method = "pearson")

# S4 method for CLR
covariance(x, method = "pearson")

Arguments

x

A CompositionMatrix object.

...

Currently not used.

center

A logical scalar: should the centered log-ratio covariance matrix be computed?

method

A character string indicating which covariance is to be computed (see stats::cov()).

Value

A matrix.

Methods (by class)

  • covariance(ALR): Computes the log-ratio covariance matrix (Aitchison 1986, definition 4.5).

  • covariance(CLR): Computes the centered log-ratio covariance matrix (Aitchison 1986, definition 4.6).

References

Aitchison, J. (1986). The Statistical Analysis of Compositional Data. London: Chapman and Hall, p. 64-91.

Greenacre, M. J. (2019). Compositional Data Analysis in Practice. Boca Raton: CRC Press.

See also

Other statistics: aggregate(), dist, mahalanobis(), margin(), mean(), metric_var(), quantile(), scale(), variation()

Author

N. Frerebeau

Examples

## Data from Aitchison 1986
data("hongite")

## Coerce to compositional data
coda <- as_composition(hongite)

## Log-ratio covariance matrix
## (Aitchison 1986, definition 4.5)
covariance(coda, center = FALSE)
#>            A_E        B_E        C_E       D_E
#> A_E  0.1385604  0.2641498 -0.2233304 0.1214018
#> B_E  0.2641498  0.6490135 -0.7020147 0.1444000
#> C_E -0.2233304 -0.7020147  0.9476375 0.0116220
#> D_E  0.1214018  0.1444000  0.0116220 0.1870579

## Centered log-ratio covariance matrix
## (Aitchison 1986, definition 4.6)
covariance(coda, center = TRUE)
#>             A           B           C           D           E
#> A  0.06443676  0.17907284 -0.24408053  0.01453821 -0.01396727
#> B  0.17907284  0.55298309 -0.73371823  0.02658296 -0.02492066
#> C -0.24408053 -0.73371823  0.98026080 -0.04186819  0.03940616
#> D  0.01453821  0.02658296 -0.04186819  0.04745430 -0.04670728
#> E -0.01396727 -0.02492066  0.03940616 -0.04670728  0.04618906