Unit 2, lesson 8

Percentiles, Quartiles and Box Plots

How percentiles and quartiles locate positions in ordered data, how the interquartile range, five-number summary, box plot and outlier fences are built, and how the median absolute deviation and trimmed mean resist extreme values.

  • Video 8
  • Center, Spread and Position

The last eight trips on a bus route arrived 11, 22, 33, 44, 55, 66, 77 and 2020 minutes late. The mean delay is 66 minutes, even though the two middle delays are 44 and 55 minutes, because one long delay pulls the mean upward. To compare routes fairly we want summaries that show where the bulk of the trips lies and how wide the middle half is, without letting a single trip dominate. This lesson builds such summaries from positions in the ordered data, draws them as a box plot, and adds two resistant measures, the median absolute deviation and the trimmed mean.

Key terms

Percentile

Definition For 0<p<1000 < p < 100, a ppth percentile is a value that splits a distribution so that pp percent of it lies below the value and 100−p100 - p percent lies above it. A quantile is the same idea with the fraction written between 00 and 11, so the 25th percentile is the 0.250.25 quantile, and the median is the 50th percentile. For a finite set of values, such as a sample, an exact split may be impossible, or a whole interval of values may give it. A sample percentile is therefore computed with a stated rule, and the rules in common use, which differ in how they interpolate between neighboring ordered values, can give different answers in small samples.

In plain words A percentile marks a position in the ordered data. About pp percent of the observations lie below it and the rest above it. In a large dataset the different rules usually agree closely, but in a small one they can disagree, so a reported percentile should come with the rule that produced it, especially when results from different software are compared.

Example In the eight delays, every value strictly between 22 and 33 minutes has two delays below it and six above it, an exact split of 25 percent and 75 percent. A rule that takes the midpoint gives 2.52.5 minutes, while the linear interpolation rule that many software packages use by default gives 2.752.75 minutes. Both are reasonable 25th percentiles, and neither is an arithmetic mistake.

Quartiles and interquartile range

Definition The quartiles Q1Q_1, Q2Q_2 and Q3Q_3 are the 25th, 50th and 75th percentiles, so they cut ordered data into four parts with about a quarter of the observations in each, and Q2Q_2 is the median. Like other sample percentiles they need a stated rule. This page uses the median-of-halves rule for n≥2n \ge 2 observations. Sort the data and find the median. The lower half consists of the observations before the median position and the upper half of those after it, and when nn is odd the single middle observation is left out of both halves. Then Q1Q_1 is the median of the lower half and Q3Q_3 is the median of the upper half. The interquartile range is

IQR=Q3−Q1,\text{IQR} = Q_3 - Q_1 ,

measured in the units of the data.

In plain words The quartiles bracket the middle half of the ordered data, and the IQR is the width of that middle half. It is a measure of spread built from positions near the middle. Under the median-of-halves rule, in a dataset of at least six values, moving the largest observation farther up or the smallest farther down leaves it unchanged.

Example For the eight delays the median is halfway between the fourth and fifth values, Q2=(4+5)/2=4.5Q_2 = (4 + 5)/2 = 4.5 minutes. The lower half 1,2,3,41, 2, 3, 4 has median Q1=2.5Q_1 = 2.5, and the upper half 5,6,7,205, 6, 7, 20 has median Q3=6.5Q_3 = 6.5, so IQR=6.5−2.5=4\text{IQR} = 6.5 - 2.5 = 4 minutes. The middle half of the delays lies between 2.52.5 and 6.56.5 minutes, and changing the largest delay from 2020 to 200200 minutes would leave all three quartiles and the IQR exactly as they are. The linear interpolation rule gives Q1=2.75Q_1 = 2.75 and Q3=6.25Q_3 = 6.25 instead, with IQR=3.5\text{IQR} = 3.5 minutes.

Five-number summary and box plot

