| Title: | Rearrangement Correlation Coefficient |
|---|---|
| Description: | The Rearrangement Correlation Coefficient is an adjusted version of Pearson's correlation coefficient that accurately measures monotonic dependence relationships, including both linear and nonlinear associations. This method addresses the underestimation problem of classical correlation coefficients in nonlinear monotonic scenarios through improved statistical bounds derived from rearrangement inequalities. For more details, see Ai (2024) <doi:10.52202/079017-1180>. |
| Authors: | Xinbo Ai [aut, cre] |
| Maintainer: | Xinbo Ai <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.3 |
| Built: | 2026-05-18 09:33:45 UTC |
| Source: | https://github.com/byaxb/recor |
)Computes the rearrangement correlation coefficient (), an adjusted version of Pearson's
correlation coefficient that addresses the underestimation problem for monotonic dependence.
This coefficient captures arbitrary monotone relationships (both linear and nonlinear) while
reverting to Pearson's in linear scenarios. The rearrangement correlation is derived from
a tighter inequality than the classical Cauchy-Schwarz inequality, providing sharper bounds
and expanded capture range.
recor(x, y = NULL)recor(x, y = NULL)
x |
A numeric vector, matrix, or data.frame. |
y |
NULL (default) or a vector, matrix, or data.frame with compatible dimensions to x. |
The rearrangement correlation coefficient is based on rearrangement inequality theorems that
provide tighter bounds than the Cauchy-Schwarz inequality. Mathematically, for samples and ,
it is defined as:
where:
is the sample covariance between and .
is the increasing rearrangement of .
is either (increasing rearrangement) if
or (decreasing rearrangement) if
Key properties of the rearrangement correlation:
with equality if and only if and are monotone dependent.
with equality when is a permutation of
(i.e., linear relationship).
More accurate than classical coefficients for nonlinear monotone dependence.
Reverts to Pearson's for linear relationships and to Spearman's for rank data.
The function automatically handles various input types consistently with stats::cor():
If x is a vector and y is a vector: returns a single correlation value
If x is a matrix/data.frame and y is NULL: returns correlation matrix between columns of x
If x and y are both matrices/data.frames: returns correlation matrix between columns of x and y
A numeric value or matrix containing the rearrangement correlation coefficient(s):
Single correlation value if x and y are vectors
Correlation matrix if x is a matrix/data.frame (symmetric if y is NULL, rectangular if y is provided)
Ai, X. (2024). Adjust Pearson's r to Measure Arbitrary Monotone Dependence. In Advances in Neural Information Processing Systems (Vol. 37, pp. 37385-37407). https://proceedings.neurips.cc/paper_files/paper/2024/file/41c38a83bd97ba28505b4def82676ba5-Paper-Conference.pdf
cor for Pearson's correlation coefficient,
cor with method = "spearman" for Spearman's rank correlation,
cor with method = "kendall" for Kendall's rank correlation,
cov for covariance calculation
# Vector example (perfect linear relationship) x <- c(1, 2, 3, 4, 5) y <- c(2, 4, 6, 8, 10) recor(x, y) # Returns 1.0 # Nonlinear monotone relationship x <- c(1, 2, 3, 4, 5) y <- c(1, 8, 27, 65, 125) # y = x^3 recor(x, y) # Higher value than Pearson's r cor(x, y) # Matrix example set.seed(123) mat <- matrix(rnorm(100), ncol = 5) colnames(mat) <- LETTERS[1:5] recor(mat) # 5x5 correlation matrix # Two matrices mat1 <- matrix(rnorm(50), ncol = 5) mat2 <- matrix(rnorm(50), ncol = 5) recor(mat1, mat2) # 5x5 cross-correlation matrix # data.frame recor(iris[, 1:4]) # correlation matrix for iris dataset features# Vector example (perfect linear relationship) x <- c(1, 2, 3, 4, 5) y <- c(2, 4, 6, 8, 10) recor(x, y) # Returns 1.0 # Nonlinear monotone relationship x <- c(1, 2, 3, 4, 5) y <- c(1, 8, 27, 65, 125) # y = x^3 recor(x, y) # Higher value than Pearson's r cor(x, y) # Matrix example set.seed(123) mat <- matrix(rnorm(100), ncol = 5) colnames(mat) <- LETTERS[1:5] recor(mat) # 5x5 correlation matrix # Two matrices mat1 <- matrix(rnorm(50), ncol = 5) mat2 <- matrix(rnorm(50), ncol = 5) recor(mat1, mat2) # 5x5 cross-correlation matrix # data.frame recor(iris[, 1:4]) # correlation matrix for iris dataset features