# Spearman’s Correlation

The correlation between two variables, ${\displaystyle x'}$ and ${\displaystyle y'}$ is:

${\displaystyle r={\frac {\sum _{i=1}^{n}w_{i}(x_{i}-{\bar {x}})(y_{i}-{\bar {y}})}{{\sqrt {\sum _{i=1}^{n}w_{i}(x_{i}-{\bar {x}})^{2}}}{\sqrt {\sum _{i=1}^{n}w_{i}(y_{i}-{\bar {y}})^{2}}}}}}$

where:

${\displaystyle x=rank(x')}$ and ${\displaystyle y=rank(y')}$ where ties are replaced by their means,
${\displaystyle {\bar {x}}}$ and ${\displaystyle {\bar {y}}}$ are their means, respectively,
${\displaystyle w_{i}}$ is the Calibrated Weight for the ${\displaystyle i}$th of ${\displaystyle n}$ observations
${\displaystyle p\approx \Pr(t_{\sum _{i=1}^{n}w_{i}-2}\geq r{\sqrt {\frac {\sum _{i=1}^{n}w_{i}-2}{1-r^{2}}}})}$

Note: a bug existed in versions of Q prior to Q5.0.2, caused by Spearman ranks being calculated without omitting the cases with missing values in any of the two input variables. The impact of this bug should be minimal and proportional to the amount of missing values in the data set. We have observed that the bug typically resulted in a difference in the reported Spearman correlation at the 4th decimal place compared to the correct value. As a result, is unlikely that this bug would have affected Spearman correlation significance test results and any inferences made from them.