Definition The five-number summary lists the minimum, Q1Q_1, the median, Q3Q_3 and the maximum. A box plot draws these positions along a number line. A box runs from Q1Q_1 to Q3Q_3, a line inside the box marks the median, and whiskers extend outward from the box. In the simple version the whiskers reach the minimum and the maximum. In the modified version, the default in much statistical software, each whisker stops at the most extreme observation that is not beyond its outlier fence, and any observation beyond a fence is drawn as a separate point. A box plot should state which version it shows and which quartile rule it uses.

In plain words A box plot compresses a dataset into a few positions. It shows the center, the middle half and the extent of the data at a glance, and it makes several groups easy to compare side by side. It does not show the sample size or the mean, and it can hide gaps, clusters and multiple peaks, so quite different datasets can produce the same box plot.

Example For the eight delays the five-number summary is (1,2.5,4.5,6.5,20)(1, 2.5, 4.5, 6.5, 20) minutes. A simple box plot has a box from 2.52.5 to 6.56.5, a median line at 4.54.5 and whiskers out to 11 and 2020. In the modified version the fences, found in the next card, are −3.5-3.5 and 12.512.5 minutes. The upper whisker then stops at 77, the delay of 2020 minutes appears as a separate point, and the lower whisker still reaches 11.

Outlier fence

Definition The lower and upper outlier fences are

L=Q1−1.5 IQR,U=Q3+1.5 IQR.\begin{gathered} L = Q_1 - 1.5\,\text{IQR}, \\[0.4em] U = Q_3 + 1.5\,\text{IQR}. \end{gathered}

An observation below LL or above UU is flagged as a potential outlier. The factor 1.51.5 is a convention, and the fences move when the quartile rule changes.

In plain words The fences screen for observations that lie unusually far from the middle half of the data. A flagged value deserves a closer look, at how it was recorded and at whether it came from the same process as the rest. The flag alone does not prove that the value is an error, and it is not a reason to delete it. Even a normal distribution has about 0.7 percent of its values beyond the fences computed from its own quartiles, so a large sample of perfectly ordinary normal data can be expected to contain some flagged points.

Example For the eight delays IQR=4\text{IQR} = 4, so L=2.5−6=−3.5L = 2.5 - 6 = -3.5 and U=6.5+6=12.5U = 6.5 + 6 = 12.5 minutes. No delay lies below −3.5-3.5, and only the delay of 2020 minutes lies above 12.512.5, so it is the one flagged. It could be a recording mistake, or a real trip held up by a road closure, and the flag says to find out which. With the linear interpolation quartiles 2.752.75 and 6.256.25, the fences would be −2.5-2.5 and 11.511.5 minutes, and the same delay would be flagged.

Median absolute deviation

Definition For observations x1,…,xnx_1, \dots, x_n with median mm, the median absolute deviation is the median of their distances from mm,

MAD⁡=median⁡i∣xi−m∣.\operatorname{MAD} = \operatorname{median}_{i} \lvert x_i - m \rvert .

This is the raw, or unscaled, MAD, and it is in the units of the data. Some software multiplies it by about 1.48261.4826 by default, so that for normal data it estimates the standard deviation. A reported MAD should say whether it is raw or scaled.

In plain words The MAD measures spread with two medians, one for the center and one for the typical distance from it. A summary is called resistant when changing a few observations, even to extreme values, can move it only a limited amount. In a dataset of at least three values, moving one observation, however far, changes the MAD by only a limited amount, while it can make the standard deviation as large as you like. Resistance has limits, though. If enough observations move, the MAD moves too.

Example For the constructed values 2,3,4,5,162, 3, 4, 5, 16, the median is 44. The distances from 44 are 22, 11, 00, 11 and 1212, which in order are 0,1,1,2,120, 1, 1, 2, 12, so the raw MAD is 11. The sample standard deviation of the same values is about 5.705.70, inflated by the single value 1616.

Trimmed mean

Definition Sort nn observations and choose a whole number kk with 2k<n2k < n. The trimmed mean removes the kk smallest and the kk largest observations and averages the remaining n−2kn - 2k. The amount of trimming is usually described by the proportion k/nk/n removed from each tail. When a requested proportion does not give a whole number of observations, software rules differ in how they round, so the rule should be reported.

