简体   繁体   中英

Weighted Spearman rank correlation coefficient in R

This post provides a function for weighted Pearson correlation in R, ie function(x, y, weights) . Is a corollary available for the Spearman rank correlation coefficient?

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}

equation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM