Change language

Learn to calculate by playing with Spearman correlation calculator

A short game to see where the result comes from. Pick a language and start; you can stop halfway and come back.

Loading the game…

← Back to Spearman correlation calculator

What you will practise

Rank correlation between two variables, which detects monotonic relationships even if they are not straight, with p value and confidence interval.

How it works

Each value is replaced by its rank (1 for the smallest, n for the largest; with ties, the average of the ranks they occupy) and Pearson’s correlation is computed between the ranks. The result runs from −1 to +1: +1 if whenever one variable rises the other always does, even along a curve.

The p value uses a Student’s t on n − 2 degrees of freedom, and the confidence interval uses Fisher’s z transformation with Bonett and Wright’s (2000) standard error, which is slightly larger than Pearson’s.

Formula

ρ = Pearson correlation between the ranks of X and the ranks of Y
t = ρ · √( (n − 2) / (1 − ρ²) ), df = n − 2
CI: z = atanh(ρ); SE = √( (1 + ρ²/2) / (n − 3) ); limits = tanh( z ± critical z · SE )
With ties: average rank of the tied positions

Worked example

Example 1. With repeated values.
With X = 1, 2, 2, 3, 4, 4, 4, 5, 6, 7 and Y = 2, 1, 3, 3, 5, 6, 4, 7, 8, 9 (there are ties), rho = .960 (95% CI .782 to .993), t(8) = 9.69, p < .001: a very strong positive monotonic relationship.

Example 2. An outlier.
With X = 1 to 10 and Y = 2, 3, …, 10 and 60, Pearson would give .644, but Spearman gives rho = 1: the relationship is perfectly monotonic, and the outlier does not count because only its position matters.

Example 3. A monotonic curve.
With y = x² for x = 1 to 10, the relationship is not a line but is always increasing: rho = 1.

How to play

First pick your language. Then work through the challenges one by one: each sets out a case with real numbers and, if you get stuck, you can ask for a hint. When you answer, you see whether you got it right and why. Progress is saved only in your browser, so you can stop halfway and carry on another day.