Module 29 of 47Lesson 1 of 7 · Hypothesis tests 1 · Ranking data & Spearman’s rank correlation
1
Spearman's rank & hypothesis testing · Essential understanding 1

Ranking data & Spearman's rank correlation

IB AI SL 4.10with Prof. Kitso
💻 Using the TI-Nspire CX Student Software on a laptop
  • The screens in these notes are drawn exactly as the Student Software shows them. The keypad on the left of the software works like the handheld — click its keys with the mouse.
  • menu: click menu on the on-screen keypad (or Documents Toolbox ▸ 🔧). The menu numbers and letters are the same as in these notes.
  • enter = Enter  ·  tab = Tab (next box)  ·  esc = Esc  ·  del = Backspace.
  • Powers: type ^ (Shift+6), the power, then press → to come back down before typing more. x² = ^2 then →.
  • Fraction: type /  ·  √: type sqrt(  ·  π: type pi  ·  eˣ: type exp(  ·  store: type :=. For EE (×10ⁿ) and i, click them on the keypad.
  • New page: Ctrl+I (or the Insert menu)  ·  change page: Ctrl+← / Ctrl+→  ·  graph entry line: Ctrl+G  ·  var: Ctrl+L.
  • Radian / Degree: click Settings in the status bar at the bottom of the window. The mode (RAD or DEG) shows in the top bar.
  • IB exam mode (Press-to-Test): everything in these notes works on the non-CAS TI-Nspire with the IB exam settings. In exam mode there are no dot-product, cross-product, unit-vector or eigenvalue keys and no Diff Eq graphs — the notes show the allowed way (type the components, use polyRoots on the characteristic equation, do Euler steps on a Calculator page).
  • If you type nDeriv(, the software shows it as centralDiff( — it is the same command.
The big idea: Spearman's coefficient rs measures how well two variables move in the same order (or in opposite orders). We do not use the raw numbers: we swap them for ranks (1st, 2nd, 3rd…) and then find the correlation of the ranks.
By the end of this lesson you can:
  • rank a list of numbers, including tied values
  • find rs with your GDC from two lists of ranks
  • interpret rs for strength and direction
  • check rs by hand with the d² formula when there are no ties
🧑🏾 Imagine this…
Two judges taste six cakes at the Maun school fete. Judge Neo gives marks out of 100 and Judge Lesedi gives marks out of 10, so you cannot compare the marks directly. But you can ask a simpler question: do they put the cakes in the same order? If both say “cake C is best, cake A is second best…”, they agree. Ranks throw away the size of the marks and keep only the order.
Rank
the position of a value when the data is put in order. Smallest = 1, next smallest = 2, and so on. (You may also give the largest rank 1. Just use the same direction for both variables.)
Tied values
two or more equal values. They share the average of the ranks they would have taken.
Monotonic
always going the same way: as x increases, y never goes down (increasing) or never goes up (decreasing). It does not need to be a straight line.
Spearman's rank correlation coefficient rₛ
the correlation of the ranks of x and the ranks of y. It measures how strong a monotonic relationship is. −1 ≤ rs ≤ 1.
★ Finding rₛ: the method
  • Step 1. Rank the x-values (1 = smallest). Step 2. Rank the y-values separately in the same direction.
  • Tied values: give each the average of the ranks they cover. Example: two values tied for 3rd and 4th both get rank 3.5. The next value gets rank 5.
  • Step 3. Put the two lists of ranks into your GDC and do a linear regression. The value of r you read off is rs.
  • rs = +1: the ranks match perfectly. rs = −1: the ranks are exactly reversed. rs near 0: no monotonic relationship.
⚠️ Watch out
  • Rank x and y separately. Never rank the pairs together.
  • Use the same direction for both lists (both smallest = 1, or both largest = 1). If you reverse only one, your answer changes sign.
  • After ranking, check: the ranks must add up to . For n = 8 that is 36. Tied ranks must still give the same total.
💡 The d² formula (no ties only)
If there are no tied values, you can also use , where d is the difference between the two ranks of each item. This gives the same answer as the GDC. With ties it is only approximate, so in the exam always use the GDC method. You do not need to memorise it; it is a handy check.
🧪 Try it yourselfCheck your ranking
Rank each list with the smallest value as rank 1.

Worked examples

Example 1.1Ranking data with no ties
Seven runners at a Gaborone club had these 400 m times (seconds): 14.2, 12.8, 15.6, 13.1, 12.5, 14.9, 13.7. Rank the times with the fastest (smallest) time as rank 1.
🧠 Think it through
  1. Put the times in order from smallest to largest.
  2. The smallest time gets rank 1, the next gets rank 2, and so on.
  3. Write the ranks back in the original order of the list (not in sorted order).
  4. Check the total: for n = 7 the ranks must add to .
✍️ By hand
Sorted: 12.5 (1), 12.8 (2), 13.1 (3), 13.7 (4), 14.2 (5), 14.9 (6), 15.6 (7)
Original order 14.2, 12.8, 15.6, 13.1, 12.5, 14.9, 13.7 ranks 5, 2, 7, 3, 1, 6, 4
Check: ✓
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the times in column A (name it time).
  2. Read down the list and pick out the smallest, then the next smallest, and so on. For a short list, ranking by hand is quickest in the exam.
1.1*DocRAD◆Atime14.212.815.613.112.514.913.7Brank5273164CD1234567A114.2
✅ Answer Ranks (in the original order): 5, 2, 7, 3, 1, 6, 4.
The TI-Nspire CX II has no rank command, so you rank by hand. Exam questions keep n small for this reason.
Example 1.2Ranking data with ties
Eight students wrote a quiz marked out of 20: 12, 15, 9, 15, 18, 12, 15, 7. Rank the marks, smallest = 1, using average ranks for ties.
🧠 Think it through
  1. Sort the marks: 7, 9, 12, 12, 15, 15, 15, 18.
  2. Give ranks 1 to 8 to the sorted list.
  3. Two 12s would take ranks 3 and 4. Average = 3.5 each.
  4. Three 15s would take ranks 5, 6 and 7. Average = 6 each.
✍️ By hand
7 1,   9 2,   12, 12 ,   15, 15, 15 ,   18 8
Original order 12, 15, 9, 15, 18, 12, 15, 7 3.5, 6, 2, 6, 8, 3.5, 6, 1
Check: ✓
🔢 On your TI-Nspire CX II
  1. Use the calculator to check the total of the ranks: type sum({3.5,6,2,6,8,3.5,6,1}) enter ↵💻 Enter. It must equal 36.
    📍 Where to find it on the TI-Nspire
    sum( is in menu💻 click menu on keypad▸6: Statistics▸3: List Math▸5: Sum of Elements
1.1*DocRADsum({3.5,6,2,6,8,3.5,6,1})368·9236
Same total: the ranks are right
✅ Answer Ranks: 3.5, 6, 2, 6, 8, 3.5, 6, 1.
Notice there is no rank 3 or 4, and no rank 5 or 7. The tied values used them up.
Example 1.3Spearman's coefficient with the GDC (no ties)
Kagiso asks 8 friends how many hours per week they study, and records their latest test mark.
Hours356810121415
Mark4145435862607570
  1. (a) Rank both variables, smallest = 1.
  2. (b) Find Spearman's rank correlation coefficient.
  3. (c) Describe the relationship.
🧠 Think it through
  1. Hours are already in order: ranks 1 to 8.
  2. Rank the marks: 41→1, 43→2, 45→3, 58→4, 60→5, 62→6, 70→7, 75→8. Write them in the original order.
  3. Enter the two rank lists in the GDC and do a linear regression.
  4. The value of r is rs.
✍️ By hand
Hours ranks: 1, 2, 3, 4, 5, 6, 7, 8
Mark ranks: 1, 3, 2, 4, 6, 5, 8, 7
Check by hand: , so and
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the two ranked lists. Name column A rh and column B rm (same row = same item).
  2. Check that each column shows the ranks you wrote by hand.
    1.1*DocRAD◆Arh12345678Brm13246587CD12345678A11
  3. Add a Calculator page: ctrl💻 Ctrl doc ▾💻 File menu then 1 (Add Calculator).
  4. Go to menu💻 click menu on keypad▸6: Statistics▸1: Stat Calculations▸3: Linear Regression (mx+b) and press enter ↵💻 Enter. Set X List = rh, Y List = rm. Press enter ↵💻 Enter.
    1.1*DocRADLinear Regression (mx+b)X List:rhY List:rmSave RegEqn to:f1Frequency List:1Category List:Include Categories:OKCancel
  5. Read r. Because the lists hold ranks, this r is rs. Ignore m and b.
    1.1*DocRADLinRegMxrh,rm,1:CopyVarstat.RegEqn,f1:stat.results"Title""Linear Regression (mx+b)""RegEqn""m·x+b""m"0.928571"b"0.321429"r²"0.862245"r"0.928571"Resid""{…}"
    This r is the Spearman coefficient rₛ, because the lists hold RANKS
✅ Answer (a) Hours: 1,2,3,4,5,6,7,8. Marks: 1,3,2,4,6,5,8,7. (b) rs = 0.929. (c) A strong positive monotonic relationship: students who study more hours tend to get higher marks.
Do not write “study causes marks”. Correlation only says the two variables move together.
Example 1.4Spearman's coefficient with tied ranks
A school in Francistown records, for 9 students, the daily hours of screen time (x) and hours of sleep (y).
Screen time2.54165.535.574.5
Sleep8.57.5966.5875.57
  1. (a) Rank each variable, smallest = 1.
  2. (b) Find rs and interpret it in context.
🧠 Think it through
  1. Screen time has a tie: 5.5 appears twice (ranks 6 and 7, so 6.5 each).
  2. Sleep has a tie: 7 appears twice (ranks 4 and 5, so 4.5 each).
  3. Rank the sleep values: 5.5→1, 6→2, 6.5→3, 7 and 7→4.5, 7.5→6, 8→7, 8.5→8, 9→9.
  4. Enter the ranks and do the regression.
✍️ By hand
Screen-time ranks: 2, 4, 1, 8, 6.5, 3, 6.5, 9, 5   (total 45 ✓)
Sleep ranks: 8, 6, 9, 2, 3, 7, 4.5, 1, 4.5   (total 45 ✓)
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the two ranked lists. Name column A rsc and column B rsl (same row = same item).
  2. Check that each column shows the ranks you wrote by hand.
    1.1*DocRAD◆Arsc24186.536.59Brsl8692374.51CD12345678A12
  3. Add a Calculator page: ctrl💻 Ctrl doc ▾💻 File menu then 1 (Add Calculator).
  4. Go to menu💻 click menu on keypad▸6: Statistics▸1: Stat Calculations▸3: Linear Regression (mx+b) and press enter ↵💻 Enter. Set X List = rsc, Y List = rsl. Press enter ↵💻 Enter.
    1.1*DocRADLinear Regression (mx+b)X List:rscY List:rslSave RegEqn to:f1Frequency List:1Category List:Include Categories:OKCancel
  5. Read r. Because the lists hold ranks, this r is rs. Ignore m and b.
    1.1*DocRADLinRegMxrsc,rsl,1:CopyVarstat.RegEqn,f1:stat.results"Title""Linear Regression (mx+b)""RegEqn""m·x+b""m"-0.987395"b"9.93697"r²"0.974949"r"-0.987395"Resid""{…}"
    This r is the Spearman coefficient rₛ, because the lists hold RANKS
✅ Answer (a) Screen time: 2, 4, 1, 8, 6.5, 3, 6.5, 9, 5. Sleep: 8, 6, 9, 2, 3, 7, 4.5, 1, 4.5. (b) rs = −0.987: a very strong negative monotonic relationship. Students with more screen time tend to sleep fewer hours.
⚠️ With these ties the d² formula would give −0.971, which is NOT the same. With tied ranks always use the GDC.
Example 1.5Two judges: comparing rankings
Two judges rank six dishes at a cooking contest in Kasane (1 = best).
DishABCDEF
Judge 1123456
Judge 2214365
  1. (a) Find the Spearman's rank correlation coefficient.
  2. (b) What does your answer say about the judges?
🧠 Think it through
  1. The data is already in ranks, so skip the ranking step.
  2. Enter the two rows as lists and do the regression.
  3. Each dish differs by 1 place, so the judges nearly agree.
✍️ By hand
, so , and
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the two ranked lists. Name column A j1 and column B j2 (same row = same item).
  2. Check that each column shows the ranks you wrote by hand.
    1.1*DocRAD◆Aj1123456Bj2214365CD123456A11
  3. Add a Calculator page: ctrl💻 Ctrl doc ▾💻 File menu then 1 (Add Calculator).
  4. Go to menu💻 click menu on keypad▸6: Statistics▸1: Stat Calculations▸3: Linear Regression (mx+b) and press enter ↵💻 Enter. Set X List = j1, Y List = j2. Press enter ↵💻 Enter.
    1.1*DocRADLinear Regression (mx+b)X List:j1Y List:j2Save RegEqn to:f1Frequency List:1Category List:Include Categories:OKCancel
  5. Read r. Because the lists hold ranks, this r is rs. Ignore m and b.
    1.1*DocRADLinRegMxj1,j2,1:CopyVarstat.RegEqn,f1:stat.results"Title""Linear Regression (mx+b)""RegEqn""m·x+b""m"0.828571"b"0.6"r²"0.686531"r"0.828571"Resid""{…}"
    This r is the Spearman coefficient rₛ, because the lists hold RANKS
✅ Answer (a) rs = 0.829. (b) A strong positive correlation: the judges mostly agree on the order of the dishes, although they swap neighbouring pairs (A and B, C and D, E and F).
rs compares the orders only. The judges might give very different marks and still have rs = 1.

Challenge questions

⭐ Challenge 1.6Two judges, raw marksPaper 1 style
Five contestants in a talent show were given marks by two judges.
Contestant12345
Judge X7864719085
Judge Y7066738892
  1. (a) Write down the ranks given by each judge (smallest mark = 1).
  2. (b) Calculate Spearman's rank correlation coefficient.
  3. (c) Comment on the level of agreement between the judges.
✏️ Try it on paper and on your calculator first. Then check.
Show the full solution
🧠 Think it through
  1. Rank each judge's marks separately.
  2. Enter the rank lists and do a linear regression, or use d².
  3. Give strength and direction in words.
✍️ By hand
Judge X: 3, 1, 2, 5, 4. Judge Y: 2, 1, 3, 4, 5.   , so
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the two ranked lists. Name column A jx and column B jy (same row = same item).
  2. Check that each column shows the ranks you wrote by hand.
    1.1*DocRAD◆Ajx31254Bjy21345CD12345A13
  3. Add a Calculator page: ctrl💻 Ctrl doc ▾💻 File menu then 1 (Add Calculator).
  4. Go to menu💻 click menu on keypad▸6: Statistics▸1: Stat Calculations▸3: Linear Regression (mx+b) and press enter ↵💻 Enter. Set X List = jx, Y List = jy. Press enter ↵💻 Enter.
    1.1*DocRADLinear Regression (mx+b)X List:jxY List:jySave RegEqn to:f1Frequency List:1Category List:Include Categories:OKCancel
  5. Read r. Because the lists hold ranks, this r is rs. Ignore m and b.
    1.1*DocRADLinRegMxjx,jy,1:CopyVarstat.RegEqn,f1:stat.results"Title""Linear Regression (mx+b)""RegEqn""m·x+b""m"0.8"b"0.6"r²"0.64"r"0.8"Resid""{…}"
    This r is the Spearman coefficient rₛ, because the lists hold RANKS
✅ Answer (a) Judge X: 3, 1, 2, 5, 4. Judge Y: 2, 1, 3, 4, 5. (b) rs = 0.8. (c) Strong positive correlation: the judges mostly agree on the order of the contestants.
⭐ Challenge 1.7Temperature and hot-drink salesPaper 2 style
A kiosk owner in Francistown records the maximum temperature (°C) and the number of hot drinks sold on 9 days.
Temp172430213733243927
Drinks645852664049553547
  1. (a) Rank the temperatures and the number of drinks (smallest = 1).
  2. (b) Find Spearman's rank correlation coefficient.
  3. (c) Interpret your answer in context.
  4. (d) Find Pearson's product-moment coefficient r for the original data. Comment on how it compares with rs.
  5. (e) Explain why the d² formula should not be used for this data.
✏️ Try it on paper and on your calculator first. Then check.
Show the full solution
🧠 Think it through
  1. Temperature has a tie (24 twice, ranks 3 and 4 → 3.5). Drinks has no ties.
  2. Do the regression on the rank lists for rs, then on the raw lists for r.
  3. Both are strongly negative. The formula needs no ties.
✍️ By hand
Temp ranks: 1, 3.5, 6, 2, 8, 7, 3.5, 9, 5. Drinks ranks: 8, 7, 5, 9, 2, 4, 6, 1, 3.
🔢 On your TI-Nspire CX II
  1. On 1.1 Lists & Spreadsheet type the two ranked lists. Name column A rt and column B rd (same row = same item).
  2. Check that each column shows the ranks you wrote by hand.
    1.1*DocRAD◆Art13.562873.59Brd87592461CD12345678A11
  3. Add a Calculator page: ctrl💻 Ctrl doc ▾💻 File menu then 1 (Add Calculator).
  4. Go to menu💻 click menu on keypad▸6: Statistics▸1: Stat Calculations▸3: Linear Regression (mx+b) and press enter ↵💻 Enter. Set X List = rt, Y List = rd. Press enter ↵💻 Enter.
    1.1*DocRADLinear Regression (mx+b)X List:rtY List:rdSave RegEqn to:f1Frequency List:1Category List:Include Categories:OKCancel
  5. Read r. Because the lists hold ranks, this r is rs. Ignore m and b.
    1.1*DocRADLinRegMxrt,rd,1:CopyVarstat.RegEqn,f1:stat.results"Title""Linear Regression (mx+b)""RegEqn""m·x+b""m"-0.932773"b"9.66387"r²"0.862815"r"-0.928878"Resid""{…}"
    This r is the Spearman coefficient rₛ, because the lists hold RANKS
  6. For part (d) repeat the regression with the raw lists temp and drinks and read r = −0.939.
✅ Answer (a) Temperature: 1, 3.5, 6, 2, 8, 7, 3.5, 9, 5. Drinks: 8, 7, 5, 9, 2, 4, 6, 1, 3. (b) rs = −0.929. (c) A strong negative monotonic relationship: the hotter the day, the fewer hot drinks tend to be sold. (d) r = −0.939. Both coefficients tell the same story (strong negative), so the relationship is close to linear. (e) The temperature data contains a tie, and the d² formula is only valid when there are no tied ranks.
Next: Lesson 2 · Spearman or Pearson?