In this guide
← Maths AI guides

Statistics & probability · AI SL & HL

Spearman’s rank correlation

Measure monotonic association through ranks, handle tied values and distinguish rank correlation from a linear fit.

Course focus: AI SL & HL · First-assessment-2021 course. The sections distinguish the mathematical idea, the calculation and its interpretation.

Before you start: Paired data, ordering values and Pearson correlation.

Start with a small example

Build it from the beginning

Spearman correlation measures how consistently two orderings agree. Rank the observations in each variable first. Ties share the average of the rank positions they occupy; ignoring ties can change the result.

A first walkthrough

Rank the values 4, 7, 7, 10 from smallest to largest.

  1. The 4 occupies rank 1.
  2. The tied 7s occupy positions 2 and 3, so each receives 2.5.
  3. The 10 receives rank 4. The rank total remains 10.
Try the practice ladder after learning the methods ↓

The foundations behind the method

Understand what the symbols mean

A rank says where a value sits in an ordering, not how far it is from another value. This change of scale lets correlation focus on whether the two variables move consistently in the same or opposite order. Original pairing remains essential: sorting both columns independently would manufacture a perfect agreement.

How the ideas connect

Rank correlation is ordinary correlation on transformed data. This explains why its sign and range look familiar while its interpretation differs from a regression slope. Ties need average ranks because equal observations carry no internal order; a no-tie derivation cannot silently replace that information with distinct invented positions.

01

Start with the idea

Build your understanding

Ordering

Ranks discard gaps in original scale, so a large outlier changes order without dominating through its size alone.

Monotonic association

A curved but consistently increasing relationship can be strong in ranks even when a linear fit on original values is imperfect.

Compare the approaches

Choose by the information in the question, rather than the formula you recognise first.

Pearson coefficient

When it helpsUse for linear association on numerical values.

Check before using itInspect the scatter plot and possible outliers; a coefficient alone does not describe every shape.

Spearman coefficient

When it helpsUse for monotonic association or ordinal measurements.

Check before using itPreserve pairs and use average ranks for ties; constant ranks make correlation undefined.

Your method plan

  1. Maintain the paired rows and rank each variable.
  2. Handle ties before choosing the coefficient calculation.
  3. Interpret the observed monotonic pattern without a causal claim.
02

Learn the methods

Learn step by step

1. Rank an ordering, not a distance

Ranking replaces each measurement by its ordered position. The smallest receives rank 1 when ascending ranks are used. Differences between original measurement magnitudes are discarded; only their order remains. This makes rank correlation useful for ordinal data or monotonic trends that are not linear. Preserve the original pairing: a person’s x and y measurements must stay together even when separate rank lists are constructed.

2. Monotonic is broader than linear

A relationship is monotonic when larger inputs tend consistently toward larger outputs or consistently toward smaller outputs. It need not have a constant slope. Pearson correlation measures linear association in original values, while Spearman correlation measures linear association in their ranks. A perfect curved increasing relationship can have Spearman coefficient 1 without lying on a straight line. Neither coefficient establishes that one variable causes the other.

An increasing curve can be perfect in ranks

012345-10369xyVertex
  • y = (x − 2)² − 1
The parabola is increasing only to the right of its vertex and decreasing to the left. Rank correlation reflects monotonic order over the observed domain, so a sample drawn across both sides can behave very differently from a sample on one side.

3. Assign average ranks to ties

If several values occupy positions 2,3,4, give all of them rank 3, the average of those positions. Continue the next rank at 5 rather than 4. Do this separately for each variable. Ties contain genuine loss of ordering information, not a reason to break them arbitrarily by row order. The two ranked data lists still have equal length and retain their paired rows.

General rank definition

Why this formula works

Correlation depends on paired deviations from the respective means. Replacing each variable by its ranks preserves ordering while changing the measurement scale. Average ranks handle ties without inventing an ordering among equal values. The definition therefore works with ties when both rank lists have nonzero variation.

The formula

\(r_s=\operatorname{corr}(R_X,R_Y)\).

Quick example

