MathemagiciansLibraryExplorationsDeep Dives
← Mathematics · Upper Secondary
MathematicsUpper Secondary

Estimating median and quartiles from a histogram

U4 — Statistics Advancing › U4.2 — HistogramsLecture 4 of 4~2830 words

A median with no list and no curve

At a charity bicycle ride, 80 riders recorded how far they cycled. The organisers grouped the distances and drew this histogram.

00.511.522.501020304050607080Distance (km)Frequency density
The distances cycled by 80 riders. The classes are 0 to 10, 10 to 20, 20 to 30, 30 to 50 and 50 to 80 km. Height is frequency density, in riders per kilometre. One small square is 2 km across and 0.1 up.

Here is the question: what is the median distance?

You know what a median is. It is the value with half of the data below it. With a list, you put the values in order and find the middle one. With a cumulative frequency curve, you go across from half the total and read down. Here you have neither. The histogram does not show a single rider's distance. It shows only how many riders are in each class.

It can still be answered, and you already own the tool. The last lecture took a range of values and estimated how many riders were inside it. This lecture runs the same idea backwards. You choose the count, and you find the value.

The median is the line that halves the area

Start with the one rule that every histogram lecture has used. On a histogram, area is count. The bar for 10 to 20 km has height 2.4 and width 10, so its area, 24, is the number of riders in that class.

Now think about the median in the language of area. Half of 80 is 40. The median is the distance with 40 riders below it. On the histogram, the riders below a distance are the area to the left of that distance. So the median is the place where a vertical line cuts the histogram into two equal areas: 40 on the left and 40 on the right.

That is the picture to hold on to. Before you calculate anything, make a guess about where that line falls.

Predict, then reveal — where is the median?

Look at the ride histogram above. Which answer is right? Choose one, then read the explanation.

The figure shows the ride histogram with the number of riders below each class boundary written under the axis. The median class is picked out.

00.511.522.5median ≈ 23.8010203040506070800832537080Distance (km)Frequency density
The numbers under the axis are the riders below each boundary: 0, 8, 32, 53, 70 and 80. The 40th rider is passed between 20 and 30 km, so the median is in that class. The dashed line is the estimate worked out below, about 23.8 km.

32 riders are below 20 km and 53 are below 30 km. Half of 80 is 40, which lies between 32 and 53, so the median is in the 20–30 km class. It is not in the tallest bar, and it is not at 40 km, the middle of the axis.

Step 1: count up to the right class

The first step is to turn the picture back into numbers, as in the last lecture, and then add a running total. Each frequency is height × width.

Distance (km)HeightWidthFrequencyRiders below the end of the class
0.81088
2.4102432
2.1102153
0.85201770
⅓301080

The last column is the cumulative frequency from the cumulative frequency lectures. Its final entry is 80, the number of riders ✓.

Look at the last bar. Its top is a third of the way from 0.3 to 0.4, so its height is one third. If you round it to 0.33, you get 0.33 × 30 = 9.9 riders, and the total becomes 79.9. Riders are whole, so the reading was rounded: ⅓ × 30 = 10. Check the total every time.

Now go down the last column and look for 40. After the second class there are 32 riders. After the third class there are 53. So the 40th rider is inside the 20–30 km class, which is called the median class. This part is exact. It does not depend on any assumption.

Step 2: go the right distance into the class

Now you are standing at 20 km with 32 riders behind you. You need 40, so you need 40 − 32 = 8 more riders. How far past 20 km must you go to collect them?

This is the hard part of the lecture. Spend time here. The histogram knows that the class holds 21 riders. It does not know where they are inside the class. So you use the assumption from the last lecture: the riders are spread evenly through the class. The flat top of the bar draws exactly this assumption.

The last lecture used it in one direction: count = height × width. Here you know the count, 8, and you want the width. So turn the rule round:

width = count ÷ height = 8 ÷ 2.1 ≈ 3.81 km

The height, 2.1, means 2.1 riders per kilometre. Collecting 8 riders at that rate takes 8 ÷ 2.1 ≈ 3.81 km. So the median is about 20 + 3.81 = 23.81 km. Rounded to 3 significant figures (3 s.f.), the estimated median is 23.8 km.

