L24 Pick Five Rectangles

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

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.

WordIt meansWith the rectangles
populationeveryone or everything you want to know aboutall 100 rectangles
samplethe part of the population you look atyour five
true meanthe population’s mean=AVERAGE(RECT!B2:B101)
biassample mean − true mean=E8-E9
random sampleevery 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 strategy

Bias is the sample mean minus the true mean. The sign says which way the sample leaned.

Apply the idea

41 − 26 = 15 minutes.

Reflect and check

Above 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.

id12345678910
pages1203409521041015018088390117
Create a strategy

Find 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 check

Both 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 strategy

Find each sample’s bias in points: its percent minus the true percent.

Apply the idea

The online poll: 72 − 48 = 24 points. The random 400: 51 − 48 = 3 points.

Reflect and check

Anyone 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:

  1. Get the tool that opens files.
  2. Get the pandas toolbox and call it pd.
  3. Show a Choose files button, and call the name of the file you pick name.
  4. Open the file as a table called df.
  5. 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:

  1. Take 50 of the weight column’s rows at random, and call them fifty.
  2. 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:

  1. Keep the rows where gender is male, and call them boys.
  2. 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

C2 held =RANDBETWEEN(1,20). You copied it and used Edit > Paste special > Values only. What does C2 hold tomorrow? L20

A population’s true mean is 42. A sample’s mean is 39.5. What is the sample’s bias?

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?

Which is a random sample of a school’s students?

A biased survey grows from 500 people to 50,000, picked the same way. What happens to its bias?

To learn how much the school’s students read, a teacher surveys the library’s book club. Which is the best fix?

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?

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 datasetB5, the countA5, 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.

Read More

OpenStax, Introductory Statistics 2e, section 1.2: Data, Sampling, and Variation in Data and Sampling. A free college textbook. Read the parts on simple random samples and on sampling bias. It puts today’s idea in one line: “A sample that is not representative of the population is biased.”

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.