# Birthday paradox: How to estimate the probability of two or more people in a group of 30 sharing a birthday?

I might be overthinking this. I generated the output in R and 5 of my 10 samples were successful, so that's 50%. Given that, if I am to estimate the probability of two or more people in a group of 30 sharing a birthday, what is my total sample? Should I be using combinations?

How are you generating your birthdays? To generate 23 birthdays:

dates = sample(1:365, 23, replace = TRUE)


To see if 2 or more share the same birthday:

length(dates) != length(unique(dates)) # TRUE if there are duplicates


How often is the above TRUE?

dupe_count = 0
runs = 1000000
for (i in 1:runs) {
dates = sample(1:365, 23, replace = TRUE)
if (length(dates) != length(unique(dates))) {
dupe_count = dupe_count + 1
}
}
print(dupe_count / runs)

[1] 0.508158


This closely matches the theoretical value of 50.7% in the wikipedia page

• With the expression round(runif(23, 1, 365)) you do not generate dates uniformly: the chances of $1$ or $365$ are only half the chances of any other numbers between them. This error won't noticeably affect the answer in this particular example, but repeating it in other situations with smaller ranges of numbers could introduce serious errors that might be difficult to detect. Interestingly, a two-sided test of your result yields p=3.6%, intimating it might be wrong: it's a tiny bit too large. – whuber Feb 8 '18 at 22:53
• @whuber Good catch. I replaced it with sample(1:365, 23, replace = TRUE) – reisner Feb 8 '18 at 23:12
• p = 1-cumprod(seq(365,266,by=-1) / 365) plot(1:100,p,type='o') abline(h=0.5,col='red') – HEITZ Feb 8 '18 at 23:55