Spearman Rank Correlation Calculator

Enter your x and y values to measure how well their ranks agree.

Numbers separated by commas, spaces or new lines.

One y for each x, in the same order.

Try

Result

You enteredx={10, 20, 30, 40, 50}y={1, 3, 2, 5, 4}x = \left\{ 10,\ 20,\ 30,\ 40,\ 50 \right\} \quad y = \left\{ 1,\ 3,\ 2,\ 5,\ 4 \right\}

ρ=0.8\displaystyle \rho = 0.8

ρ squared

0.64\displaystyle 0.64
Show the work
  1. Rank the data

    Spearman's coefficient measures how well the ranks of x and y agree, so replace every value by its rank, 1 for the smallest. A value tied with others takes the mean of the ranks they share. Here no values tie. Ties matter: the shortcut ρ=1−6∑d2n(n2−1)\rho = 1 - \frac{6\sum d^2}{n(n^2 - 1)} is exact only when the ranks are exactly 1 to nn, which a tie breaks, so the correlation is always found as Pearson's rr on the ranks.

    rx: 1, 2, 3, 4, 5ry: 1, 3, 2, 5, 4\begin{gathered} r_x:\ 1,\ 2,\ 3,\ 4,\ 5 \\ r_y:\ 1,\ 3,\ 2,\ 5,\ 4 \end{gathered}
  2. Pearson correlation of the ranks

    Treat the ranks as ordinary data: SxxS_{xx} and SyyS_{yy} measure the spread of the ranks and SxyS_{xy} how the two sets of ranks move together.

    Using ρ=SxySxx Syy\rho = \frac{S_{xy}}{\sqrt{S_{xx}\,S_{yy}}}

    Sxx=10, Syy=10, Sxy=8⇒ρ=810×10=0.8S_{xx} = 10,\ S_{yy} = 10,\ S_{xy} = 8 \Rightarrow \rho = \frac{8}{\sqrt{10 \times 10}} = 0.8
  3. Spearman's shortcut formula

    With no ties, dd is the difference between each pair of ranks and the shortcut agrees with the result above.

    Using ρ=1−6∑d2n(n2−1)\rho = 1 - \frac{6\sum d^2}{n\left(n^2 - 1\right)}

    ∑d2=4ρ=1−6×45×(52−1)=0.8\begin{gathered} \sum d^2 = 4 \\ \rho = 1 - \frac{6 \times 4}{5 \times \left(5^2 - 1\right)} = 0.8 \end{gathered}
  4. Result

    So ρ=0.8\rho = 0.8, a strong positive monotonic relationship.

Worked examples