IB Maths Help logoIB Maths Help

Spearman's rank correlation coefficient

Rank the data and find Spearman's rank correlation coefficient with the exact key presses for the TI-84 Plus CE, Casio fx-CG50, Casio fx-CG100 and TI-Nspire CX, plus what to write in the exam.

Used inAI SLAI HL

Spearman's rank correlation coefficient, rsr_s, is the ordinary correlation coefficient rr of the ranks. Rank each variable from smallest to largest, using the mean rank for tied values. Enter the two sets of ranks in two lists and run linear regression on those lists. The rr value on the screen is rsr_s. The calculator has no separate Spearman command.

Example

Eight students record the number of hours xx they spent revising and their test mark yy.
xx: 12, 5, 9, 15, 7, 11, 3, 8
yy: 64, 50, 71, 80, 58, 62, 41, 66
Find Spearman's rank correlation coefficient. Give your answer to 3 significant figures.

xy48121620406080

Rank each variable from smallest to largest. The ranks of xx are 7, 2, 5, 8, 3, 6, 1, 4 and the ranks of yy are 5, 2, 7, 8, 3, 4, 1, 6. Linear regression on these two lists gives rs=0.810r_s = 0.810, a strong positive relationship: students who revised more tended to score higher.

Choose your calculator

How to find Spearman's rank correlation coefficient on a TI-84 Plus CE

Rank the data, then linear regression on the ranks

Rank each variable by hand first, as in Ranking the data. Then press stat and choose 1:Edit.... Type the xx values in L1 and the yy values in L2, pressing enter after each. Type the rank of each xx value in L3 and the rank of each yy value in L4, in the same order as the data.

L1    L2    L3    L4
 12   64    7    5
  5   50    2    2
  9   71    5    7
 15   80    8    8
  7   58    3    3
 11   62    6    4
  3   41    1    1
  8   66    4    6

The correlation coefficient is only shown when diagnostics are on. Press mode, use ▼ to move to STAT DIAGNOSTICS, press ▶ to highlight ON and press enter. Press 2nd mode (QUIT) to leave the screen.

STAT DIAGNOSTICS:
OFF  [ON]

Press stat, press ▶ to reach CALC and choose 4:LinReg(ax+b). With the Stat Wizards on, a screen asks for each value: set Xlist to L3 (2nd 3) and Ylist to L4 (2nd 4), leave FreqList and Store RegEQ empty, and choose Calculate. If the wizards are off, type LinReg(ax+b) L3,L4 and press enter.

LinReg(ax+b)
Xlist:L3
Ylist:L4
FreqList:
Store RegEQ:
Calculate

The result shows a, b, r² and r. Because the two lists hold ranks, r is Spearman's coefficient.

rs=0.810r_s = 0.810 to 3 significant figures.

LinReg
y=ax+b
a=0.8095238
b=0.8571429
r²=0.6553288
r=0.8095238

Read r from the rank lists, not from L1 and L2. The same command on the raw data gives Pearson's r, which is a different number.

How to find Spearman's rank correlation coefficient on a Casio fx-CG50

Rank the data, then linear regression on the ranks

Rank each variable by hand first, as in Ranking the data. Press MENU and choose Statistics. In List 1 type the xx values and in List 2 the yy values, pressing EXE after each. In List 3 type the rank of each xx value and in List 4 the rank of each yy value, in the same order as the data.

List1    List2    List3    List4
 12   64    7    5
  5   50    2    2
  9   71    5    7
 15   80    8    8
  7   58    3    3
 11   62    6    4
  3   41    1    1
  8   66    4    6

Tell the calculator which lists to use. Press F2 (CALC), then F6 (SET). Set 2Var XList to List 3 and 2Var YList to List 4, then press EXIT.

2Var XList:List3
2Var YList:List4
2Var Freq:1

Press F2 (CALC), then F3 (REG), then F1 (X), then F1 (ax+b). The result shows a, b, r, r² and MSe. Because the two lists hold ranks, r is Spearman's coefficient.

rs=0.810r_s = 0.810 to 3 significant figures.

Linear Reg(ax+b)
a =0.8095238
b =0.8571429
r =0.8095238
r²=0.6553288

The lists named in 2Var XList and 2Var YList must both hold ranks. If they are still List 1 and List 2, you get Pearson's r from the raw data instead.

How to find Spearman's rank correlation coefficient on a Casio fx-CG100

Rank the data, then linear regression on the ranks

Rank each variable by hand first, as in Ranking the data. Press HOME and choose Statistics. In the List Editor tab, type the xx values in List 1 and the yy values in List 2, pressing EXE after each. In List 3 type the rank of each xx value and in List 4 the rank of each yy value, in the same order as the data.

List1    List2    List3    List4
 12   64    7    5
  5   50    2    2
  9   71    5    7
 15   80    8    8
  7   58    3    3
 11   62    6    4
  3   41    1    1
  8   66    4    6

Press ▶ to open the Setup tab. Highlight the first line, press OK and choose Calculate Summary Statistics.

Setup
Calculate Summary Statistics

Highlight the second line and press OK. From the menu choose Linear Regression (ax+b). Highlight 2Var XList, press OK, enter 3 for List 3 and press OK. Highlight 2Var YList, press OK, enter 4 for List 4 and press OK.

Linear Regression(ax+b)
2Var XList:List3
2Var YList:List4

Choose Execute and press OK. The Results tab shows a, b, r, r² and MSe. Because the two lists hold ranks, r is Spearman's coefficient.

rs=0.810r_s = 0.810 to 3 significant figures.

