| Title: | Weighted Dependence Measures |
|---|---|
| Description: | Provides efficient implementations of weighted dependence measures and related asymptotic tests for independence. Implemented measures are the Pearson correlation, Spearman's rho, Kendall's tau, Blomqvist's beta, Hoeffding's D, and Chatterjee's xi; see, e.g., Nelsen (2006) <doi:10.1007/0-387-28678-0>, Hollander et al. (2015, ISBN:9780470387375), and Chatterjee (2021) <doi:10.1080/01621459.2020.1758115>. |
| Authors: | Thomas Nagler [aut, cre] |
| Maintainer: | Thomas Nagler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.3.0 |
| Built: | 2026-09-30 12:49:58 UTC |
| Source: | https://github.com/tnagler/wdm-r |
Provides efficient implementations of weighted dependence measures and related asymptotic tests for independence. Implemented measures are the Pearson correlation, Spearman's rho, Kendall's tau, Blomqvist's beta, Hoeffding's D, and Chatterjee's xi; see, e.g., Nelsen (2006) <doi:10.1007/0-387-28678-0>, Hollander et al. (2015, ISBN:9780470387375), and Chatterjee (2021) <doi:10.1080/01621459.2020.1758115>.
Maintainer: Thomas Nagler [email protected]
Authors:
Thomas Nagler [email protected]
Useful links:
Report bugs at https://github.com/tnagler/wdm-r/issues
Computes a dependence measure and its asymptotic independence test for two numeric vectors.
indep_test( x, y, method = "pearson", weights = NULL, remove_missing = TRUE, alternative = "two-sided", seeds = NULL, y_continuous = TRUE )indep_test( x, y, method = "pearson", weights = NULL, remove_missing = TRUE, alternative = "two-sided", seeds = NULL, y_continuous = TRUE )
x, y
|
numeric vectors of data values. |
method |
the dependence measure; see Details for possible values. |
weights |
an optional vector of weights for the observations. |
remove_missing |
if |
alternative |
indicates the alternative hypothesis and must be one of
|
seeds |
an optional integer vector used to break predictor ties for Chatterjee's xi. The default uses a fixed, reproducible ordering. |
y_continuous |
whether the response distribution is known to be
continuous for Chatterjee inference. Set this to |
Available methods:
"pearson": Pearson correlation
"spearman": Spearman's
"kendall": Kendall's
"blomqvist": Blomqvist's
"hoeffding": Hoeffding's
"chatterjee": Chatterjee's
Partial matching of method names is enabled.
This implementation of Hoeffding's does not support tied
observations; test results are invalid when ties are present. It supports
only the two-sided alternative. The natural one-sided alternative for
Chatterjee's is "greater".
Chatterjee's measures the dependence of y on x. Analytic
inference with unequal weights requires a continuous response and assumes
that weights are fixed or depend only on x. It is unavailable when the
response is discrete or tied and weights are unequal.
A one-row data frame containing the estimate, transformed test statistic, p-value, effective sample size, method, and alternative.
x <- rnorm(100) y <- rpois(100, 1) w <- runif(100) indep_test(x, y, method = "kendall") # unweighted indep_test(x, y, method = "kendall", weights = w) # weightedx <- rnorm(100) y <- rpois(100, 1) w <- runif(100) indep_test(x, y, method = "kendall") # unweighted indep_test(x, y, method = "kendall", weights = w) # weighted
For observations without ties, the weighted rank of among
with weights is
Thus, multiplying every weight by the same positive constant does not change
the ranks, and unit weights reproduce ordinary ranks. Tied values are
handled according to ties_method.
rank_wtd(x, weights = numeric(), ties_method = "average")rank_wtd(x, weights = numeric(), ties_method = "average")
x |
a numeric vector. |
weights |
an optional vector of nonnegative weights with the same
length as |
ties_method |
how to treat ties; one of |
a vector of ranks.
x <- rnorm(100) w <- rexp(100) rank(x) rank_wtd(x, w)x <- rnorm(100) w <- rexp(100) rank(x) rank_wtd(x, w)
Computes a (possibly weighted) dependence measure between x and y if
these are vectors. If either argument is a matrix, the measures between all
corresponding columns are computed.
wdm( x, y = NULL, method = "pearson", weights = NULL, remove_missing = TRUE, seeds = NULL )wdm( x, y = NULL, method = "pearson", weights = NULL, remove_missing = TRUE, seeds = NULL )
x |
a numeric vector, matrix or data frame. |
y |
|
method |
the dependence measure; see Details for possible values. |
weights |
an optional vector of weights for the observations. |
remove_missing |
if |
seeds |
an optional integer vector used to break predictor ties for Chatterjee's xi. The default uses a fixed, reproducible ordering. |
Available methods:
"pearson": Pearson correlation
"spearman": Spearman's
"kendall": Kendall's
"blomqvist": Blomqvist's
"hoeffding": Hoeffding's
"chatterjee": Chatterjee's
Partial matching of method names is enabled.
Spearman's and Kendall's are corrected for ties if
there are any.
This implementation of Hoeffding's does not support tied
observations; estimates are invalid when ties are present.
Chatterjee's measures the dependence of y on x and is
generally asymmetric. Consequently, wdm(x, method = "chatterjee") need
not return a symmetric matrix.
A numeric scalar when both inputs are vectors or one-column objects; otherwise, a matrix containing the dependence measure for every pair of columns.
## dependence between two vectors x <- rnorm(100) y <- rpois(100, 1) w <- runif(100) wdm(x, y, method = "kendall") # unweighted wdm(x, y, method = "kendall", weights = w) # weighted ## dependence in a matrix x <- matrix(rnorm(100 * 3), 100, 3) wdm(x, method = "spearman") # unweighted wdm(x, method = "spearman", weights = w) # weighted ## dependence between columns of two matrices y <- matrix(rnorm(100 * 2), 100, 2) wdm(x, y, method = "hoeffding") # unweighted wdm(x, y, method = "hoeffding", weights = w) # weighted## dependence between two vectors x <- rnorm(100) y <- rpois(100, 1) w <- runif(100) wdm(x, y, method = "kendall") # unweighted wdm(x, y, method = "kendall", weights = w) # weighted ## dependence in a matrix x <- matrix(rnorm(100 * 3), 100, 3) wdm(x, method = "spearman") # unweighted wdm(x, method = "spearman", weights = w) # weighted ## dependence between columns of two matrices y <- matrix(rnorm(100 * 2), 100, 2) wdm(x, y, method = "hoeffding") # unweighted wdm(x, y, method = "hoeffding", weights = w) # weighted