1

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?

Community
  • 1
  • 1
Max Ghenis
  • 14,783
  • 16
  • 84
  • 132

1 Answers1

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: equation

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}

equation

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