Skip to contents

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.

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.

Details

Available methods:

  • "pearson": Pearson correlation

  • "spearman": Spearman's \(\rho\)

  • "kendall": Kendall's \(\tau\)

  • "blomqvist": Blomqvist's \(\beta\)

  • "hoeffding": Hoeffding's \(D\)

  • "chatterjee": Chatterjee's \(\xi\) Partial matching of method names is enabled.

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.

Examples

##  dependence between two vectors
x <- rnorm(100)
y <- rpois(100, 1)
w <- runif(100)
wdm(x, y, method = "kendall")               # unweighted
#> [1] -0.1295267
wdm(x, y, method = "kendall", weights = w)  # weighted
#> [1] -0.07076238

##  dependence in a matrix
x <- matrix(rnorm(100 * 3), 100, 3)
wdm(x, method = "spearman")               # unweighted
#>            [,1]       [,2]       [,3]
#> [1,]  1.0000000  0.1892589 -0.1260126
#> [2,]  0.1892589  1.0000000 -0.2395560
#> [3,] -0.1260126 -0.2395560  1.0000000
wdm(x, method = "spearman", weights = w)  # weighted
#>             [,1]       [,2]        [,3]
#> [1,]  1.00000000  0.1763072 -0.09894217
#> [2,]  0.17630718  1.0000000 -0.19502270
#> [3,] -0.09894217 -0.1950227  1.00000000

##  dependence between columns of two matrices
y <- matrix(rnorm(100 * 2), 100, 2)
wdm(x, y, method = "hoeffding")               # unweighted
#>               [,1]         [,2]
#> [1,] -0.0008920469  0.007046148
#> [2,] -0.0014812415  0.003563858
#> [3,] -0.0043310897 -0.001534677
wdm(x, y, method = "hoeffding", weights = w)  # weighted
#>               [,1]        [,2]
#> [1,] -0.0030186240 0.003734748
#> [2,] -0.0007278424 0.003522086
#> [3,] -0.0062132311 0.002368683