Menu
Sign up Sign in

AI SL · 13.3

Statistics

13.3.8

Spearman's rank correlation and comparison with Pearson's r

13.3.8

Spearman's rank correlation and comparison with Pearson's r

Target: I can rank a list of values, giving tied values the mean of their ranks. (+3 more)

By the end of this section

Key points

Ranking

  • To rank a list, give the smallest value rank 1, the next smallest rank 2, and so on. Keep the ranks in the original order of the data.
  • Tied values share the mean of the ranks they occupy. Two values tied for 3rd and 4th place each get 3.5.
  • Negative values and decimals rank in the usual order: −4.5 is smaller than −1.2.
  • Check: the ranks of n values add up to \(n(n+1)/2\), also when there are ties.

Spearman's rank correlation coefficient

  • Rank both variables. Then \(r_s\) is Pearson's correlation coefficient of the two lists of ranks. Use the calculator for that step.
  • \(-1 \le r_s \le 1\). A value close to 1 or −1 is strong; a value near 0 is weak.
  • \(r_s\) measures how well the variables increase together (or decrease together), not whether the points lie on a line.
  • Say the direction, the strength and the context. Correlation is not causation.

Pearson or Spearman?

  • Pearson's r uses the actual values. It measures how close the points are to a straight line.
  • Spearman's \(r_s\) uses only the ranks. It is the better measure when the points rise (or fall) steadily along a curve.
  • \(r_s = 1\) or −1 for any perfectly increasing or decreasing relationship, even a curved one. \(r = 1\) or −1 only for a straight line.
  • One outlier changes Pearson's r a lot. It changes \(r_s\) much less, because the outlier is only one rank.

On the calculator

Ranking a list

Menu > Actions > Sort

  • Enter the data in a list or spreadsheet column.
  • Sort the values in order, or use the sorted order to read off the rank of each value.
  • Write the ranks back beside the original values, in the original order.
  • Where values tie, type the mean of their ranks.

Screenshot and video to come

The correlation of the ranks

  • Put the ranks of x in one list and the ranks of y in another.
  • Run the linear regression on the two lists and read r.
  • This r is Spearman's \(r_s\). Give it to 3 significant figures.

Screenshot and video to come

Pearson's r on the raw data

  • Use the same linear regression with the original values, not the ranks.
  • Compare r with \(r_s\): a large gap means the points are not close to a straight line, or there is an outlier.

Screenshot and video to come

Explore: Spearman's rank correlation

Drag a point on the top diagram, or change the numbers in the table. The ranks are worked out for you and drawn below, and Pearson's r and Spearman's rₛ are found side by side. Then add one extreme point.

xyRank of xRank of y

Pearson's r
Spearman's rₛ

Change a number in the table.

  1. Drag a point a little way without passing another point. Why does rₛ stay the same when r changes? Now drag it past a neighbour.
  2. Make two x values equal. What rank does each get? Do the ranks still add up to n(n + 1)/2?
  3. Press "Add an extreme point". Which of r and rₛ changes more? Look at the rank diagram: how far from the others is the new point?
  4. Press "Use a curve that always rises". Why is rₛ exactly 1 when r is not?

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
Ranking two lists, no ties

Eight members of a running club give their weekly training distance (km) and their time for a 10 km race (minutes). Calculate Spearman's rank correlation coefficient \(r_s\) between distance and time.

Distance (km)1225183022153528Time (min)6251584755604652
Working
  1. Rank distance

    Distance ranks: 1, 5, 3, 7, 4, 2, 8, 6

    Smallest value gets rank 1. List the ranks in the original order of the students.

  2. Rank time

    Time ranks: 8, 3, 6, 2, 5, 7, 1, 4

    Rank the second list the same way, smallest = 1.

  3. Correlation of the ranks

    From the calculator: \(r_s = −0.976\)

    Put the two lists of ranks into the calculator and find the correlation coefficient r.

  4. Say what it means

    \(r_s = −0.976\): a strong negative association. As weekly distance increases, race time tends to decrease. This does not show that one causes the other.

    Name the direction and the strength, and use the words of the question.

Video walkthrough coming
Tied values get the mean rank

Eight adults record their mean daily steps (thousands) and their resting heart rate (beats per minute). Calculate \(r_s\) and comment on the relationship.

Steps (thousands)4961268104Heart rate7466706272666475
Working
  1. Rank steps

    Steps in order: 4, 4, 6, 6, 8, 9, 10, 12. The two 4s take ranks 1 and 2, so each gets 1.5. The two 6s take ranks 3 and 4, so each gets 3.5. Steps ranks: 1.5, 6, 3.5, 8, 3.5, 5, 7, 1.5

    Tied values receive the mean of the ranks they occupy.

  2. Rank heart rate

    The two 66s take ranks 3 and 4, so each gets 3.5. Heart rate ranks: 7, 3.5, 5, 1, 6, 3.5, 2, 8

    Check that the ranks add to 36, the sum of 1 to 8.

  3. Correlation of the ranks

    From the calculator: \(r_s = −0.982\)

    Correlation coefficient of the two lists of ranks.

  4. Comment

    \(r_s = −0.982\): a strong negative association. As daily steps increases, resting heart rate tends to decrease. This does not show that one causes the other.

    Direction, strength, context.

Video walkthrough coming
Decimals and negative values

A house is heated for eight winter days. The table gives the mean outside temperature (°C) and the energy used (kWh). Calculate \(r_s\).

Temperature (°C)−4.52−1.26.80.5−3.14.49.3Energy (kWh)52.138.44530.241.749.534.927.6
Working
  1. Rank temperature

    Temperature ranks: 1, 5, 3, 7, 4, 2, 6, 8

    A negative value is smaller than a positive one: −4.5 is the smallest, so it has rank 1.

  2. Rank energy

    Energy ranks: 8, 4, 6, 2, 5, 7, 3, 1

    Decimals rank in the same way. Compare place by place.

  3. Correlation of the ranks

    From the calculator: \(r_s = −1\)

    The warmer the day, the less energy used: a negative association.

Video walkthrough coming
A curve: Pearson or Spearman?

A mug of tea cools. Its temperature T (°C) is measured every 5 minutes. t (min): 0, 5, 10, 15, 20, 25, 30, 35 T (°C): 92, 71, 58, 48, 41, 36, 33, 31 (a) Describe the scatter graph. (b) Calculate Pearson's r and Spearman's \(r_s\). (c) Which is the better measure of the association? Explain.

5101520253035402030405060708090100t (min)T (°C)
Working
  1. Describe

    The points fall from left to right along a curve that flattens out.

    The temperature always goes down as the time goes up, but not in a straight line.

  2. Pearson's r

    From the calculator, raw data: \(r = −0.943\)

    Pearson measures how close the points are to a straight line.

  3. Spearman's r_s

    Time ranks: 1, 2, 3, 4, 5, 6, 7, 8 Temperature ranks: 8, 7, 6, 5, 4, 3, 2, 1 From the calculator: \(r_s = −1\)

    Every increase in t comes with a decrease in T, so the ranks are exactly opposite.

  4. Compare

    \(r_s\) is the better measure here.

    The relationship is decreasing but not linear. \(r_s = -1\) shows it always decreases; \(r\) is further from \(-1\) only because the points curve.

Video walkthrough coming