Tied values at positions 2 and 3 both receive rank 2.5; use these average ranks in the ordinary correlation operation.

Worked example: Keep ties honest

The x values are 1,2,2,4 and their paired y values are 10,20,30,40.

  1. The x ranks are 1,2.5,2.5,4; the y ranks are 1,2,3,4.
  2. Both rank means are 2.5. The covariance numerator is 4.5.
  3. Squared-deviation totals are 4.5 for x and 5 for y.
  4. Thus \(r_s=4.5/\sqrt{4.5(5)}\approx0.948683\). Calculate correlation of average ranks rather than assuming the untied shortcut.

4. Calculate the coefficient appropriately

Spearman’s coefficient is Pearson correlation calculated on the two rank lists. Without ties, the shortcut \(1-6\sum d_i^2/[n(n^2-1)]\) is valid, where d is the difference in paired ranks. With ties, calculate Pearson correlation of average ranks or use a properly tie-corrected method. Applying the no-tie shortcut uncritically can give a different value. Keep a table of original pairs and both ranks so the calculation is auditable.

No-tie shortcut

Why this formula works

Without ties, both rank lists are permutations of the integers 1 through n. They have the same mean and known squared-deviation total. Expanding squared rank differences converts the Pearson rank covariance into this shortcut. Ties alter those squared-deviation totals, so its uncomplicated form no longer applies.

The formula

\(r_s=1-\frac{6\sum d_i^2}{n(n^2-1)}\), only without tied ranks.

Quick example

For n=4 and rank differences 0,−1,1,0, the squared-difference sum is 2 and \(r_s=1-12/60=0.8\).

Worked example: A four-pair calculation

For pairs (1,10), (2,30), (3,20), (4,40), find Spearman correlation.

  1. The x ranks are 1,2,3,4. The paired y ranks are 1,3,2,4.
  2. Differences are 0,−1,1,0, so the squared sum is 2.
  3. Without ties, \(r_s=1-6(2)/(4(16-1))=0.8\).
  4. There is a positive monotonic tendency in this tiny constructed sample; the coefficient alone is not a population or causal conclusion.
Worked example: Perfect decreasing ranks

Paired ranks are x:1,2,3,4 and y:4,3,2,1. Find Spearman correlation.

  1. Rank differences are −3,−1,1,3.
  2. Their squared total is 9+1+1+9=20.
  3. With no ties, \(r_s=1-6(20)/(4(16-1))=-1\).
  4. The ordering is perfectly decreasing. This rank conclusion does not require a particular original measurement scale or a causal interpretation.

5. Interpret direction and strength

The coefficient lies from −1 to 1 when both rank lists have nonzero variation. Positive indicates an increasing tendency, negative a decreasing one, and values near zero indicate little monotonic association. A U-shaped relationship may have low rank correlation despite a strong non-monotonic pattern. Terms such as strong and weak are context-dependent, so combine the coefficient with the scatter plot and sample size rather than using a universal cutoff.

6. Choose data and statements carefully

Rank correlation can reduce the influence of extreme magnitudes but is not immune to bad sampling, incorrect pairs or measurement problems. If one variable is constant, its ranks have zero variation and correlation is undefined. An association in a sample may require a separate statistical test before a population inference is justified. Describe the observed tendency and its context, and avoid converting a coefficient directly into a percentage of causal explanation.

Quick formula reference

For revision once you understand the methods above. Check the conditions before using a formula.

No-tie shortcut

\(r_s=1-\frac{6\sum d_i^2}{n(n^2-1)}\), only without tied ranks.

Return to the explanation →

General rank definition

\(r_s=\operatorname{corr}(R_X,R_Y)\).

Return to the explanation →

Learn to diagnose an error

Spot the mistake

The statement below is incorrect. Identify the missing condition or reasoning before opening the explanation.

Incorrect reasoning

Sort the x and y lists independently, then compare the first ranks, second ranks and so on.

Explain and repair the mistake

That destroys the original observational pairs and usually forces an artificial increasing rank match. Assign ranks separately but return each rank to its original paired row before calculating correlation.

03

Connect and apply

