What is the probability that at least two people share the same birhtday in this room?
Is is \(\frac{1}{365} \times 25 = 0.0684932\)
But actually when we compute the math. We get an surprising result:
\[\begin{align} 1 - \bar p(n) &= 1 \times \left(1-\frac{1}{365}\right) \times \left(1-\frac{2}{365}\right) \times \cdots \times \left(1-\frac{n-1}{365}\right) \nonumber \\ &= \frac{ 365 \times 364 \times \cdots \times (365-n+1) }{ 365^n } \nonumber \\ &= \frac{ 365! }{ 365^n (365-n)!} = \frac{n!\cdot\binom{365}{n}}{365^n}\\ p(n= 25) &= 0.569 \nonumber \end{align}\]1 - Simulate 10,000 rooms with n = 25 random birthdays, and store the results in matrix where each row represents a room.
2 - For each room (row) compute the number of unique birthdays.
3 - Compute the average number of times a room has 25 unique birthdays, across 10,000 simulations, and report the complement.
birthday.prob = function(n.pers, n.sims) {
# simulate birthdays
birthdays = matrix(round(runif(n.pers * n.sims, 1,
365)), nrow = n.sims,
ncol = n.pers)
# for each room (row) get unique birthdays
unique.birthdays = apply(birthdays, 1, unique)
# Indicator with 1 if all are unique birthdays
all.different = (lapply(unique.birthdays, length) == n.pers) # Compute average time all have different birthdays
result = 1 - mean(all.different)
return(result)
}
n.pers.param = n.pers
n.sims.param = 1e4
birthday.prob(n.pers.param,n.sims.param)
## [1] 0.5667
Ok, I am convinced that the probability of atl least two people in this room share the same birthday is 0.5698