MyNixOS website logo
Description

Unified Interface for Modern and Classical Correlation Coefficients.

Provides a single unified interface for computing a wide variety of classical and modern correlation and association measures. Continuous methods include classical correlations (Pearson, Spearman, Kendall), modern dependence measures (distance correlation, maximal information coefficient, Hilbert-Schmidt independence criterion, Chatterjee's xi, Hoeffding's D, mutual information), robust correlations (biweight midcorrelation, percentage bend, Winsorized), ordinal correlations (polychoric, tetrachoric), partial and semi-partial correlations, and nonparametric measures (ball correlation, Bergsma-Dassios tau*). Categorical association measures (Cramer's V, phi coefficient, Goodman-Kruskal gamma, Somers' D, contingency coefficient, Tschuprow's T) are available via moderncor_cat().

moderncor: Unified Interface for Modern and Classical Correlation Coefficients

moderncor is an R package that provides a single, unified interface to compute a wide variety of classical and modern correlation and association measures. Instead of remembering different package names, function calls, and argument signatures, you only need moderncor() (continuous) or moderncor_cat() (categorical).

Features

  • Single Entry Point: Compute 18 continuous association measures with moderncor(x, y, method = "...").
  • Categorical Association: Compute 6 categorical measures with moderncor_cat(x, y, method = "...").
  • Matrix Input: Compute full pairwise correlation matrices from data frames or matrices.
  • Tidy Integration: Convert results to tidy data frames with as.data.frame().
  • Partial Correlations: Control for confounders via the z parameter.
  • Fast Execution: Toggle p-value computation with p_value = FALSE.
  • Rich Output: Standardized S3 class with estimate, p-value, test statistic, and sample size.

Supported Methods

Continuous (moderncor)

CategoryMethod Namemethod keyPackage
ClassicPearson Product-Moment"pearson"stats
ClassicSpearman Rank"spearman"stats
ClassicKendall Rank"kendall"stats
ModernDistance Correlation"dcor"energy
ModernMaximal Information Coefficient"mic"minerva
ModernHilbert-Schmidt Independence Criterion"hsic"dHSIC
ModernChatterjee's Xi"xi"XICOR
ModernHoeffding's D"hoeffding"Hmisc
ModernMutual Information"mutual_info"infotheo
RobustBiweight Midcorrelation"biweight"built-in
RobustPercentage Bend"percentage_bend"WRS2
RobustWinsorized Correlation"winsorized"WRS2
OrdinalPolychoric Correlation"polychoric"psych
OrdinalTetrachoric Correlation"tetrachoric"psych
PartialPartial Correlation"partial"ppcor
PartialSemi-partial Correlation"semi_partial"ppcor
OtherBall Correlation"ball"Ball
OtherBergsma-Dassios Tau*"tau_star"TauStar

Categorical (moderncor_cat)

CategoryMethod Namemethod keyPackage
NominalCramer's V"cramers_v"DescTools
NominalPhi Coefficient"phi"DescTools
NominalContingency Coefficient"contingency"DescTools
NominalTschuprow's T"tschuprow"DescTools
OrdinalGoodman-Kruskal Gamma"gamma"DescTools
OrdinalSomers' D"somers_d"DescTools

Installation

# Install from source after cloning the repository
devtools::install()

Optional dependencies for specific methods:

install.packages(c("minerva", "Hmisc", "dHSIC", "infotheo",
                   "WRS2", "psych", "ppcor", "Ball", "TauStar", "DescTools"))

Quick Start

Basic Usage

library(moderncor)

set.seed(123)
x <- runif(100, -1, 1)
y <- x^2 + rnorm(100, sd = 0.1)  # non-linear relationship

# Pearson misses the non-linear dependency
moderncor(x, y, method = "pearson")

# Distance correlation captures it
moderncor(x, y, method = "dcor")

# Chatterjee's Xi detects functional dependence
moderncor(x, y, method = "xi")

Robust Correlations

x_out <- c(rnorm(50), 10)  # data with an outlier
y_out <- c(rnorm(50),  0)

# Biweight midcorrelation is resistant to outliers (no extra package needed)
moderncor(x_out, y_out, method = "biweight")

Partial Correlation

# Partial correlation of x and y controlling for z
z <- rnorm(100)
moderncor(x, y, z = z, method = "partial")

Categorical Association

# Cramer's V for two nominal variables
a <- factor(sample(c("A", "B", "C"), 100, replace = TRUE))
b <- factor(sample(c("X", "Y"), 100, replace = TRUE))
moderncor_cat(a, b, method = "cramers_v")

# Goodman-Kruskal Gamma for two ordinal variables
ord1 <- factor(sample(1:4, 100, replace = TRUE), ordered = TRUE)
ord2 <- factor(sample(1:4, 100, replace = TRUE), ordered = TRUE)
moderncor_cat(ord1, ord2, method = "gamma")

Pairwise Correlation Matrix

# Distance correlation matrix for the iris dataset
res_mat <- moderncor(iris[, 1:4], method = "dcor")
res_mat

# Convert to tidy data frame
as.data.frame(res_mat)

Helper Functions

# List all continuous methods
available_methods()

# List all categorical methods
available_methods_cat()

# Get details on a specific method
method_info("dcor")

License

GPL-3 (required by GPL-3 licensed dependencies).

Metadata

Version

0.2.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows