Lucky, or Protected?
Three crew members escaped a virus that infected almost everyone else. Could that be luck? You'll use R.
The American Dynasty, a fishing trawler out of Seattle
| Crew members | How many | Infected on the trip |
|---|---|---|
| Had antibodies before the trip | 3 | 0 |
| No antibodies before the trip | 117 | 103 |
| All tested crew | 120 | 103 |
Antibodies are proteins the immune system makes after an infection. Source: a study by Jesse Bloom and colleagues in the Journal of Clinical Microbiology, as reported in the press.
1. Did the antibodies protect them?
All the crew tested negative before leaving port, but the virus got on board anyway. By the time the ship came back, 103 of the 117 crew without antibodies were infected. None of the 3 with antibodies were.
Maybe the antibodies protected those 3. Or maybe they were just lucky. To decide, we ask one question all the way through:
If antibodies did nothing at all, how often would those 3 particular people all escape, just by luck?
If the answer is “often”, luck explains it. If it is “almost never”, luck is a poor explanation.
Your gut guess: if antibodies did nothing, the 3 would all escape about…
Keep your guesses in mind. Steps 2 to 6 work out the real answer, two different ways, and step 7 compares it with your guess.
Two ways to describe “just luck”
(a) The hat model
Put all 120 names in a hat. Pull out 103 names, without putting any back. Those 103 people get sick.
Exactly 103 sick, every time. Only who gets sick is luck.
(b) The coin model
Each person flips their own weighted coin. It lands “sick” with chance 103/120 (about 86%).
Who gets sick and how many are both luck: usually somewhere around 95 to 111.
In both models the 3 antibody holders are treated exactly like everyone else. That is what “antibodies did nothing” means. Statisticians call this assumption the null hypothesis.
2. What does “just luck” mean?
To work out how often luck alone would spare the 3, we need a precise picture of luck. The workbook offers two, shown here. Read both.
The difference: the hat model takes the observed fact “103 of 120 got sick” as fixed. The coin model takes only the rate, 103/120, and lets the count vary.
Check you've got it. Which model allows that, by luck, 110 people get sick?
A small hat: 10 names, 3 pulled out
3. Warm-up: a small hat
Before the ship, a tiny version. 10 people, including two we care about, A and B. The hat model pulls out 3 names; those 3 get sick.
What's the chance that A and B are both spared? Follow one lucky path: every name pulled is someone other than A or B.
- Press Pull the next name. Read the fraction that appears: the chance that this name is not A or B.
- Do it three times. Watch how the top and bottom numbers change.
- To stay lucky every time, multiply the three fractions.
Why is the second fraction 7/9, not 8/10?
4. The ship, by multiplying fractions in R
Same idea, bigger hat: 120 names, 103 pulled out, and we want the 3 antibody holders never pulled.
- 1st name: 117 of the 120 names are not antibody holders, so 117/120.
- 2nd name: one name is gone, so 116/119. Then 115/118, 114/117, and so on.
- One fraction for each name pulled: 103 fractions. Multiply them all.
Three R tools you'll see
117:15 means the numbers 117, 116, 115, … down to 15.
c(8, 7, 6) / c(10, 9, 8) divides pair by pair: 8/10, 7/9, 6/8.
prod( … ) multiplies everything inside.
Your task: the tops of the fractions (top) are done for you. The bottoms (bottom) start at 120 and need to stop at the right number, so that there are also 103 of them.
- Press Run as it is. The first number is the warm-up answer from step 3. Then see the two lengths: 103 and 21. They don't match yet, so R also prints a warning and a wrong
p_a. That's expected. - Change
100on thelastline to the number wherebottomshould stop. - Run again. When both lengths say 103,
p_ais your answer.
Hint 1
bottom starts 3 higher than top (120 against 117), so it also ends 3 higher.Hint 2
top ends at 15, so bottom ends at 18. The line should read last <- 18.Read your answer
Look at the number R printed for p_a once both lengths say 103. In plain words, that is about…
5. Check it by rerunning the voyage 10,000 times
A second way to the same answer: let R play the hat model over and over, and count how often the 3 escape. This uses a for loop, which repeats the lines inside { }.
| Line | What it does |
|---|---|
| population <- 1:120 | The 120 crew, numbered. Numbers 1, 2 and 3 are the antibody holders. |
| for (i in 1:sims) { … } | Repeat the voyage 10,000 times. i counts which voyage it is. |
| sample(population, size, replace) | Pull names from the hat. size: how many names. replace: does a name go back in after it's pulled? |
| is.element(c(1, 2, 3), sick) | For each of persons 1, 2, 3: was their name pulled? Gives three TRUE/FALSE answers. |
| sum( … ) == 0 | Counts the TRUEs. == 0 asks “were none of the 3 pulled?”: TRUE means all 3 escaped. |
| mean(storage) | The share of voyages that gave TRUE. (The mean of TRUE/FALSE values is the share of TRUEs, like a 0/1 dummy variable.) |
Your task: the sample(…) line pulls the wrong number of names, and puts them back. Fix both values.
- Press Run as it is.
spared_acomes out near 0.97: pulling 1 name rarely hits the 3. - Change
size = 1to the number of names the hat model pulls out. - Change
replace = TRUEtoFALSE: nobody can get sick twice, so a pulled name stays out. - Run again (it takes a few seconds) and compare
spared_awithp_afrom step 4.
Hint 1
How many people get sick in the hat model? That's how many names to pull.Hint 2
The line should readsick <- sample(population, size = 103, replace = FALSE).Compare
spared_a is close to p_a from step 4, but not equal to it. Why?
6. The coin model, by the multiplication rule
Now model (b): each person flips their own weighted coin, “sick” with chance 103/120. One person's coin doesn't affect anyone else's. That makes the 3 people independent.
- Chance one person is spared: 1 − 103/120 = 17/120, about 0.142.
- From the pre-class reading, for independent events: P(A and B and C) = P(A) × P(B) × P(C).
- So the chance all 3 are spared is
p_spare×p_spare×p_spare. In R,x^2means x × x, andx^3means x × x × x.
Real infections aren't independent: a sick bunkmate makes you more likely to get sick. The coin model ignores that to keep things simple.
Your task: replace the one NA with how many people must all be spared, then Run.
Hint 1
There are 3 antibody holders, and all of them must be spared.Hint 2
The line should readp_b <- p_spare^3.If antibodies did nothing: chance all 3 escape
| Model | Exact | Simulated | About 1 time in |
|---|---|---|---|
| (a) Hat | 0.0024 | 0.0023 | 413 |
| (b) Coins | 0.0028 | – | 352 |
The simulated value is from step 5: set.seed(350) and 10,000 voyages.
7. The verdict
Both models say the same thing: if antibodies did nothing, all 3 would escape only about 1 time in 350 to 400. Compare that with your guess in step 1.
As a group: what can you conclude?
8. Where else could it be luck?
As a group: pick a small group from your own studies or life that did strikingly better or worse than everyone around it (a study group in which everyone passed a hard exam, say, but find your own). How would you set up “just luck” for it as a hat or a coin model, with which three numbers? If luck turned out to be a poor explanation, what would you check before crediting the reason you suspect?
Points to compare
- A usable luck model names three numbers, like 120 crew, 103 sick and 3 antibody holders in step 2: how many people in all, how many had the outcome, and how many are in the small group.
- The hat fits when the total with the outcome is fixed (steps 2, 5); the coins fit when each person’s chance is the same and independent of everyone else’s (step 6). For a small group drawn from a big pool, the two give close answers (the table in step 7).
- A tiny chance makes luck a poor explanation, not an impossible one, and it leaves other explanations open. Check how the small group differs from the rest: a study group that chose its own members, or antibody holders who slept or worked apart from the crew (step 7).
You should now be able to:
- state a “just luck” assumption (a null hypothesis) as a model you can calculate with (step 2);
- find a probability by multiplying a chain of fractions (steps 3, 4) or, for independent events, with the multiplication rule (step 6);
- check a calculation by simulation, and expect the simulation to land close, not exactly (step 5);
- judge from a small chance that luck is a poor explanation, while other explanations stay open (step 7).
Assumptions
- dataFrom the course workbook's excerpt of a news report on Bloom and colleagues' study: 120 crew tested before and after; 3 had neutralizing antibodies before the trip and none of them were infected; 103 of the other 117 were.
- simplificationBoth models assume antibodies did nothing (the null hypothesis) and that test results are correct.
- distributionHat model: the 103 infected are a random 103 of the 120, every set equally likely. Coin model: each person is infected independently with chance 103/120.
- parameterSimulations use set.seed(350) and 10,000 voyages.
Left out: p-values and formal hypothesis tests by name, and how contagion between crew members would change the answer.