Put the ideas together

A more demanding application of this guide’s methods. This is a learning stage; any additional HL content is labelled separately.

Worked application

A perfect rank relationship can curve

Take x=1,2,3,4 and y=x². What is Spearman correlation?

  1. Both variables increase in exactly the same order.
  2. Both rank lists are 1,2,3,4.
  3. Every rank difference is zero, so Spearman coefficient is 1.
  4. The original values do not lie on a straight line; perfect rank association is not the same as perfect linear association.
Pause and explain

Would squaring preserve this conclusion if x included both negative and positive values?

Check your reasoning

Not necessarily. Squaring is not increasing over all real inputs; it decreases on negative inputs and increases on positive inputs. Check monotonicity over the actual data domain.

Common mistakes and how to avoid them

  • That destroys the original observational pairs and usually forces an artificial increasing rank match. Assign ranks separately but return each rank to its original paired row before calculating correlation.
  • Inspect the scatter plot and possible outliers; a coefficient alone does not describe every shape.
  • Preserve pairs and use average ranks for ties; constant ranks make correlation undefined.
04

Practise independently

Build confidence, then apply it

Try each question before opening its hint or solution. If a method is new, return to the walkthrough, then try again. These learning stages describe the practice sequence; additional HL content is labelled separately.

  1. 1

    Build confidence

    Rank 2, 5, 9, 12.

    Need a starting point?

    There are no ties.

    Show the worked solution
    1. The ranks are 1,2,3,4.
    2. Using the same direction for both variables is essential when calculating the correlation.
  2. 2

    Apply and explain

    Two variables have exactly reversed ranks with no ties. What is Spearman correlation?

    Need a starting point?

    Compare highest with lowest at every observation.

    Show the worked solution
    1. The association is perfectly decreasing in rank.
    2. The coefficient is -1; the original values need not lie on a straight line.
  3. 3

    Check your understanding

    With no ties, what does a squared rank-difference sum of zero imply?

    Show the worked solution

    Every paired rank agrees, giving Spearman coefficient 1. It indicates perfect increasing rank order, not necessarily a straight-line relationship between original measurements.

  4. 4

    Use the method

    Three equal values occupy ordered positions 4,5,6. What rank does each receive?

    Show the worked solution

    Each receives rank 5, the mean of 4,5,6. The next observation receives rank 7; the tie uses all three positions even though the same average is assigned.

Finished? Use the linked question bank below to practise selecting the method without a guide telling you which rule to use.

Using these methods in exam questions

AI Paper 1

GDC required

Short-response questions still need mathematical setup and interpretation. Choose the correct tool, enter the model or data carefully, and check units and rounding.

AI Paper 2

GDC required

Extended-response questions connect several steps. Keep intermediate values at full precision and explain how each result answers the context.

For this topic: Define the variable or events, write the probability statement or hypotheses, then calculate. Name the distribution and its parameters; interpret the result using the original population or context.

HL only · GDC required

Paper 3: build a connected argument

Both AA HL and AI HL Paper 3 contain two extended problem-solving questions. A question develops a theme, so keep useful earlier results, test small cases and explain any proposed general rule. A calculator pattern can suggest a result; your mathematical reasoning must support it.

  1. Identify what the first part establishes and record the conditions under which it holds.
  2. When a later part introduces a new definition or model, connect it to methods you already know rather than assuming a new formula must have been memorised.
  3. Check the conclusion against an earlier numerical case and explain its meaning or limitation.

For the first-assessment-2021 courses. IB assessment reference ↗

Find a specific method or formula

Now practise the method

If you opened this guide from a question, return to that tab and try the method without looking at the example. Your answer stays in the question tab.

Practise this subtopic →

Want a broader practice session? Explore IB Maths AI SL practice questions →Explore IB Maths AI HL practice questions →Try free IB Maths exam-style questions and worked solutions →

Original Arc Practice teaching notes for Maths AI. Core and HL sections are distinguished above. These notes follow the first-assessment-2021 course and are not an official IB publication or a complete syllabus checklist. IB course reference. Report a correction.