| Type: | Package |
| Title: | Rearrangement Correlation Coefficient |
| Version: | 1.0.3 |
| 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>. |
| License: | GPL-3 |
| URL: | https://github.com/byaxb/recor |
| BugReports: | https://github.com/byaxb/recor/issues |
| Depends: | R (≥ 3.5.0) |
| Imports: | Rcpp (≥ 1.0.7) |
| LinkingTo: | Rcpp |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| NeedsCompilation: | yes |
| Packaged: | 2025-12-09 13:25:08 UTC; axb |
| Author: | Xinbo Ai [aut, cre] |
| Maintainer: | Xinbo Ai <axb@bupt.edu.cn> |
| Repository: | CRAN |
| Date/Publication: | 2025-12-15 17:50:02 UTC |
Rearrangement Correlation (r^\#)
Description
Computes the rearrangement correlation coefficient (r^\#), 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 r 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.
Usage
recor(x, y = NULL)
Arguments
x |
A numeric vector, matrix, or data.frame. |
y |
NULL (default) or a vector, matrix, or data.frame with compatible dimensions to x. |
Details
The rearrangement correlation coefficient is based on rearrangement inequality theorems that
provide tighter bounds than the Cauchy-Schwarz inequality. Mathematically, for samples x and y,
it is defined as:
r^\#(x, y) = \frac{s_{x,y}}{\left| s_{x^\uparrow, y^\updownarrow} \right|}
where:
-
s_{x,y}is the sample covariance betweenxandy. -
x^\uparrowis the increasing rearrangement ofx. -
y^\updownarrowis eithery^\uparrow(increasing rearrangement) ifs_{x,y} \geq 0ory^\downarrow(decreasing rearrangement) ifs_{x,y} < 0
Key properties of the rearrangement correlation:
-
|r^\#| \leq 1with equality if and only ifxandyare monotone dependent. -
|r^\#| \geq |r|with equality whenyis a permutation ofax + b(i.e., linear relationship). More accurate than classical coefficients for nonlinear monotone dependence.
Reverts to Pearson's
rfor linear relationships and to Spearman's\rhofor 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
Value
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)
References
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
See Also
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
Examples
# 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