Package {wdm}


Title: Weighted Dependence Measures
Version: 0.3.0
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>.
Depends: R (≥ 3.2.0)
License: MIT + file LICENSE
Encoding: UTF-8
LinkingTo: Rcpp
Imports: Rcpp
URL: https://tnagler.github.io/wdm-r/, https://github.com/tnagler/wdm-r
BugReports: https://github.com/tnagler/wdm-r/issues
Suggests: testthat (≥ 3.0.0), Hmisc, copula, covr
Config/roxygen2/version: 8.0.0
Config/testthat/edition: 3
NeedsCompilation: yes
Packaged: 2026-08-31 16:08:22 UTC; n5
Author: Thomas Nagler [aut, cre]
Maintainer: Thomas Nagler <mail@tnagler.com>
Repository: CRAN
Date/Publication: 2026-08-31 22:10:02 UTC

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>.

Author(s)

Maintainer: Thomas Nagler mail@tnagler.com

Authors:

See Also

Useful links:


Independence Tests for Weighted Dependence Measures

Description

Computes a dependence measure and its asymptotic independence test for two numeric vectors.

Usage

indep_test(
  x,
  y,
  method = "pearson",
  weights = NULL,
  remove_missing = TRUE,
  alternative = "two-sided",
  seeds = NULL,
  y_continuous = TRUE
)

Arguments

x, y

numeric vectors of data values. x and y must have the same length.

method

the dependence measure; see Details for possible values.

weights

an optional vector of weights for the observations.

remove_missing

if TRUE, all pairwise incomplete observations are removed; if FALSE, the function throws an error if there are incomplete observations.

alternative

indicates the alternative hypothesis and must be one of "two-sided", "greater" or "less". You can specify just the initial letter. "greater" corresponds to positive association, "less" to negative association.

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 FALSE for a discrete response even if the sample contains no observed response ties.

Details

Available methods:

Partial matching of method names is enabled. This implementation of Hoeffding's D 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 \xi is "greater".

Chatterjee's \xi 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.

Value

A one-row data frame containing the estimate, transformed test statistic, p-value, effective sample size, method, and alternative.

Examples

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)  # weighted


Computing weighted ranks

Description

For observations without ties, the weighted rank of X_i among X_1, \dots, X_n with weights w_1, \dots, w_n is

\frac{n}{\sum_{k = 1}^n w_k} \sum_{j = 1}^n w_j 1[X_j \le X_i].

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.

Usage

rank_wtd(x, weights = numeric(), ties_method = "average")

Arguments

x

a numeric vector.

weights

an optional vector of nonnegative weights with the same length as x.

ties_method

how to treat ties; one of "average", "min", "first", or "random", as in rank().

Value

a vector of ranks.

Examples

x <- rnorm(100)
w <- rexp(100)
rank(x)
rank_wtd(x, w)

Weighted Dependence Measures

Description

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.

Usage

wdm(
  x,
  y = NULL,
  method = "pearson",
  weights = NULL,
  remove_missing = TRUE,
  seeds = 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. The default is equivalent to y = x (but more efficient).

method

the dependence measure; see Details for possible values.

weights

an optional vector of weights for the observations.

remove_missing

if TRUE, all pairwise incomplete observations are removed; if FALSE, the function throws an error if there are incomplete observations.

seeds

an optional integer vector used to break predictor ties for Chatterjee's xi. The default uses a fixed, reproducible ordering.

Details

Available methods:

Spearman's \rho and Kendall's \tau are corrected for ties if there are any. This implementation of Hoeffding's D does not support tied observations; estimates are invalid when ties are present. Chatterjee's \xi measures the dependence of y on x and is generally asymmetric. Consequently, wdm(x, method = "chatterjee") need not return a symmetric matrix.

Value

A numeric scalar when both inputs are vectors or one-column objects; otherwise, a matrix containing the dependence measure for every pair of columns.

Examples

##  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