3 Birthdays

This code computes the probability that three (and possibly more) people in a group have the same birthday. The simple case of having two (or more) with the same birthday is widely discussed; it is one minus the probability that no one shares a birthday.  Having three birthdays in a day has to take into account one minus no one sharing a birthday and no two people on any days sharing a birthday.   For all of the math, there is a website: http://mathforum.org/library/drmath/view/56650.html  Make sure you read all of the corrections to the original post.  But here is the R code to go with it.

n=50    #group size, must be even
K=n/2
## one birthday per day
one=1
for(i in 1:n){  one=one*(365-i+1)/(365) }
## two share a birthday
1-one
### three share
pnk=0
for(k in 1:K)
{  mult2=1; mult3=1
   for(i in 1:(n-2*k)){  mult3=mult3* (365-k-i+1)/365 }
   mult3=mult3/(365^(2*k))
   for(i in 1:(2*k)){ mult2=mult2*  (n-i+1)/2}
   mult2=mult2*k^(n-2*k)
   mult22=1
   ind=seq((n-2*k+2), n, length=(n-(n-2*k+2))/2+1)
   for(i in ind){  mult22=mult22*choose(i,2) }
   pnk=pnk+choose(365,k)*mult22*mult3
}
## three share
1-one-pnk

Tags: