Block 1: Counting and the birthday problem
Week 9 · Probability I · Imai §6.1 · about 4 min
NoteHow this works
Run each cell with Run Code, look at the output, then answer the question at the end of the block. Every cell is editable; Start Over resets it. Errors are information: read them.
1. Counting rules in R
factorial(5) = permutations of 5 objects; choose(5, 2) = combinations; choose(84, 6) = a lottery with 6 numbers out of 84.
2. The birthday problem
P(at least two of k people share a birthday) = 1 - 365! / ((365 - k)! 365^k). We use logs to avoid overflow of 365!.
3. Monte Carlo simulation of the same quantity
Conclusion: How many people do you need for a better-than-50% chance of a shared birthday?
With only 23 people the probability is already 50.7% (the simulation gives about 0.51, close but not exact); with 57 it exceeds 99%. Intuition is poor because 23 people form 253 pairs.