Learn R Programming

descriptio (version 1.3)

weighted.cor: Weighted correlation

Description

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

Usage

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

Value

a length-one numeric vector

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.

Author

Nicolas Robette

See Also

weighted.sd, weighted.cor2

Examples

Run this code
data(Movies)
weighted.cor(Movies$Critics, Movies$BoxOffice, weights = rep(c(.8,1.2), 500))
weighted.cor(Movies$Critics, Movies$BoxOffice, weights = rep(c(.8,1.2), 500), method = "spearman")

Run the code above in your browser using DataLab