-
Notifications
You must be signed in to change notification settings - Fork 0
/
covariance.R
40 lines (37 loc) · 1.04 KB
/
covariance.R
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# COVARIANCE
#' @include AllGenerics.R
NULL
# Covariance ===================================================================
#' @export
#' @rdname covariance
#' @aliases covariance,CompositionMatrix-method
setMethod(
f = "covariance",
signature = c(x = "CompositionMatrix"),
definition = function(x, center = TRUE, method = "pearson") {
x <- if (center) transform_clr(x) else transform_alr(x)
methods::callGeneric(x = x, method = method)
}
)
#' @export
#' @describeIn covariance Computes the log-ratio covariance matrix
#' (Aitchison 1986, definition 4.5).
#' @aliases covariance,ALR-method
setMethod(
f = "covariance",
signature = c(x = "ALR"),
definition = function(x, method = "pearson") {
stats::cov(x, method = method)
}
)
#' @export
#' @describeIn covariance Computes the centered log-ratio covariance matrix
#' (Aitchison 1986, definition 4.6).
#' @aliases covariance,ALR-method
setMethod(
f = "covariance",
signature = c(x = "CLR"),
definition = function(x, method = "pearson") {
stats::cov(x, method = method)
}
)