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.007244855
wdm(x, y, method = "kendall", weights = w) # weighted
#> [1] 0.006367486
## dependence in a matrix x <- matrix(rnorm(100 * 3), 100, 3) wdm(x, method = "spearman") # unweighted
#> [,1] [,2] [,3] #> [1,] 1.0000000 -0.1084668 0.1078428 #> [2,] -0.1084668 1.0000000 0.0780318 #> [3,] 0.1078428 0.0780318 1.0000000
wdm(x, method = "spearman", weights = w) # weighted
#> [,1] [,2] [,3] #> [1,] 1.00000000 -0.09497972 0.1067206 #> [2,] -0.09497972 1.00000000 0.1292720 #> [3,] 0.10672057 0.12927201 1.0000000
## dependence between columns of two matrices y <- matrix(rnorm(100 * 2), 100, 2) wdm(x, y, method = "hoeffding") # unweighted
#> [,1] [,2] #> [1,] 0.002148337 0.006288094 #> [2,] -0.002800238 -0.001640325 #> [3,] 0.007099477 0.003868609
wdm(x, y, method = "hoeffding", weights = w) # weighted
#> [,1] [,2] #> [1,] 0.002481089 0.006531391 #> [2,] -0.004807590 0.001435961 #> [3,] 0.003446762 0.001962314