In plain words A trimmed mean is a compromise between the mean, which uses every value, and the median, which in effect trims everything except the middle one or two. Like the mean, it uses the actual sizes of the values it keeps, and like the median, it ignores the most extreme positions. For a skewed distribution it describes a different quantity from the ordinary mean, so it is not the mean with inconvenient values quietly removed. Choose the trimming rule before making the comparison, report it, and keep the full data on record.

Example For 2,3,4,5,162, 3, 4, 5, 16, trimming one observation from each end, 20 percent per tail, removes 22 and 1616 and leaves 3,4,53, 4, 5, whose mean is 44. The ordinary mean is 66. For the eight delays, trimming one from each end, 12.5 percent per tail, removes 11 and 2020, and the remaining six delays average 27/6=4.527/6 = 4.5 minutes, compared with the ordinary mean of 66 minutes.

Check yourself

  1. Nine trips on another route took 1212, 1414, 1515, 1515, 1616, 1818, 1919, 2121 and 4040 minutes. With the median-of-halves rule, find the quartiles, the IQR and the fences. Which trips are flagged, and where do the whiskers of the modified box plot end?
Show the answer

With n=9n = 9 the median is the fifth value, 1616 minutes, and it is left out of both halves. The lower half 12,14,15,1512, 14, 15, 15 gives Q1=14.5Q_1 = 14.5, and the upper half 18,19,21,4018, 19, 21, 40 gives Q3=20Q_3 = 20, so IQR=5.5\text{IQR} = 5.5 minutes. The fences are L=14.5−8.25=6.25L = 14.5 - 8.25 = 6.25 and U=20+8.25=28.25U = 20 + 8.25 = 28.25 minutes. Only the trip of 4040 minutes lies outside, above UU. The whiskers end at 1212 and 2121 minutes, and the trip of 4040 minutes is drawn as a separate point, a value to check rather than to discard.

  1. Compare the eight delays 1,2,3,4,5,6,7,201, 2, 3, 4, 5, 6, 7, 20 with the nine values 1,2,3,4,4.5,5,6,7,201, 2, 3, 4, 4.5, 5, 6, 7, 20. Show that the two datasets have the same modified box plot. What do the box plots fail to reveal?
Show the answer

For the nine values the median is the fifth value, 4.54.5. The lower half 1,2,3,41, 2, 3, 4 gives Q1=2.5Q_1 = 2.5 and the upper half 5,6,7,205, 6, 7, 20 gives Q3=6.5Q_3 = 6.5. With minimum 11 and maximum 2020, the five-number summary is (1,2.5,4.5,6.5,20)(1, 2.5, 4.5, 6.5, 20), the same as for the eight delays. The IQR is 44 in both cases, so the fences are −3.5-3.5 and 12.512.5, the whiskers end at 11 and 77, and 2020 is flagged in both. The two box plots are identical, yet one dataset has 88 values with mean 66 and the other has 99 values with mean 52.5/9≈5.8352.5/9 \approx 5.83. A box plot does not show the sample size or the mean, and it shows only a rough outline of the shape.

  1. In the values 2,3,4,5,162, 3, 4, 5, 16, change 1616 to 2626. Recompute the mean, the median, the raw MAD and the mean trimmed by one observation at each end. Which summaries resist the change?
Show the answer

The mean rises from 66 to 40/5=840/5 = 8. The median stays 44. The distances from 44 are now 22, 11, 00, 11 and 2222, which in order are 0,1,1,2,220, 1, 1, 2, 22, so the raw MAD stays 11. Trimming removes 22 and 2626 and leaves 3,4,53, 4, 5, so the trimmed mean stays 44. The median, the MAD and the trimmed mean resist the change, while the mean moves, and so does the sample standard deviation, from about 5.705.70 to about 10.1210.12. The resistance of this trimmed mean covers only one extreme value per tail. If 55 were also changed to 5050, the trimmed mean would keep 2626 and become (3+4+26)/3=11(3 + 4 + 26)/3 = 11, while the median would still be 44.

How this lesson connects