8 riders(area 8)13 ridersheight 2.1 riders per km2023.8130width = 8 ÷ 2.1 ≈ 3.81 kmDistance (km)
The 20–30 km bar on its own. The 32 riders below 20 km are off to the left. Cutting the bar at about 23.81 km leaves an area of 8 on the left, so the 40th rider is reached there. The other 13 riders of the class are to the right.

There is a second way to say the same thing. The 8 riders you need are 8 out of the 21 in the class. If the riders are spread evenly, you must go 8/21 of the way across the class. The class is 10 km wide, so:

Both routes are one calculation. Dividing 8 by the height 2.1 is the same as dividing 8 by 21 and multiplying by 10, because 2.1 = 21 ÷ 10.

That is it. That is the whole idea. Find the class by counting. Then cut the bar so that the area on the left is the number you still need.

Median and quartiles from a histogram

1. Find each frequency (height × width) and the running totals. The target is for the median, for Q₁ and for Q₃.

2. The class where the running total first reaches the target holds the answer. This is exact.

3. Inside that class, assume the values are spread evenly. Go across the fraction of the class width, where is the running total before the class and is the class frequency. This is an estimate.

Some textbooks write step 3 as one formula: value ≈ , where is the lower boundary of the class and is its width. You do not need to learn it as a separate fact. It is the last lecture's slice, read backwards. If you forget it, you can build it again from "area is count".

Quartiles: the same cut, with other targets

The quartiles cut the area into quarters. A quarter of 80 is 20, so Q₁ has 20 riders below it. Three quarters of 80 is 60, so Q₃ has 60 riders below it. Nothing else changes.

For Q₁, the running totals are 8 after the first class and 32 after the second. So Q₁ is in the 10–20 km class. You need 20 − 8 = 12 more riders out of 24. That is exactly half the class, so Q₁ ≈ 10 + 5 = 15 km. As a check by the other route, 12 ÷ 2.4 = 5 km ✓.

For Q₃, the running totals are 53 after the third class and 70 after the fourth. So Q₃ is in the 30–50 km class, which is 20 km wide. You need 60 − 53 = 7 more riders out of 17:

The check by height: 7 ÷ 0.85 ≈ 8.24 km, and 30 + 8.24 = 38.24 ✓. The interquartile range is about 38.24 − 15 ≈ 23.2 km. It is the width of the middle half of the riders.

Now try the cut yourself. Move the line, and watch the area on each side.

Explore — cut the histogram with a line

Move the line with the slider or the − / + buttons. The shaded area to its left is the number of riders below that distance. Find the place where the left side holds 40 riders. Then try the presets.

Presets:

Line at: 10 km

The figure shows the ride histogram cut at the three quartiles. Each of the four pieces has an area of 20, so each holds 20 riders.

00.511.522.5Q₁Q₂Q₃2020202001020304050607080Distance (km)Frequency density
Q₁ ≈ 15 km, the median Q₂ ≈ 23.8 km and Q₃ ≈ 38.2 km. The four pieces have equal areas but very different widths.
Line atRiders to the leftWorking
15 km (Q₁)208 + 2.4 × 5
23.81 km (median)4032 + 2.1 × 3.81
38.24 km (Q₃)6053 + 0.85 × 8.24
40 km61.553 + 0.85 × 10

Notice that the line at 40 km, the middle of the axis, already has 61.5 riders on its left. Notice also that the four quarters have equal areas but very different widths. The second quarter is only about 8.8 km wide, while the last stretches more than 40 km. Narrow means crowded, and wide means spread out.

Stop and think

The median, about 23.8 km, is not halfway between Q₁ ≈ 15 km and Q₃ ≈ 38.2 km. Halfway would be about 26.6 km. Has something gone wrong?

Show the answer

No. Each quarter holds 20 riders, but the quarters do not have to be equally wide. From Q₁ to the median is about 8.8 km. From the median to Q₃ is about 14.4 km. The riders above the median are more spread out, because a few rode very long distances. The box plot lectures called this positive skew. The median must lie between Q₁ and Q₃. It does not have to lie in the middle.

How good is the estimate?

The median class is exact, so the true median is certainly somewhere from 20 to 30 km. The position 23.8 km is an estimate, built on the evenly spread assumption.

Stop and think

Could the true median of the ride be 29 km? Could it be 31 km?

Show the answer

