DATA SCIENCE · CYCLE 2 · L24 · TEXTBOOK CHAPTER
Pick Five Rectangles
A sample picked by eye leans one way. A random sample does not. And more of the same picks lean just as far: a bigger sample does not fix a biased one.
After this chapter, you can
- Say why a sample picked by eye is biased.
- Find a sample’s bias: its mean minus the true mean.
- Pick a random sample with =RANDBETWEEN, and freeze it.
- Look up a value by its id with =XLOOKUP.
- Name a selection bias in a story, and a fix.
For your project: your ABOUT tab gets its fifth line, what your file misses, with a count. The checkpoint is at the end.
Why It Matters
In 1936 a magazine, the Literary Digest, mailed about 10 million ballots asking who would win the presidential election. Nearly 2.4 million came back. It forecast that Alf Landon would win, with 54% of the vote to Franklin Roosevelt’s 41%.
Roosevelt won with 61%. The forecast for Roosevelt missed by 41 − 61 = −20 points. That number is the forecast’s bias: what the sample said minus the truth.
The ballots went mostly to people in telephone books and lists of car owners, and the people who chose to mail one back leaned to Landon. George Gallup asked about 50,000 people, picked by a plan, and called Roosevelt the winner. Nearly 2.4 million ballots could not fix who was asked, or who chose to answer.
The Idea
Bias as a number
A sample picked by eye is biased. A random one is not. A bigger sample does not fix a biased one.
| Word | It means | With the rectangles |
| population | everyone or everything you want to know about | all 100 rectangles |
| sample | the part of the population you look at | your five |
| true mean | the population’s mean | =AVERAGE(RECT!B2:B101) |
| bias | sample mean − true mean | =E8-E9 |
| random sample | every member has the same chance to be picked | =RANDBETWEEN(1,100) |
Bias above 0: the sample ran high. One random sample can miss too, but random misses land on both sides of 0. Misses that lean one way are selection bias: how the sample was picked leaves some of the population out.
Try It: Pick Five
Here are the class’s 100 rectangles, each with its id. A rectangle’s area is the squares inside it. Click five that look typical of all 100: by eye, no counting. Then press Find my mean. Then press Draw five at random a few times, and pick again. Watch which row of dots leans right of 0.
Worked Examples
Example 1 · One sample, its bias. A city’s adults take 26 minutes to get to work, on average. A survey at a train station at 8 a.m. finds a mean of 41 minutes. What is the survey’s bias?
Create a strategyBias is the sample mean minus the true mean. The sign says which way the sample leaned.
Apply the idea41 − 26 = 15 minutes.
Reflect and checkAbove 0: the survey ran high. Who could never be in it? People who work from home or drive a short way. The station only holds people with long trips, so asking more of them would not help.
Example 2 · By eye, then at random. A library shelf has 10 books. Their ids are in A2 to A11 of a tab named BOOKS, and their page counts in B2 to B11.
| id | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| pages | 120 | 340 | 95 | 210 | 410 | 150 | 180 | 88 | 390 | 117 |
Create a strategyFind the true mean of all 10. Then take two samples of 3: the books on the display table, ids 2, 5 and 9, and three ids from =RANDBETWEEN(1,10), frozen. Look each up with =XLOOKUP(D2,BOOKS!A:A,BOOKS!B:B).
Apply the idea
True mean: the pages add to 2,100, and 2,100 ÷ 10 = 210 pages.
The display table: 340 + 410 + 390 = 1,140, and 1,140 ÷ 3 = 380. Bias: 380 − 210 = 170 pages.
RANDBETWEEN gave 4, 7 and 10: 210 + 180 + 117 = 507, and 507 ÷ 3 = 169. Bias: 169 − 210 = −41 pages.
Reflect and checkBoth samples missed. The random one missed low this time, and next time it could miss high. The display table holds the big new books every time, so it misses high every time. That lean is the bias.
Example 3 · A bigger sample. A school asks: should the day start later? An online poll gets 30,000 votes, and 72% say yes. A survey of 400 students picked at random gets 51% yes. When every student is asked, 48% say yes.
Create a strategyFind each sample’s bias in points: its percent minus the true percent.
Apply the ideaThe online poll: 72 − 48 = 24 points. The random 400: 51 − 48 = 3 points.
Reflect and checkAnyone could choose to vote online, and the students who cared most did. 75 times as many votes still missed by 8 times as much. A bigger sample did not fix who chose to answer. Picking at random did.
The Same Idea in Python
These three cells take the idea to a big file: the survey’s 13,583 students, one row each. Press ▶ Run under each one, in order. Say your guess first. On this page the file is already here, so no Choose files button shows. No pandas word is new: .sample came in L20 and the filter in L22.
1from google.colab import files
2import pandas as pd
3name = next(iter(files.upload()))
4df = pd.read_csv(name)
5print(round(df["weight"].mean(), 1))
In Sheets this is: =AVERAGE(DATA!G2:G13584) on your L21 copy: the true mean, every weight in the file.
In English:
- Get the tool that opens files.
- Get the pandas toolbox and call it pd.
- Show a Choose files button, and call the name of the file you pick name.
- Open the file as a table called df.
- Print the mean of the weight column, rounded to 1 place.
Predict: every student in the survey is today’s population. What is their mean weight, in kilograms?
Can’t run it here? Show what it prints
67.9
In Sheets this is: =INDEX(DATA!G:G,RANDBETWEEN(2,13584)) typed in 50 cells, frozen, then =AVERAGE of the 50.
In English:
- Take 50 of the weight column’s rows at random, and call them fifty.
- Print the mean of fifty, rounded to 1 place.
Predict: will it print the same number as Cell 1? Run it again. Then click in the cell, change 50 to 500 and run it twice more.
Can’t run it here? Show what it prints
68.4
Yours will differ: a new 50 every run. Most runs land from 63.9 to 72.1, a little high or a little low. With 500, from 66.7 to 69.2. About 4 of the 50 rows have no weight; .mean() skips them, as =AVERAGE skips a word.
In Sheets this is: a filter that keeps male, then 500 random rows of what is left, and their mean.
In English:
- Keep the rows where gender is male, and call them boys.
- Take 500 of the boys’ weights at random, and print their mean, rounded to 1 place.
Predict: 500 is ten times 50. Will this land closer to Cell 1’s number? Then change 500 to 5000.
Can’t run it here? Show what it prints
73.7
Yours will differ a little: most runs land from 72.4 to 74.9, and with 5000 from 73.4 to 73.9. Every run is about 5.7 kg too high. The sample can hold only boys, so more of them only make the wrong answer steadier. That is the Literary Digest in one line.
Want to type your own? The Python practice page has tasks and a notebook.
In your project
Every file leaves someone out. A college file holds only the colleges that report admissions; a weather file holds one station; a trail counter sees one spot on one trail. That is a selection bias, and your claim inherits it. Your ABOUT tab says so in A5, with a count, and the memo’s two biases with numbers start there.
Check Yourself
Answer each one before you look. The first two are from L22 and L20.
A2 to B6 hold red 3, blue 9, red 5, blue 2, red 7. What does =AVERAGEIF(A2:A6,"red",B2:B6) show? L22
The red rows are 3, 5 and 7. 3 + 5 + 7 = 15, and 15 ÷ 3 = 5. 5.2 is the mean of all five rows: AVERAGEIF uses only the rows that say red.
C2 held =RANDBETWEEN(1,20). You copied it and used Edit > Paste special > Values only. What does C2 hold tomorrow? L20
Values only keeps the number and throws the formula away, so it never changes again. A live =RANDBETWEEN draws a new number every time the Sheet opens.
A population’s true mean is 42. A sample’s mean is 39.5. What is the sample’s bias?
39.5 − 42 = −2.5
Sample mean minus true mean. Below 0: the sample ran low. 2.5 has the right size and the wrong sign.
A tab holds ids 21 to 25 in A2 to A6 and the values 19, 47, 64, 30 and 8 in B2 to B6. What does =XLOOKUP(23,A2:A6,B2:B6) show?
23 is in A4, the third id. Beside it in B4 is 64. XLOOKUP finds the id in the first range and gives back what is beside it in the second.
Which is a random sample of a school’s students?
Only RANDBETWEEN gives every student the same chance. The door picks early arrivers, and the form picks students who choose to answer.
A biased survey grows from 500 people to 50,000, picked the same way. What happens to its bias?
More people picked the same way lean the same way. The answer only gets steadier around the wrong number, as the 2.4 million ballots did in 1936.
To learn how much the school’s students read, a teacher surveys the library’s book club. Which is the best fix?
The book club leaves out students who read less, so the survey runs high. Asking the club again, or asking more of it, keeps the same lean. A random pick from everyone gives each student the same chance.
A shop’s 50 parcels weigh 3.2 kg on average. Five picked at random weigh 2.0, 4.5, 3.5, 2.5 and 4.0 kg. What is this sample’s bias, in kg?
2.0 + 4.5 + 3.5 + 2.5 + 4.0 = 16.5, and 16.5 ÷ 5 = 3.3. Bias: 3.3 − 3.2 = 0.1 kg. A random sample misses a little, high or low.
Project Checkpoint
ABOUT · part of P2, due Fri 18 Dec
A reader can trust your claim only about the rows your file holds. A5 says who or what it could never hold, with a number, so nobody stretches your claim past your data. It is the first of the two biases your memo shows with numbers.
| My dataset | B5, the count | A5, what it misses |
| Colleges | =COUNTA('RAW directory'!A2:A)-COUNTA(RAW!A2:A) | What it misses: B5 colleges in the directory with no admissions numbers. |
| Bikeshare trips | =COUNTUNIQUE(RAW!F2:F) | What it misses: every station but these B5, all in Arlington and Alexandria, and every month but September 2025. |
| Weather | =COUNTUNIQUE(RAW!A2:A) | What it misses: every place but B5 station, at the airport. |
| Trail counters | =COUNTUNIQUE(RAW!A2:A) | What it misses: every trail but these B5 counters, and 87 days at the Rosslyn Bikeometer. |
Put B5’s number where the line says B5. 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.