DATA SCIENCE · CYCLE 2 · L25 · TEXTBOOK CHAPTER
Four Ways to Draw
A random sample lets chance pick, so no one’s lean gets in. There are four ways to do it, and each fits a different situation. All four are fair. What differs is how far one sample can miss.
After this chapter, you can
- Name the four ways to draw a random sample.
- Choose a way for a situation, and say why.
- Draw a sample each way in Sheets, frozen.
- Find each sample’s bias.
- Say why a sample a person chooses fails.
For your project: a SAMPLE tab of 300 random rows if your CLEAN is big, and one line on ABOUT that says whether your file is a sample. The checkpoint is at the end.
Why It Matters
In 1948 the polls said Thomas Dewey would beat President Harry Truman. The Gallup Poll’s final estimate had Dewey at 49.5% and Truman at 44.5%.
Truman won, 49.5% to 45.1%. Gallup’s forecast for Truman missed by 44.5 − 49.5 = −5.0 points, and it named the wrong winner.
The polls used quota samples. Each interviewer had counts to fill: so many men, so many women, so many young and old. Inside those counts, the interviewer chose whom to ask. A review after the election told pollsters to stop using quotas and to use samples drawn by chance “at all levels of respondent selection”. The pollsters had also stopped asking two weeks before Election Day, sure nothing would change. They fixed both.
The Idea
Let chance pick
A random sample lets chance pick, so no one’s lean gets in. There are four ways, and each fits a different situation.
| Way | How, for 10 of 100 | Fits when |
| simple random sample | shuffle the list; take the first 10 | you have a list of everyone |
| systematic sample | a random start from 1 to 10, then every 10th | a list or a line with no pattern |
| stratified sample | at random within each group, in proportion | the groups differ, and each must be in |
| cluster sample | whole groups at random, everyone in them | groups are alike, and a few are cheap to reach |
| quota sample | a set count from each group; a person chooses who | never: the chooser’s lean gets in |
All four are fair: over many samples their misses land on both sides of 0. They differ in how far one sample can miss. A sample’s bias is its mean minus the true mean, as in L24.
Try It: Draw 10, Four Ways
Here is the class’s school of 100, the same as your SCHOOL tab: a row for each homeroom of 10, each student’s id (small) and hours of sleep on a school night. The darker the shading, the higher the grade. Each homeroom is one grade. Press a way to draw 10 students, and watch its dot land on that way’s row. Then press 20 of each. Which row stays inside the shaded band, within 0.3 of 0? Which spreads widest?
Worked Examples
Example 1 · Every kth on a list. A running club has 480 members on a list, ids 1 to 480 in A2 to A481. The coach wants a systematic sample of 24.
Create a strategyFind the step: the list size divided by the sample size. Draw a random start from 1 to the step, freeze it, then take every step-th id.
Apply the ideaThe step is 480 ÷ 24 = 20. =RANDBETWEEN(1,20), frozen, gave 13. The ids are 13, 33, 53, and on to 13 + 23 × 20 = 473. In Sheets, =FILTER(A2:A481,MOD(A2:A481-13,20)=0) gives all 24.
Reflect and check24 ids, the first 13 and the last 473. Every member had the same chance: 1 in 20. Check the list has no pattern every 20. If it listed teams of 20 with each captain first, a start of 1 would pick only captains.
Example 2 · In proportion. A hospital has 300 nurses: 150 on the day shift, 90 on the evening shift and 60 on the night shift. Night nurses sleep very differently. A survey of 20 asks about sleep.
Create a strategyThe shifts differ, and each must be in, so stratify by shift. Each shift gets its share of the 20: the shift’s size ÷ 300 × 20.
Apply the ideaDay: 150 ÷ 300 × 20 = 10. Evening: 90 ÷ 300 × 20 = 6. Night: 60 ÷ 300 × 20 = 4. Then 10 at random from the day nurses, 6 from the evening and 4 from the night.
Reflect and check10 + 6 + 4 = 20. A stratified sample always holds 4 night nurses, the hospital’s own share. A simple random 20 holds exactly 4 only about 23 times in 100, and 1 or none about 6 times in 100. Those samples would miss the night shift’s sleep.
Example 3 · One cluster. A district has 6 schools of 500 students each. Their mean hours of screen time on a school night are 3.2, 4.0, 2.6, 5.1, 3.5 and 4.4. A cluster sample picks one school at random and asks everyone in it.
Create a strategyThe schools are the same size, so the district’s true mean is the mean of the six. Then find the bias if school 4 is picked.
Apply the idea3.2 + 4.0 + 2.6 + 5.1 + 3.5 + 4.4 = 22.8, and 22.8 ÷ 6 = 3.8 hours. School 4: 5.1 − 3.8 = 1.3 hours too high.
Reflect and checkAsking 500 students did not help: they all came from one school, and the schools differ. A cluster sample works when each cluster looks like the whole. If every school had the same mix, one school would land near 3.8.
The Same Idea in Python
Not part of class today: try it at home. Press ▶ Run under each cell, in order. Say your guess first. On this page the school file is already here, so no Choose files button shows. No pandas word is new: .sample came in L20 and L24.
1from google.colab import files
2import pandas as pd
3name = next(iter(files.upload()))
4df = pd.read_csv(name)
5print(round(df["sleep"].mean(), 2))
In Sheets this is: =AVERAGE(SCHOOL!D2:D101) in G6 of your L25 tab: the true mean, all 100 students.
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 sleep column, rounded to 2 places.
Predict: all 100 students are the population. What is their mean sleep, in hours? Your G6 has it.
Can’t run it here? Show what it prints
7.3
In Sheets this is: =AVERAGE(D2:D11) in G2: the first 10 rows of the shuffled school, a simple random sample.
In English:
- Take 10 of the sleep column’s rows at random, and call them ten.
- Print the mean of ten, rounded to 2 places.
Predict: will it print the same number as Cell 1? Run it again. Then click in the cell, change 10 to 40 and run it twice more.
Can’t run it here? Show what it prints
7.19
Yours will differ: a new 10 every run. Most runs land from about 6.9 to 7.7, a little high or a little low. With 40, from about 7.1 to 7.5.
Want to type your own? The Python practice page has tasks and a notebook.
In your project
Your claim is about the rows in your file, so a reader needs to know how those rows were picked. None of the four project files is a random sample: each holds every row of a place and a time someone chose. ABOUT A7 says so, and the rubric’s Data Acquisition row asks for it. A big file also gets a SAMPLE tab: today’s simple random sample, 300 rows of your own CLEAN, which L27 uses on Wednesday.
Check Yourself
Answer each one before you look. The first two are from L24 and L22.
A sample’s mean is 12.4. The true mean is 13.0. What is the sample’s bias? L24
12.4 − 13.0 = −0.6
Sample mean minus true mean. Below 0: the sample ran low. 0.6 has the right size and the wrong sign.
A2 to B7 hold homeroom and sleep: 1, 6.5; 2, 8.0; 1, 7.5; 2, 9.0; 1, 6.0; 2, 7.0. What does =AVERAGEIF(A2:A7,2,B2:B7) show? L22
The homeroom 2 rows are 8.0, 9.0 and 7.0. 8 + 9 + 7 = 24, and 24 ÷ 3 = 8. AVERAGEIF uses only the rows that match.
A survey takes every 5th name on a roster of 200, from a random start among the first 5. Which way is this?
A random start, then every 5th: systematic. A stratified sample draws inside each group; a cluster sample takes whole groups.
A list has 360 names. A systematic sample takes 30 of them. Every how many names?
360 ÷ 30 = 12
The step is the list size divided by the sample size: a random start from 1 to 12, then every 12th name.
A club has 250 members: 100 juniors and 150 seniors. A stratified sample of 20 takes each group in proportion. How many seniors?
150 ÷ 250 × 20 = 12
Seniors are 150 of 250, so they get that share of the 20. The juniors get 8, and 12 + 8 = 20. 10 would be the same from each group, which is not in proportion.
Four homerooms of the same size average 6.0, 7.0, 8.0 and 9.0 hours of sleep. A cluster sample picks the homeroom that averages 9.0. What is its bias?
The true mean is (6 + 7 + 8 + 9) ÷ 4 = 7.5, since the homerooms are the same size. Bias: 9.0 − 7.5 = 1.5 hours. One cluster can miss by a lot when clusters differ.
Which is a cluster sample of a school’s students?
A cluster sample draws whole groups and takes everyone in them. Ten names from the roster is simple random; five from every grade is stratified.
A poll must ask 30 women and 30 men. Its interviewers ask whoever walks by. What goes wrong?
That is a quota sample: the counts are set, but a person chooses who fills them. People who walk by, and people an interviewer picks, are not like everyone. That is how the 1948 polls worked.
A town’s neighborhoods differ a lot in income, and each one must be in the survey. Which way fits best?
The groups differ and each must be in: stratify. One neighborhood is a cluster, and it would miss the others. Whoever answers first is a person choosing, not chance.
Project Checkpoint
SAMPLE · L27 uses it Wed 16 Dec · ABOUT A7 · part of P2, due Fri 18 Dec
Your claim holds for the rows your file holds. A7 tells a reader how those rows were picked, so nobody reads your file as a random sample of more than it is. SAMPLE is a random 300 of your own rows: on Wednesday you check a share on it against all of CLEAN.
| My dataset | CLEAN rows | SAMPLE? | ABOUT A7 |
| Colleges | 1,972 | No | Sampled: no. Every college that reported admissions to IPEDS for 2023. |
| Bikeshare trips | 36,574 | Yes | Sampled: no. Every trip that started at 99 stations in September 2025. |
| Weather | 10,958 | Yes | Sampled: no. Every day from 1995 to 2024, at one station. |
| Trail counters | 1,011 | No | Sampled: no. Every day of 2024, at 3 counters the county placed. |
The SAMPLE formula, in A2: =ARRAY_CONSTRAIN(SORT(FILTER(CLEAN!A2:B,ISNUMBER(CLEAN!B2:B)),RANDARRAY(COUNT(CLEAN!B2:B),1),TRUE),300,2). Read it from the inside out. FILTER keeps columns A and B of each row whose B is a number, so the empty rows below your data stay out. COUNT counts those rows, and RANDARRAY gives each one a random number. SORT puts the rows in that order: a shuffle. ARRAY_CONSTRAIN keeps the first 300 rows and both columns. Then freeze A2 to B301: copy, Edit > Paste special > Values only. 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.