a =0.8095238
b =0.8571429
r =0.8095238
r²=0.6553288

The regression menu also offers Linear Regression (a+bx). It gives the same r, so either item works for Spearman's coefficient.

How to find Spearman's rank correlation coefficient on a TI-Nspire CX

Rank the data, then linear regression on the ranks

Rank each variable by hand first, as in Ranking the data. Press home and choose Lists & Spreadsheet. Type the xx values down column A and the yy values down column B, pressing enter after each. Type the rank of each xx value down column C and the rank of each yy value down column D, in the same order as the data.

A    B    C    D
 12   64    7    5
  5   50    2    2
  9   71    5    7
 15   80    8    8
  7   58    3    3
 11   62    6    4
  3   41    1    1
  8   66    4    6

Press menu → Statistics → Stat Calculations → Linear Regression (mx+b). In the box, set X List to c[] and Y List to d[], and set 1st Result to e[]. Move between the fields with tab, then press enter on OK.

Linear Regression (mx+b)
X List:c[]
Y List:d[]
1st Result:e[]

Two new columns appear, with the names of the results and their values. Read r. Because the two lists hold ranks, r is Spearman's coefficient.

rs=0.810r_s = 0.810 to 3 significant figures.

m   0.8095238
b   0.8571429
r²  0.6553288
r   0.8095238

Use the columns that hold the ranks, here c[] and d[]. The results stay linked to the data, so if you correct a rank the coefficient updates.

Sources. Key presses follow the manufacturers' documentation: the TI-84 Plus CE eGuide, the TI-Nspire eGuide, the Casio fx-CG50 Software User's Guide (version 3.30) and the Casio fx-CG100 online manual.

What to write in the exam

  • Show the ranks. Write a table of the ranks of xx and yy before using the calculator. The ranks are part of the method, and an error in them is easy to follow through.
  • Write rsr_s and its value. For example rs=0.810r_s = 0.810. Do not write the key presses or the words linear regression as working.
  • Give 3 significant figures unless the question says otherwise, and keep the full calculator value for later parts instead of re-typing a rounded one.
  • Interpret the value. A value of rsr_s near 1 means that as one variable increases the other tends to increase; near −1-1 means that as one increases the other tends to decrease; near 0 means no consistent pattern. Describe it in the context of the question.
  • Check which papers allow a calculator. In AI SL and AI HL a calculator is allowed on every paper (check your syllabus).

Ranking the data

In the example the ranks are:

xxyyrank of xxrank of yy
126475
55022
97157
158088
75833
116264
34111
86646

Checking with the formula

When there are no tied ranks, rs=1−6∑d2n(n2−1)r_s = 1 - \dfrac{6\sum d^2}{n(n^2-1)}, where dd is the difference between the two ranks of each item. In the example ∑d2=16\sum d^2 = 16 and n=8n = 8, so rs=1−6×168×63=0.810r_s = 1 - \dfrac{6 \times 16}{8 \times 63} = 0.810, the same as the calculator. With tied ranks the formula is only approximate, so use the calculator value. The related guide on linear regression covers Pearson's rr for raw data.

Error messages and what to do

CalculatorMessageUsual causeWhat to try
TI-84 Plus CEERR:DIMENSION MISMATCHThe two lists have different numbers of values, for example a rank missing from L4.Check that L3 and L4 each have one rank for every data pair.
TI-84 Plus CEERR:STATThe lists are not suitable for a statistics calculation, for example fewer than two data points.Check that Xlist and Ylist name the filled rank lists.
Casio fx-CG50Dimension ERRORThe two lists have different numbers of values.Check that List 3 and List 4 each have one rank for every data pair.
Casio fx-CG100Dimension ERRORThe two lists have different numbers of values.Make the number of ranks in List 3 and List 4 the same.
TI-Nspire CXDimension mismatchThe two columns have different numbers of values.Check that the X List and Y List columns each have one rank for every data pair.

Common mistakes

  • Running the regression on the raw data. That gives Pearson's rr. Spearman's coefficient comes from the lists of ranks.
  • Mixing up the pairs. Each rank must stay in the same row as the item it belongs to. Ranks typed in a different order change the answer.
  • Ranking one variable high to low and the other low to high. Use the same direction for both, or the sign of rsr_s comes out wrong.
  • Ignoring ties. Tied values need the mean of their ranks, not the next whole numbers.
  • The correlation coefficient not showing. On the TI-84 Plus CE the r value appears only when STAT DIAGNOSTICS is on.

Try it yourself

Real questions from the IB Maths Help question bank. Type your answer and press Mark it: the worked solution and mark scheme then appear. Enter the ranks in two lists and use your calculator for the coefficient.

Practise with your calculator

Choose your course to see the practice sets that use this skill. You can also try practice mode or browse every GDC guide.

Quick questions

Does my calculator have a Spearman button?

No. Rank each variable, enter the two lists of ranks, and run linear regression on them. The r value is Spearman's rank correlation coefficient. The command is LinReg(ax+b) on the TI-84 Plus CE, the REG menu on the Casio calculators, and Linear Regression (mx+b) on the TI-Nspire.

How do I rank the data?

Give the smallest value rank 1 and the largest rank n, separately for each variable. Where values are tied, give each the mean of the ranks they would have taken. Keep each pair in the same row.

Why is my answer different from the one in the question?

Check that the regression used the rank lists and not the raw data, that the ranks are in the same order as the pairs, and that tied values have mean ranks. Also check the lists have the same number of values.

Do I write the regression in my exam working?

No. Show the table of ranks, then write the value of r_s and what it means in context. Examiners look for the ranks and the value, not the key presses.