Package 'wdm'

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, and Hoeffding's D; see, e.g., Nelsen (2006) <doi:10.1007/0-387-28678-0> and Hollander et al. (2015, ISBN:9780470387375).
Authors: Thomas Nagler [aut, cre]
Maintainer: Thomas Nagler <[email protected]>
License: MIT + file LICENSE
Version: 0.2.4
Built: 2024-11-15 05:08:03 UTC
Source: https://github.com/tnagler/wdm-r

Help Index


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, and Hoeffding's D; see, e.g., Nelsen (2006) <doi:10.1007/0-387-28678-0> and Hollander et al. (2015, ISBN:9780470387375).

Details

The DESCRIPTION file: This package was not yet installed at build time.


Independence Tests for Weighted Dependence Measures

Description

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.

Usage

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

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 (pairswise) 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.

Details

Available methods:

  • "pearson": Pearson correlation

  • "spearman": Spearman's ρ\rho

  • "kendall": Kendall's τ\tau

  • "blomqvist": Blomqvist's β\beta

  • "hoeffding": Hoeffding's DD

Partial matching of method names is enabled. All methods except "hoeffding" work with discrete variables.

Examples

x <- rnorm(100)
y <- rpois(100, 1)  # all but Hoeffding's D can handle ties
w <- runif(100)

indep_test(x, y, method = "kendall")               # unweighted
indep_test(x, y, method = "kendall", weights = w)  # weighted

Computing weighted ranks

Description

The weighted rank of XiX_i among X1,,XnX_1, \dots, X_n with weights w1,,wnw_1, \dots, w_n is defined as

1nj=1nwi1[XjXi].\frac 1 n \sum_{j = 1}^n w_i 1[X_j \le X_i].

Usage

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

Arguments

x

a numeric vector.

weights

a vector of weights (same length as x).

ties_method

Indicates how to treat ties; same as in R, see https://stat.ethz.ch/R-manual/R-devel/library/base/html/rank.html.

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 x and y are matrices then the measure between the columns of x and the columns of y are computed.

Usage

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