This post provides a function for weighted Pearson correlation in R, i.e. function(x, y, weights)
. Is a corollary available for the Spearman rank correlation coefficient?
Asked
Active
Viewed 2,167 times
1

Community
- 1
- 1

Max Ghenis
- 14,783
- 16
- 84
- 132
-
you mean Spearman with weight? – Colonel Beauvel Sep 04 '15 at 07:04
-
I'd like the coefficient to consider a third vector of observation-level weights, which I'd provide. – Max Ghenis Sep 04 '15 at 14:36
1 Answers
0
Spearman's rank correlation coefficient r_s is calculated in the same way as Pearson's product moment correlation coefficient, except that ordinal rather than interval data are used. However, there is a way to calculate r_p using weights:
LaTeX:
\begin{align}
\bar{x} & = \frac{\sum_{i=1}^n{w_i x_i}}{\sum_{i=1}^n{w_i}} \quad
\bar{y} = \frac{\sum_{i=1}^n{w_i y_i}}{\sum_{i=1}^n{w_i}} \\
s_{x,y} & = \frac{\sum_{i=1}^n{w_i (x_i - \bar{x}_i) (y_i - \bar{y}_i)}}{\sum_{i=1}^n{w_i}} \quad
s_x = \frac{\sum_{i=1}^n{w_i (x_i - \bar{x})}}{w_i} \quad
s_y = \frac{\sum_{i=1}^n{w_i (y_i - \bar{y})}}{w_i} \\
r(x,y,w) & = \frac{s_{x,y}}{\sqrt{s_x s_y}}
\end{align}

Max Ghenis
- 14,783
- 16
- 84
- 132
-
I think that in the weighted variance S_x, the term (x_i - x_bar) should be squared. Similar in S_y – hector Feb 12 '19 at 04:40