29 km is possible. Perhaps most of the 21 riders in the 20–30 class rode close to 30 km. Then the 40th rider would be near the top of the class. 31 km is impossible. At least 53 riders rode less than 30 km, so the 40th rider is certainly below 30 km.

You have also met this calculation before, in another form. On a cumulative frequency curve, some courses join the points with straight lines. Between 20 km and 30 km, that line climbs from 32 to 53. A straight line climbs evenly, so it reaches 40 after 8/21 of the way across. That gives 23.81 km again, the same number by a second route. As the last lecture showed, the straight join and the flat top of the bar are the same assumption. A smooth curve bends a little, so it may give a slightly different reading. Neither answer is exact. Both are honest estimates.

One more detail matches the cumulative frequency lectures. The target for the median is , not . With a list, you count positions, and finds the middle one. A histogram shows counts below a value, not positions in a list. The difference between 40 and 40.5 is half a rider. Here it moves the median by 0.5 ÷ 2.1 ≈ 0.24 km, which is much smaller than the doubt that the assumption brings.

Sometimes the target lands exactly on a running total. Then no bar is cut, the answer is a class boundary, and no assumption is needed. Worked Example 2 shows this.

Worked examples

Worked Example 1 — The parcels from the last lecture

In the last lecture, a histogram of 56 parcel masses had heights 3.5, 4.0, 2.6, 1.2 and 0.4 over the classes 0–2, 2–5, 5–10, 10–20 and 20–50 kg. Estimate the median, the quartiles and the interquartile range.

The frequencies were 7, 12, 13, 12 and 12. The running totals are 7, 19, 32, 44 and 56 ✓.

Median: the target is 56 ÷ 2 = 28. The running total passes 28 in the 5–10 class (19 before it, 32 after it). You need 28 − 19 = 9 more parcels, at 2.6 parcels per kg. That takes 9 ÷ 2.6 ≈ 3.46 kg. So the median ≈ 5 + 3.46 ≈ 8.46 kg.

Q₁: the target is 14, in the 2–5 class (7 before it). You need 7 more out of 12, across a width of 3 kg: kg.

Q₃: the target is 42, in the 10–20 class (32 before it). You need 10 more out of 12: kg.

The interquartile range is about 18.33 − 3.75 ≈ 14.6 kg.

Check: Q₁ ≈ 3.75 is less than the median ≈ 8.46, which is less than Q₃ ≈ 18.33 ✓. Each answer lies inside its own class ✓.

Worked Example 2 — An exact answer and a percentile

The mangoes from the last lecture (invented data) had frequencies 30, 50, 45 and 25 over the classes 150–200, 200–220, 220–250 and 250–300 g. A shop sells the lightest 20% as juice fruit and the heaviest 10% as premium fruit. (a) Below what mass are the lightest 20%? (b) Estimate the median. (c) Estimate the mass above which the heaviest 10% lie.

The running totals are 30, 80, 125 and 150 ✓.

(a) 20% of 150 is 30. The running total reaches exactly 30 at 200 g, the end of the first class. So exactly 30 mangoes are below 200 g, and the answer is 200 g. No bar is cut, so this answer is exact.

(b) The target is 75, in the 200–220 class (30 before it, 80 after it). You need 45 more out of 50: g.

(c) The heaviest 10% are above the 90th percentile. 90% of 150 is 135, in the 250–300 class (125 before it). You need 10 more out of 25: g. Check by height: the bar is 25 ÷ 50 = 0.5 mangoes per gram, and 10 ÷ 0.5 = 20 g ✓.

Worked Example 3 — From a histogram to a box plot

Draw a box plot of the parcel masses from Worked Example 1, and describe its shape.

A box plot needs five numbers. The quartiles and median come from Worked Example 1. The histogram does not show the lightest and heaviest parcels. It shows only that every parcel is between 0 and 50 kg. So the whiskers end at these class limits. They are limits, not measured values.

Parcels (n = 56)01020304050Mass (kg)
The box runs from Q₁ ≈ 3.75 kg to Q₃ ≈ 18.33 kg, with the median ≈ 8.46 kg. The whiskers end at the class limits 0 and 50 kg.

From Q₁ to the median is about 4.7 kg. From the median to Q₃ is about 9.9 kg. The right whisker is much longer than the left one. So the masses show positive skew: most parcels are light, with a long tail of heavy ones.

