Computes a matrix of weighted correlations between the columns of x and the columns of y. This can be Pearson, Spearman or Kendall correlation.

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

Arguments

x

a data frame of numeric vectors

y

an optional data frame of numeric vectors. Default is NULL, which means that correlations between the columns of x are computed.

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 matrix of correlations

Author

Nicolas Robette

See also

Examples

data(Movies)
weighted.cor2(Movies[,c("Budget", "Critics", "BoxOffice")], weights = rep(c(.8,1.2), 500))
#>                Budget     Critics  BoxOffice
#> Budget     1.00000000 -0.09755667 0.60973789
#> Critics   -0.09755667  1.00000000 0.05410962
#> BoxOffice  0.60973789  0.05410962 1.00000000