Skip to content
Tutorials Center
My learning

Topics

Lesson 12 of 37 ยท Averages and Spread

Range, Quartiles and the Interquartile Range

Measure spread with the range, quartiles and interquartile range. Learn the median-of-halves method, percentiles, and why software may give slightly different quartiles.

Two classes can have the same mean score but very different stories: in one, everyone scored close to 70; in the other, half scored 40 and half scored 100. An average alone hides this. Spread (also called dispersion or variability) measures how far the values are scattered. This lesson covers the range and the quartile-based measures.

The range

range = largest value โˆ’ smallest value

It is quick, but it depends only on the two extreme values, so one outlier can inflate it. For 2, 4, 4, 5, 7, 8, 9, 10, 12, 15 the range is 15 โˆ’ 2 = 13.

Quartiles

If the median splits sorted data into two halves, the quartiles split it into four equal-sized parts.

  • Q1 (lower quartile): the median of the lower half. About 25% of values lie below it.
  • Q2: the median itself.
  • Q3 (upper quartile): the median of the upper half. About 75% of values lie below it.

Method used in this lesson (the "median of halves" method):

  1. Sort the data and find the median.
  2. Split into a lower half and an upper half. If n is odd, leave the median out of both halves.
  3. Q1 is the median of the lower half; Q3 is the median of the upper half.

Data: 2, 4, 4, 5, 7, 8, 9, 10, 12, 15 (n = 10).

  • Median = (7 + 8) / 2 = 7.5.
  • Lower half: 2, 4, 4, 5, 7, so Q1 = 4.
  • Upper half: 8, 9, 10, 12, 15, so Q3 = 10.

The interquartile range

IQR = Q3 โˆ’ Q1

For the example above, IQR = 10 โˆ’ 4 = 6. The IQR is the range of the middle 50% of the data. It ignores the extreme quarter at each end, so it is resistant to outliers, unlike the range. Use it together with the median.

flowchart LR
  A["Minimum"] --- B["Q1"] --- C["Median Q2"] --- D["Q3"] --- E["Maximum"]

The five points that split sorted data into quarters. The IQR is the distance from Q1 to Q3.

Python Quartiles by the median-of-halves method

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the odd-sized data set the median (6) is left out of both halves, giving a lower half 1, 3, 4 and an upper half 8, 9, 12.

There are several accepted ways to define quartiles. School syllabuses usually use the median-of-halves method above, but software often uses interpolation, so your calculator, spreadsheet or Python may give slightly different values for small data sets. For large data sets the differences vanish.

Python Software quartiles can differ

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Compare these results with Q1 = 4 and Q3 = 10 from the median-of-halves method. Which agree and which do not? None of them is "wrong"; they are different conventions.

Percentiles

A percentile generalizes quartiles. The 90th percentile is the value below which about 90% of the data fall. Q1 is the 25th percentile, the median is the 50th and Q3 is the 75th. Exam results and growth charts use percentiles.

Comparing spread

Measure Uses Affected by outliers?
Range Max and min only Strongly
IQR Middle 50% Hardly
Standard deviation (next lesson) Every value Strongly
Python IQR resists an outlier

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The range jumps from 8 to 80, but the IQR changes only modestly.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the range of 12, 7, 19, 3, 10?

    19 โˆ’ 3 = 16.
  2. 2. For the sorted data 3, 5, 6, 8, 9, 12, 14, 15, what is the median-of-halves Q1?

    n = 8, so the lower half is 3, 5, 6, 8 and its median is (5 + 6) / 2 = 5.5.
  3. 3. Q1 = 20 and Q3 = 38. What is the IQR?

    IQR = Q3 โˆ’ Q1 = 38 โˆ’ 20 = 18.
  4. 4. Why is the IQR often preferred to the range?

    The IQR covers only the middle 50% of the data, so outliers hardly change it.

Summary

  • Range = max โˆ’ min; simple but fragile.
  • Quartiles Q1, Q2, Q3 split sorted data into quarters; IQR = Q3 โˆ’ Q1 is the spread of the middle half.
  • Different methods give slightly different quartiles; know which one your course uses.
  • Percentiles are a general version of quartiles.

Next: Variance and Standard Deviation