Sub topic 5
The Interquartile Range
This chapter assumes that you can order a data set and find its median. You should also be comfortable with subtraction and interpreting fractions, decimals, and percents.
The interquartile range, or IQR, measures the spread of the middle half of an ordered data set. It is calculated from the first quartile and third quartile:
\[ \text{IQR}=Q3-Q1 \]
Here, \(Q1\) is the first quartile, and \(Q3\) is the third quartile. The median is \(Q_2\).
Finding the IQR
Start by ordering the data from least to greatest. Find the median, then split the data into a lower half and an upper half. If the data set has an odd number of values, leave the overall median out of both halves.
For example:
\[ 3,\ 5,\ 7,\ 8,\ 12,\ 13,\ 14,\ 18,\ 21 \]
The median is 12. The lower half is \(3,5,7,8\), and the upper half is \(13,14,18,21\).
- \(Q_1\) is the median of the lower half: \((5+7)/2=6\)
- \(Q_3\) is the median of the upper half: \((14+18)/2=16\)
- \(\text{IQR}=16-6=10\)
The IQR is 10. This means the middle 50% of the data extends across 10 units.
| Quantity | Meaning | Value in the example |
|---|---|---|
| \(Q_1\) | Boundary below the middle half | 6 |
| \(Q_2\) | Median of the entire data set | 12 |
| \(Q_3\) | Boundary above the middle half | 16 |
| IQR | Width of the middle half | 10 |
def median(values):
n = len(values)
middle = n // 2
if n % 2 == 1:
return values[middle]
return (values[middle - 1] + values[middle]) / 2
data = [3, 5, 7, 8, 12, 13, 14, 18, 21]
ordered = sorted(data)
middle = len(ordered) // 2
lower = ordered[:middle]
upper = ordered[middle + len(ordered) % 2:]
q1 = median(lower)
q3 = median(upper)
print(q3 - q1) # 10.0IQR Versus Range
The range is the maximum value minus the minimum value:
\[ \text{range}=\text{maximum}-\text{minimum} \]
For the example, the range is \(21-3=18\), while the IQR is 10.
The range uses only two values, so one unusually large or small value can change it greatly. The IQR ignores the lowest quarter and highest quarter of the data. It therefore gives a more stable measure of typical spread.
A larger IQR means that the middle half is more spread out. A smaller IQR means that the middle half is more tightly grouped. However, comparing IQRs is most useful when the data sets use the same units.
Using the IQR to Compare Data Sets
Suppose two classes have the same median test score. If Class A has an IQR of 6 and Class B has an IQR of 14, the middle scores in Class B are more variable. Class A's middle 50% is more concentrated around its median.
An IQR does not tell you the exact minimum or maximum. Two data sets can have the same IQR but very different ranges. On a boxplot, the IQR is represented by the length of the box, from \(Q1\) to \(Q3\).
Exercise
An ordered data set has Q1 = 18 and Q3 = 31. What is its IQR, and what does that value measure?
Show answer
The IQR is 31 - 18 = 13. It measures the spread of the middle 50% of the data.