AI Glossary / Statistics and probability / Intermediate

Spearman rank correlation

Definition

Spearman rank correlation measures the strength and direction of a monotonic association between two variables using their ranks. It is commonly calculated as the Pearson correlation of the ranked observations, with tied values assigned average ranks. Its coefficient ranges from minus one to plus one when defined. A positive value indicates that larger values of one variable tend to accompany larger values of the other; a negative value indicates the opposite ordering. It does not measure causation or every possible form of dependence.

What it means

Ranking replaces original magnitudes with relative positions. This makes Spearman correlation useful when order matters more than exact spacing, including many ordinal measurements. A strongly curved but consistently increasing relationship can have a high Spearman correlation even when a straight line is not a good description. Conversely, a U-shaped relationship can be strongly structured while having a rank correlation near zero. The coefficient summarizes monotonic association, so a scatterplot or another suitable display remains important.

How it works

Pair the observations correctly, handle missing values according to a documented rule and rank each variable. Assign average ranks to ties, then calculate the ordinary correlation between the two rank vectors. With no ties, the shortcut is one minus six times the sum of squared rank differences divided by n times (n squared minus one). Use an inferential method appropriate to sample size and dependence. A permutation test requires an exchangeability justification; paired, clustered or time-dependent observations cannot always be freely rearranged.

Three practical examples

Example 1: A researcher compares two sets of ordinal ratings for the same items. Example 2: An AI team compares the ordering of systems under two evaluation metrics. Example 3: A service analyst studies whether longer waiting times tend to accompany lower satisfaction ranks. These applications preserve pairing and distinguish association from agreement. Two rating systems can rank items similarly while assigning very different absolute scores, so high rank correlation does not establish that their measurements are interchangeable.

Think of it this way

Think of comparing two race finishing orders rather than the runners' exact times. Similar ordering produces a positive rank association, even if one race is much slower overall. Reversing the order produces a negative association. The comparison tells you about relative placement, not how many seconds separate the runners or whether the two races measure precisely the same ability.

Worked example

Consider five paired observations whose x ranks are (1,2,3,4,5) and y ranks are (1,3,2,5,4). Their rank differences are (0,-1,1,-1,1), giving a squared-difference sum of four. The no-ties formula gives 1 minus 6 times 4 divided by 5 times 24 = 0.8. This is a positive sample rank association. For an illustrative exact permutation test under a null that makes all 120 pairings equally likely, sixteen permutations have an absolute coefficient at least 0.8. The two-sided absolute-statistic p-value is therefore 16/120 = 0.1333. A coefficient that looks large can still have substantial uncertainty with only five pairs. This exact calculation uses the stated permutation null; it is not a universal test of every possible zero-correlation hypothesis.

Illustrative case study

In this fictional case study, Alder Analytics compares two AI evaluation scorecards across a small group of systems. The rankings are fairly similar, but the team notices that several systems are nearly tied and that absolute score differences vary widely. Analysts report Spearman correlation with the number of paired systems and inspect disagreements individually. They avoid calling the scorecards equivalent or treating the strongest observed correlation as definitive evidence. A larger, prespecified comparison is planned before changing the evaluation process.

Common misconceptions and mistakes

Common mistakes include interpreting a zero coefficient as independence, using the no-ties shortcut without handling ties, and reading correlation as agreement. Ranking can reduce sensitivity to extreme magnitudes, but it does not make an analysis immune to unusual observations or selection bias. Constant input has no rank variation, so the correlation is undefined rather than zero. Testing many metric pairs and highlighting only the largest correlations also creates a selective reporting problem that ranking does not solve.

Business use

Businesses use rank correlation when comparing priorities, ordinal surveys or competing rankings. Report the direction, magnitude, sample size and tie handling, and consider whether monotonic association answers the business question. If absolute calibration matters, additional analyses are necessary. For small datasets, inspect an appropriate exact or resampling method instead of relying automatically on a large-sample approximation. SciPy's documentation specifically cautions about the accuracy of its asymptotic p-value for smaller samples; this is an implementation warning, not a reason to ignore study design.

People also ask

Does Spearman correlation require a linear relationship?

No; it summarizes monotonic ordering.

Does a value of 0.8 mean 80 percent accuracy?

No.

Can it be computed with ties?

Yes, using suitable ranks and inference.

Is a p-value the probability that the variables are unrelated?

No; it evaluates the statistic under a specified null model.

Can a constant variable have a valid Spearman correlation?

No, because its rank variance is zero.

Check your understanding

What is the squared-rank-difference sum in the example?

Answer: Four.

What coefficient does it produce?

Answer: 0.8.

Why is the exact illustrative p-value 0.1333?

Answer: Sixteen of 120 equally likely pairings are at least as extreme in absolute coefficient.

Does a high coefficient establish agreement in original units?

Answer: No; the calculation uses order rather than absolute score differences.

Learn next

Learn next how ties change rank vectors and why the convenient no-ties formula is not the general definition. Compare monotonic and nonmonotonic examples visually. Then study permutation assumptions, uncertainty estimation and the distinction between a useful ranking comparison and validation of an absolute measurement scale.

More in Statistics and probability

  • Sparse model - A sparse model is a model whose representation contains relatively few active or nonzero components compared with the available possibilities.
  • Sparsity-of-effects principle - The sparsity-of-effects principle is the working expectation that only a relatively small subset of the many possible effects in an experiment materially...
  • Spatial Regression - Spatial regression is a family of regression methods that explicitly represents geographical relationships, spatial dependence or spatial variation in the...
  • Special cause - A special cause is a source of process variation associated with a particular circumstance or change beyond the routine common-cause variation of the...
  • Specification limits - Specification limits are the numerical boundaries that define acceptable values for a specified characteristic of a product, service or process output.
  • Spectrum bias - Spectrum bias occurs when an evaluation's mix of cases does not adequately represent the range of cases relevant to its intended use, leading to a...

Sources

Sources: SciPy developers, spearmanr, https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html. This primary implementation reference defines the coefficient, constant-input limitation and inference cautions. The five-pair example is original; all 120 permutations were independently enumerated. The organisational case is fictional and does not represent measured performance of real evaluation systems.

Previous: Speaker verification Next: Special cause

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer