| Title: | Unified Interface for Modern and Classical Correlation Coefficients |
|---|---|
| Description: | 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(). |
| Authors: | Toshihiro Iguchi [aut, cre] |
| Maintainer: | Toshihiro Iguchi <[email protected]> |
| License: | GPL-3 |
| Version: | 0.2.0 |
| Built: | 2026-06-24 13:30:06 UTC |
| Source: | https://github.com/cran/moderncor |
Convert moderncor object to a data.frame
## S3 method for class 'moderncor' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'moderncor' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
An object of class "moderncor". |
row.names |
Ignored. |
optional |
Ignored. |
... |
Additional arguments. |
A data.frame.
Convert moderncor_cat object to a data.frame
## S3 method for class 'moderncor_cat' as.data.frame(x, row.names = NULL, optional = FALSE, ...)## S3 method for class 'moderncor_cat' as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
An object of class "moderncor_cat". |
row.names |
Ignored. |
optional |
Ignored. |
... |
Additional arguments. |
A data.frame.
List all available correlation methods
available_methods()available_methods()
A data.frame with method names, labels, and package requirements.
available_methods()available_methods()
List all available categorical association methods
available_methods_cat()available_methods_cat()
A data.frame with method names, labels, package requirements, and type.
available_methods_cat()available_methods_cat()
Get detailed information about a specific correlation method
method_info(method)method_info(method)
method |
Character: the method name. |
A list with method details.
method_info("pearson")method_info("pearson")
This function provides a single unified interface to compute a wide range of classical and modern correlation and association measures.
moderncor( x, y = NULL, z = NULL, method = c("pearson", "spearman", "kendall", "dcor", "mic", "hsic", "xi", "hoeffding", "mutual_info", "biweight", "percentage_bend", "winsorized", "polychoric", "tetrachoric", "partial", "semi_partial", "ball", "tau_star"), alternative = c("two.sided", "less", "greater"), p_value = TRUE, use = c("complete.obs", "everything", "pairwise.complete.obs"), method_partial = c("pearson", "spearman", "kendall"), ... )moderncor( x, y = NULL, z = NULL, method = c("pearson", "spearman", "kendall", "dcor", "mic", "hsic", "xi", "hoeffding", "mutual_info", "biweight", "percentage_bend", "winsorized", "polychoric", "tetrachoric", "partial", "semi_partial", "ball", "tau_star"), alternative = c("two.sided", "less", "greater"), p_value = TRUE, use = c("complete.obs", "everything", "pairwise.complete.obs"), method_partial = c("pearson", "spearman", "kendall"), ... )
x |
A numeric vector, matrix, or data.frame. |
y |
A numeric vector, or |
z |
A numeric vector, matrix, or data.frame representing control variables. Required for partial and semi-partial correlations. |
method |
Character: the association method to compute. Must be one of:
|
alternative |
Character: alternative hypothesis. Must be one of
|
p_value |
Logical: whether to compute the p-value. Default is |
use |
Character: how to handle missing values. Must be one of:
|
method_partial |
Character: correlation method to use for partial/semi-partial.
Must be one of |
... |
Additional arguments passed to the underlying compute functions.
For example, |
Most methods delegate both the estimate and the p-value to the original
implementing package. The biweight midcorrelation is an exception: because no
CRAN package provides it (the reference implementation lives in the
Bioconductor-only WGCNA package), moderncor computes the estimate
from the standard formula (Wilcox 2012) and approximates its p-value with a
Student's t statistic, on
degrees of freedom (the same approximation used by WGCNA::bicorAndPvalue).
This p-value is therefore approximate and should be interpreted with care for
small samples or heavily contaminated data.
An object of class "moderncor".
Wilcox, R. R. (2012). Introduction to Robust Estimation and Hypothesis Testing (3rd ed.). Academic Press.
# Generate some non-linear data (parabolic relationship) set.seed(123) x <- runif(100, -1, 1) y <- x^2 + rnorm(100, sd = 0.1) # Pearson correlation (close to 0 due to non-linearity) moderncor(x, y, method = "pearson") # Distance correlation (captures non-linear association) moderncor(x, y, method = "dcor") # Chatterjee's Xi correlation moderncor(x, y, method = "xi") # Compute correlation matrix for iris dataset (first 4 columns) moderncor(iris[, 1:4], method = "pearson")# Generate some non-linear data (parabolic relationship) set.seed(123) x <- runif(100, -1, 1) y <- x^2 + rnorm(100, sd = 0.1) # Pearson correlation (close to 0 due to non-linearity) moderncor(x, y, method = "pearson") # Distance correlation (captures non-linear association) moderncor(x, y, method = "dcor") # Chatterjee's Xi correlation moderncor(x, y, method = "xi") # Compute correlation matrix for iris dataset (first 4 columns) moderncor(iris[, 1:4], method = "pearson")
Compute correlation/association coefficients for categorical variables
moderncor_cat( x, y = NULL, method = c("cramers_v", "phi", "gamma", "somers_d", "contingency", "tschuprow"), use = c("complete.obs", "everything", "pairwise.complete.obs"), ... )moderncor_cat( x, y = NULL, method = c("cramers_v", "phi", "gamma", "somers_d", "contingency", "tschuprow"), use = c("complete.obs", "everything", "pairwise.complete.obs"), ... )
x |
A factor vector, character vector, numeric vector (treated as categorical), data.frame, or matrix. |
y |
A factor vector, character vector, numeric vector (treated as categorical), or NULL. |
method |
Character: the categorical association method to compute. Must be one of:
|
use |
Character: how to handle missing values. Must be one of:
|
... |
Additional arguments passed to the underlying compute functions. |
An object of class "moderncor_cat".
Print a moderncor object
## S3 method for class 'moderncor' print(x, digits = 4, ...)## S3 method for class 'moderncor' print(x, digits = 4, ...)
x |
An object of class "moderncor". |
digits |
Integer: number of decimal places to print. |
... |
Additional arguments. |
The input object invisibly.
Print a moderncor_cat object
## S3 method for class 'moderncor_cat' print(x, digits = 4, ...)## S3 method for class 'moderncor_cat' print(x, digits = 4, ...)
x |
An object of class "moderncor_cat". |
digits |
Integer: number of decimal places to print. |
... |
Additional arguments. |
The input object invisibly.
Print a summary.moderncor object
## S3 method for class 'summary.moderncor' print(x, digits = 4, ...)## S3 method for class 'summary.moderncor' print(x, digits = 4, ...)
x |
An object of class "summary.moderncor". |
digits |
Integer: number of decimal places to print. |
... |
Additional arguments. |
The input object invisibly.
Print a summary.moderncor_cat object
## S3 method for class 'summary.moderncor_cat' print(x, digits = 4, ...)## S3 method for class 'summary.moderncor_cat' print(x, digits = 4, ...)
x |
An object of class "summary.moderncor_cat". |
digits |
Integer: number of decimal places to print. |
... |
Additional arguments. |
The input object invisibly.
Summarize a moderncor object
## S3 method for class 'moderncor' summary(object, ...)## S3 method for class 'moderncor' summary(object, ...)
object |
An object of class "moderncor". |
... |
Additional arguments. |
An object of class "summary.moderncor".
Summarize a moderncor_cat object
## S3 method for class 'moderncor_cat' summary(object, ...)## S3 method for class 'moderncor_cat' summary(object, ...)
object |
An object of class "moderncor_cat". |
... |
Additional arguments. |
An object of class "summary.moderncor_cat".