induwara.lk
induwara.lkStatistics · Data science

Spearman's Rank Correlation Calculator

Paste two columns of numbers to get Spearman's ρ (rho), a significance test (t-statistic and two-tailed p-value), a plain-English strength reading, and the full rank working — with proper mid-rank tie correction. Matched to scipy.stats.spearmanr, runs entirely in your browser — no signup, nothing uploaded.

By Induwara AshinsanaUpdated Jun 10, 2026
Spearman's rank correlation

Numbers separated by commas, spaces, or new lines. Paste two Excel columns here to fill both.

Must have the same count as X — each X needs a matching Y.

Examples
Decimals
Spearman's ρ
0.9000
Range −1 to 1 · n = 9
ρ² (shared rank variance)
0.8100
81.0% of rank variance shared
Σd² (rank differences²)
12
No ties in either column
Interpretation
Very strong positive

Significance test

t-statistic
5.4628
Degrees of freedom
7
p-value (two-tailed)
0.0009
At α = 0.05Significant

Small sample (n = 9): the t-based p-value is approximate. For a definitive result on few points, use an exact permutation test or a Spearman critical-value table.

Cross-check. ρ from Pearson-on-ranks is 0.9000; the independent raw-score formula on the same ranks [n·Σrₓr_y − Σrₓ·Σr_y] / √(…) gives 0.9000. They reconcile, as they must — and both match scipy.stats.spearmanr.

Rank working table

#xᵢyᵢrank xᵢrank yᵢd
135.000030.00007524
223.000033.000057-24
347.000045.00009811
417.000023.00004400
510.00008.00003211
643.000049.000089-11
79.000012.000023-11
86.00004.00001100
928.000031.00006600
Σd²12
ρ = 1 − 6·Σd² / (n(n²−1)) = 1 − 6·12 / (9·(9²−1)) = 0.9000
n = 9 · Σd² = 12 · no ties

Method: rank each column (average method for ties), then ρ = Pearson correlation of the ranks; significance via t = ρ√((n−2)/(1−ρ²)) with df = n−2 — Spearman (1904) / NIST e-Handbook, matched to scipy.stats.spearmanr. Nothing leaves this page.

How it works

Spearman's rank correlation coefficient ρ (rho) measures the strength and direction of the monotonic relationship between two paired variables — whether they tend to move in the same order, even if the relationship is curved rather than a straight line. It runs from −1 (a perfect decreasing order), through 0 (no monotonic association), to +1 (a perfect increasing order). It is the rank-based companion to Pearson's r and was introduced by Charles Spearman in 1904.

The key idea is to replace each value by its rank within its own column, then correlate the ranks. Because ranks ignore the exact spacing of values, ρ is robust to outliers and to non-linear (but still monotonic) shapes. The tool computes it in four steps:

  1. Parse and pair. Each box is tokenised on commas, spaces, and new lines, coerced to numbers, and checked: both columns must be the same length with at least 3 pairs. Non-numeric tokens are named in a clear error rather than silently dropped.
  2. Rank each variable. Values are ranked 1..n using the average (mid-rank) method: a tied group is given the mean of the ranks it spans, so two values tied for positions 4 and 5 each get 4.5. This is the tie handling scipy.stats.spearmanr uses.
  3. Compute ρ. With no ties, the classic shortcut applies:ρ = 1 − 6·Σdᵢ² / (n·(n² − 1)),  dᵢ = rank(xᵢ) − rank(yᵢ)When values tie, that shortcut is no longer exact, so ρ is computed as the Pearson correlation of the two rank vectors — Σ(rₓ−r̄ₓ)(r_y−r̄_y) / √(Σ(rₓ−r̄ₓ)²·Σ(r_y−r̄_y)²). The two forms coincide exactly when there are no ties, so this tool always uses the Pearson-on-ranks route for correctness and shows the simple form as well when no ties are present.
  4. Significance. Under the null hypothesis that the true rank correlation is zero, t = ρ√((n−2)/(1−ρ²)) follows a Student-t distribution with df = n−2. The two-tailed p-value is the regularized incomplete beta function I_x(df/2, 1/2) at x = df/(df+t²), the same identity SciPy uses. For small samples this t approximation is rough; an exact permutation test is preferable, and the tool says so.

As a credibility check the calculator recomputes ρ a second way — the raw-score formula applied to the same rank vectors — and confirms both routes agree to floating-point precision, matching scipy.stats.spearmanr. A strong ρ is evidence of monotonic association, never of causation on its own. For straight-line relationships on raw values, use the Pearson correlation calculator instead.

Worked examples

No ties (n = 5) — X = [10, 20, 30, 40, 50], Y = [15, 10, 25, 30, 28]

  1. Ranks of X: [1, 2, 3, 4, 5]; ranks of Y: [2, 1, 3, 5, 4]
  2. d = [−1, 1, 0, −1, 1] → d² = [1, 1, 0, 1, 1], Σd² = 4
  3. ρ = 1 − 6·4 / (5·(25−1)) = 1 − 24/120 = 0.80 (strong positive monotonic)
  4. Pearson-on-ranks of the same vectors = 0.80 → the two routes agree
  5. t = 0.80·√(3/0.36) = 2.3094, df = 3, p = 0.1041 → not significant at α=0.05

With ties (n = 6) — X = [1, 2, 2, 3, 4, 5], Y = [2, 2, 3, 4, 4, 5]

  1. Ranks of X (avg): [1, 2.5, 2.5, 4, 5, 6]; ranks of Y (avg): [1.5, 1.5, 3, 4.5, 4.5, 6]
  2. Ties present → ρ = Pearson correlation of the rank vectors (mean rₓ = r_y = 3.5)
  3. Σ(rₓ−3.5)(r_y−3.5) = 5+2+0.5+0.5+1.5+6.25 = 15.75
  4. Σ(rₓ−3.5)² = 17; Σ(r_y−3.5)² = 16.5
  5. ρ = 15.75 / √(17·16.5) = 15.75/√280.5 = 0.9404 (very strong positive monotonic)
  6. t = 5.5308, df = 4, p = 0.0052 → significant; the simple 1−6Σd² form would be wrong here

Monotonic but curved (n = 5) — X = [1, 2, 3, 4, 5], Y = [1, 4, 9, 16, 25] (Y = X²)

  1. Y rises whenever X rises, so ranks of Y = [1, 2, 3, 4, 5] = ranks of X
  2. d = [0, 0, 0, 0, 0] → Σd² = 0
  3. ρ = 1 − 0 = 1 (perfect positive monotonic)
  4. Pearson r on the raw values would be about 0.98 — below 1, because the curve is not a straight line
  5. This is the headline reason to use Spearman for ordered, non-linear data

Frequently asked questions

Sources & references

The formulas on this page were last cross-checked against these sources on 2026-06-10. Spearman's ρ is a stable mathematical definition, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against SciPy.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.