Computes a (possibly weighted) dependence measure between x and y if these are vectors. If x and y are matrices then the measure between the columns of x and the columns of y are computed.

wdm(x, y = NULL, method = "pearson", weights = NULL, remove_missing = TRUE)

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 (pairswise) incomplete observations are removed; if FALSE, the function throws an error if there are incomplete observations.

Details

Available methods:

  • "pearson": Pearson correlation

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

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

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

  • "hoeffding": Hoeffding's \(D\) Partial matching of method names is enabled.

Spearman's \(\rho\) and Kendall's \(\tau\) are corrected for ties if there are any.

Examples

##  dependence between two vectors
x <- rnorm(100)
y <- rpois(100, 1)  # all but Hoeffding's D can handle ties
w <- runif(100)
wdm(x, y, method = "kendall")               # unweighted
#> [1] 0.02331856
wdm(x, y, method = "kendall", weights = w)  # weighted
#> [1] -0.04052879

##  dependence in a matrix
x <- matrix(rnorm(100 * 3), 100, 3)
wdm(x, method = "spearman")               # unweighted
#>              [,1]         [,2]        [,3]
#> [1,]  1.000000000  0.008676868 -0.04549655
#> [2,]  0.008676868  1.000000000 -0.03840384
#> [3,] -0.045496550 -0.038403840  1.00000000
wdm(x, method = "spearman", weights = w)  # weighted
#>            [,1]        [,2]        [,3]
#> [1,] 1.00000000  0.02177004  0.02048581
#> [2,] 0.02177004  1.00000000 -0.01489218
#> [3,] 0.02048581 -0.01489218  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.002378469  0.0025429314
#> [2,] -0.001035590  0.0005252796
#> [3,]  0.005232169 -0.0035272380
wdm(x, y, method = "hoeffding", weights = w)  # weighted
#>              [,1]          [,2]
#> [1,]  0.007900614 -0.0001424806
#> [2,] -0.006867154 -0.0039366282
#> [3,]  0.007082112 -0.0032729170