Package 'recor'

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

Help Index


Rearrangement Correlation (r#r^\#)

Description

Computes the rearrangement correlation coefficient (r#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 rr 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 xx and yy, it is defined as:

r#(x,y)=sx,ysx,yr^\#(x, y) = \frac{s_{x,y}}{\left| s_{x^\uparrow, y^\updownarrow} \right|}

where:

  • sx,ys_{x,y} is the sample covariance between xx and yy.

  • xx^\uparrow is the increasing rearrangement of xx.

  • yy^\updownarrow is either yy^\uparrow (increasing rearrangement) if sx,y0s_{x,y} \geq 0 or yy^\downarrow (decreasing rearrangement) if sx,y<0s_{x,y} < 0

Key properties of the rearrangement correlation:

  • r#1|r^\#| \leq 1 with equality if and only if xx and yy are monotone dependent.

  • r#r|r^\#| \geq |r| with equality when yy is a permutation of ax+bax + b (i.e., linear relationship).

  • More accurate than classical coefficients for nonlinear monotone dependence.

  • Reverts to Pearson's rr for linear relationships and to Spearman's ρ\rho 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

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