DATA SCIENCE · CYCLE 2 · L18 · TEXTBOOK CHAPTER
Stand in Line
A center is not enough. Two groups can have the same median and still be very different. Put the values in a line, smallest first. Cut the line into four quarters. Now you can see how far apart the values are.
After this chapter, you can
- Find a five-number summary by hand.
- Find the IQR and say what it measures.
- Draw a box plot from five numbers.
- Compare spread by reading two box plots.
For your project: the five-number summary and the IQR of your number go on ANALYSIS. The checkpoint is at the end.
Why It Matters
A cockpit built for the average pilot.
Anything built for people has to fit people who differ. A center cannot tell you how much they differ.
In 1950 the Air Force measured 4,063 pilots. Two years later Lieutenant Gilbert Daniels took 10 body sizes from those records: height, chest, sleeve length and seven more. Daniels called a pilot average on a size when he was in about the middle 30% of the men for that size. Then he kept only the pilots who were average, one size at a time.
| Step | Keep the pilots who are average on | Pilots left |
| Start | Everyone measured | 4,063 |
| 1 | Height | 1,055 |
| 2 | Chest too | 302 |
| 3 | Sleeve length too | 143 |
| 10 | All ten sizes | 0 |
After only three sizes, 143 pilots were left: about 3.5% of the 4,063. After ten, nobody was left. A cockpit built for the average pilot fit nobody, so the Air Force moved to seats and pedals you can adjust.
A center hides the spread. To design for people, you need to know how far apart they are.
The Idea
A center is not enough
Put the values in order. The quartiles cut the values into four quarters; the box holds the two middle quarters, the middle half.
A box plot is the five-number summary as a picture: a box from Q1 to Q3, a line at the median, whiskers out to the minimum and maximum.
| Five-number summary | How to find it |
| minimum and maximum | the smallest and the largest |
| median | the middle, once the values are in order |
| Q1 and Q3, the quartiles | the median of the lower half and of the upper half |
| IQR | Q3 minus Q1: how wide the middle half is |
With an odd count, the median belongs to both halves. Two in the middle? Take the number halfway between them.
The IQR is one number for spread: how far apart the values are. A small IQR means the values are consistent: close together. A big IQR means the middle half is spread out.
About a quarter of the values lie in each of the four parts. The box holds the two middle parts.
One far-off value stretches a whisker and barely moves the box. An outlier barely moves the median. It barely moves the IQR too.
Worked Examples
Example 1 · A five-number summary by hand. Nine runners finished a 5 km race. Their times, in minutes: 31, 24, 28, 22, 35, 26, 41, 29, 25. Find the five-number summary and the IQR. Then read the box plot.
Create a strategyEvery list starts the same way: in order. Then find the median. Nine is an odd count, so the median belongs to both halves and each half has five values. Q1 is the middle of the lower half. Q3 is the middle of the upper half.
Apply the idea
In order: 22, 24, 25, 26, 28, 29, 31, 35, 41.
Median: nine values, so the 5th. Median = 28.
Lower half 22, 24, 25, 26, 28: Q1 = 25.
Upper half 28, 29, 31, 35, 41: Q3 = 31.
Five-number summary: 22, 25, 28, 31, 41.
IQR = Q3 − Q1 = 31 − 25 = 6 minutes.
The nine times as a box plot: a box from 25 to 31, a line at 28, whiskers out to 22 and 41.
Reflect and checkThe middle half of the runners finished between 25 and 31 minutes, within 6 minutes of each other. One runner took 41 minutes. That stretched the right whisker and left the box where it was. The 28 was used twice, once in each half. That is why Sheets’ =QUARTILE shows the same 25 and 31.
Try It: Change the Values
The lab starts on Example 1’s nine times. Change the values to meet its three goals.
Example 2 · Two in the middle, then Sheets. Lunch at seven places near a school costs, in dollars: 7, 13, 5, 24, 10, 9, 17. Find Q1, Q3 and the IQR by hand. Then check all five numbers in Sheets.
Create a strategySeven values, so the median is the 4th. It belongs to both halves, so each half has four values. Four values have two in the middle. Take the number halfway between them: add the two, then divide by 2.
Apply the idea
In order: 5, 7, 9, 10, 13, 17, 24. Median, the 4th: 10.
Lower half 5, 7, 9, 10: two in the middle, 7 and 9. Q1 = (7 + 9) ÷ 2 = 8.
Upper half 10, 13, 17, 24: two in the middle, 13 and 17. Q3 = (13 + 17) ÷ 2 = 15.
IQR = 15 − 8 = 7 dollars.
Now Sheets. The header, Lunch ($), is in A1 and the seven prices are in A2 to A8. Sheets does not need them in order.
| Cell | Type | It shows |
| C2 | =MIN(A2:A8) | 5 |
| C3 | =QUARTILE(A2:A8,1) | 8 |
| C4 | =MEDIAN(A2:A8) | 10 |
| C5 | =QUARTILE(A2:A8,3) | 15 |
| C6 | =MAX(A2:A8) | 24 |
| C7 | =C5-C3 | 7 |
Reflect and checkSheets shows the same 8 and 15 as the hand rule. The second number inside =QUARTILE names the quartile: 1 for Q1, 2 for the median, 3 for Q3. If a cell shows #NUM!, the cells you named may hold no numbers. Check the column letter first. Sheets has no box plot chart, so the five numbers are what you report.
Example 3 · Which is more consistent? Two pizza shops timed their deliveries for a week, in minutes. The box plots show both shops. Which shop is more consistent?
Both shops on one number line, so the boxes can be compared.
Create a strategyRead Q1 and Q3 off each box, then subtract. The narrower box is the more consistent shop. Then write one sentence with both IQRs and their unit.
Apply the idea
Shop A: the box runs from 25 to 32. IQR = 32 − 25 = 7 minutes.
Shop B: the box runs from 20 to 38. IQR = 38 − 20 = 18 minutes.
The sentence: “Shop A is more consistent: the middle half of its deliveries spans 7 minutes, against 18 minutes for Shop B.”
Reflect and checkThe two medians, 28 and 29 minutes, are close. The boxes show the difference. Shop A’s range, the maximum minus the minimum, is 50 − 18 = 32 minutes. Shop B’s is 44 − 16 = 28. If you compare ranges, Shop A looks more spread out. A whisker ends at one value. The box comes from half the values. So compare the boxes.
The Same in Python
Python comes in L19b, two chapters after this one. Once you have read it, come back and run Example 1’s nine runners here. One word is new: .quantile(0.25) finds the value a quarter of the way up the ordered list. That is Q1, and its twin in Sheets is =QUARTILE(…,1).
In Sheets this is: =MEDIAN(A2:A10), =MAX(A2:A10) and =QUARTILE(A2:A10,1).
In English:
- Get the pandas toolbox and call it pd.
- Make a column of the nine numbers, and call it runs.
- Print the median of runs.
- Print the largest number in runs.
- Print the value a quarter of the way up runs, in order: Q1.
Predict: Example 1 found all three by hand. What will lines 3, 4 and 5 print? Then change 0.25 to 0.75, say what line 5 will print now, and run it again.
Can’t run it here? Show what it prints
28.0
41
25.0
pandas writes a median or a quartile as a decimal: 28.0 and 25.0 are the 28 and the 25 from Example 1. With 0.75, line 5 prints 31.0, which is Q3.
Want to type your own? The Python practice page has tasks and a notebook.
In your project
Your Cycle 2 project’s ANALYSIS tab reports the five-number summary of your number column. Type =MIN, =QUARTILE(…,1), =MEDIAN, =QUARTILE(…,3) and =MAX. Put the IQR under them. When you compare two groups, say which group’s middle half is wider, the way Example 3 does: both IQRs, and their unit.
Check Yourself
Answer each one before you look. The first two are from earlier lessons.
A sign-up Sheet lists student 4417 on two rows. The two rows match in every column. Which check does the Sheet fail? L16
Unique asks: is any row in the file twice? Two rows that match in every column are a duplicate. Valid asks for one type and one format in each column. Complete asks about blanks.
A server’s tips on six nights, in dollars: 14, 9, 55, 12, 10, 13. Find the median. L17
In order: 9, 10, 12, 13, 14, 55. Six values, so two are in the middle: 12 and 13. The median is (12 + 13) ÷ 2 = 12.5 dollars. The 55 is an outlier. It pulls the mean up to 18.83, and it barely moves the median.
What does the box of a box plot hold?
The box runs from Q1 to Q3. About a quarter of the values lie below Q1 and about a quarter above Q3, so the box holds the two middle quarters: the middle half. The top half is everything above the median. The whiskers hold the bottom quarter and the top quarter, which is more than the two end values.
Nine plants’ heights in cm, in order: 8, 11, 12, 15, 19, 20, 24, 27, 33. Find the IQR.
- Median, the 5th: 19.
- Lower half 8, 11, 12, 15, 19: Q1 = 12.
- Upper half 19, 20, 24, 27, 33: Q3 = 24.
- IQR = Q3 − Q1 = 24 − 12 = 12 cm.
Pages seven students read last night, in order: 3, 4, 7, 10, 14, 17, 25. What is Q3?
- Median, the 4th: 10. It belongs to both halves.
- Upper half 10, 14, 17, 25: two in the middle, 14 and 17.
- Q3 = (14 + 17) ÷ 2 = 15.5 pages.
You type =QUARTILE(D2:D40,1) and the cell shows #NUM!. What is the most likely cause?
Most likely, Sheets found no numbers in D2 to D40. The cells are empty, or they hold words. Check the column letter first. Sheets puts the values in order itself. An even count still gives an answer.
The tallest plant in question 4 was typed wrong: the 33 should be 90. The list is now 8, 11, 12, 15, 19, 20, 24, 27, 90. What is the IQR now?
Still 12 cm. Q1 is the 3rd value, 12, and Q3 is the 7th, 24. Neither one changed, so IQR = 24 − 12 = 12. The range, the maximum minus the minimum, jumped from 25 to 82. One far-off value moves the range a lot and leaves the IQR alone.
A box plot’s whiskers end at 3 and 46. Its box runs from 13 to 28, with a line at 21. What is the IQR?
The box runs from Q1 to Q3, so Q1 = 13 and Q3 = 28. IQR = Q3 − Q1 = 28 − 13 = 15. The line at 21 is the median. The whiskers end at the minimum and the maximum. So this box plot was drawn from five numbers: 3, 13, 21, 28, 46.
Maya and Leo timed their walks to school for a month, in minutes. Which sentence belongs on an ANALYSIS tab?
| Minimum | Q1 | Median | Q3 | Maximum |
| Maya | 11 | 14 | 15 | 17 | 34 |
| Leo | 10 | 12 | 16 | 24 | 27 |
Maya’s IQR is 17 − 14 = 3 minutes and Leo’s is 24 − 12 = 12 minutes. The smaller IQR is the more consistent walker: Maya. Leo’s range is smaller, 17 minutes against 23, but one slow morning made Maya’s range. Compare the IQRs. The sentence with Leo’s IQR has the right numbers and the wrong name: the bigger IQR is the less consistent walker.
Project Checkpoint
ANALYSIS · part of P2, due Fri 18 Dec
The five-number summary shows where the middle half of your values sits, so your claim can say how spread out a group is, not only where its middle is.
Do these once your CLEAN tab exists (L22, Fri 4 Dec). Column B of CLEAN is your number.
Check these numbers in Python: Your Project File on the practice page opens your CLEAN tab and prints them.
Tick each step once it is in your Sheet. Your ticks go into the PDF you hand in. Where everything goes: your Sheet, tab by tab.
Stuck on any of this? Ask Mr. Case in class or send him a message in Canvas. Name the example or the question number, and say which step lost you.