Computes the weighted correlation between two distributions. This can be Pearson, Spearman or Kendall correlation.

weighted.cor(x, y, weights = NULL, method = "pearson", na.rm = FALSE)

Arguments

x

numeric vector

y

numeric vector

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

method

a character string indicating which correlation coefficient is to be computed. One of "pearson" (default), "kendall", or "spearman".

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. Default is FALSE.

Value

a length-one numeric vector

Author

Nicolas Robette

Examples

data(Movies)
weighted.cor(Movies$Critics, Movies$BoxOffice, weights = rep(c(.8,1.2), 500))
#> [1] 0.05410962
weighted.cor(Movies$Critics, Movies$BoxOffice, weights = rep(c(.8,1.2), 500), method = "spearman")
#> [1] 0.009101708