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={1, 2, 3}y={3, 2, 1}x = \left\{ 1,\ 2,\ 3 \right\} \quad y = \left\{ 3,\ 2,\ 1 \right\}

ρ=−1\displaystyle \rho = -1

ρ squared

1\displaystyle 1
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, 3ry: 3, 2, 1\begin{gathered} r_x:\ 1,\ 2,\ 3 \\ r_y:\ 3,\ 2,\ 1 \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=2, Syy=2, Sxy=−2⇒ρ=−22×2=−1S_{xx} = 2,\ S_{yy} = 2,\ S_{xy} = -2 \Rightarrow \rho = \frac{-2}{\sqrt{2 \times 2}} = -1
  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=8ρ=1−6×83×(32−1)=−1\begin{gathered} \sum d^2 = 8 \\ \rho = 1 - \frac{6 \times 8}{3 \times \left(3^2 - 1\right)} = -1 \end{gathered}
  4. Result

    So ρ=−1\rho = -1, a strong negative monotonic relationship.

Worked examples