Can you test for outliers? The upper fence is Q₃ + 1.5 × IQR ≈ 18.33 + 1.5 × 14.58 ≈ 40.2 kg. Some parcels in the 20–50 class may be above 40.2 kg, but the histogram cannot say how many, or whether any are. So with grouped data you cannot tell.

Trap 1 — Choosing the tallest bar

The tallest bar is the most crowded class. The median class is the one where the running total passes half the total. They are often different classes, as in the ride. Find the median class from the running totals, never from the picture alone.

Trap 2 — Using the wrong running total

In the fraction, subtract the running total before the class, 32, not the one after it, 53. Using 53 gives 40 − 53 = −13, a negative number of riders. If the fraction is negative or bigger than 1, you have used the wrong total.

Trap 3 — Forgetting where the class starts

The fraction of the class gives a distance into the class, 3.81 km. It is not the median. Add the lower boundary: 20 + 3.81 = 23.81 km. Every answer must lie inside its own class. An answer of 3.81 km would put the median in the first class, where only 8 riders are.

Try it yourself

Work each one on paper first. Open a hint only when you are stuck.

  1. A histogram shows how long 60 people waited at a clinic (invented data). The heights, in people per minute, are 1.2 for , 3 for , 4.2 for , 1.2 for and 0.4 for . Estimate the median waiting time.

    Hint 1

    Find each frequency (height × width), then the running totals. Where is the 30th person?

    Hint 2

    The frequencies are 6, 15, 21, 12 and 6. After two classes, the running total is 21.

    Full answer

    Running totals: 6, 21, 42, 54, 60 ✓. The target is 60 ÷ 2 = 30, which is passed in the 10–15 class. You need 30 − 21 = 9 more out of 21, across 5 minutes: minutes. Check by height: 9 ÷ 4.2 ≈ 2.14 minutes, and 10 + 2.14 = 12.14 ✓. The answer lies inside its class ✓.

  2. For the same 60 people, estimate Q₁, Q₃ and the interquartile range. Is the distribution skewed?

    Hint 1

    The targets are 15 and 45.

    Hint 2

    Q₁ is in the 5–10 class with 6 before it. Q₃ is in the 15–25 class with 42 before it.

    Full answer

    Q₁ ≈ minutes. Q₃ ≈ minutes. IQR ≈ 17.5 − 8 = 9.5 minutes. From Q₁ to the median is about 4.1 minutes, and from the median to Q₃ is about 5.4 minutes. So there is a slight positive skew: the longer waits are more spread out. Check: 8 < 12.1 < 17.5 ✓.

  3. The clinic says that 70% of people wait less than 15 minutes. (a) Is this claim exact or an estimate? (b) Estimate the 80th percentile of the waiting times. (c) Find the 90th percentile.

    Hint 1

    Is 15 minutes a class boundary? Find 80% and 90% of 60 first.

    Hint 2

    The targets are 48 and 54. Compare them with the running totals 42 and 54.

    Full answer

    (a) 15 minutes is a class boundary, and 42 people are below it. 42 ÷ 60 = 0.7, which is 70%. The claim is exact. (b) 80% of 60 is 48, in the 15–25 class with 42 before it: minutes. (c) 90% of 60 is 54, and the running total reaches exactly 54 at 25 minutes. So the 90th percentile is 25 minutes, with no bar cut.

  4. A histogram has classes , , and , with frequencies 12, , 30 and 8. The frequency has been lost. The estimated median, found by the method of this lecture, is 26 and lies in the 20–40 class. Find , and check your answer.

    Hint 1

    The total is , so the target is half of that. The running total before the 20–40 class is .

    Hint 2

    Write the method as an equation: .

    Full answer

    From the equation, . Multiply both sides by : , so and . Check: the total is 58 and the target is 29. The running total is 20 at 20 and 50 at 40, so the median is in the 20–40 class ✓. Then ✓.

The bigger idea

This lecture ends the histograms topic, and one rule carried all four lectures: area is count. It gave the bars their height, and it let you count inside part of a bar. Here it found the median as the line that halves the area.

The same picture continues later. When data are grouped into narrower and narrower classes, the bars become a smooth curve, and area under the curve still means "how many". Divide by the total, and area becomes a probability. For the normal distribution, the median is the line that cuts the area under the curve into two halves. That is the same cut you made with a ruler on the ride histogram.

Key concepts in this lesson