Computes answers to a generalised birthday paradox problem.
pbirthday
computes the probability of a coincidence and
qbirthday
computes the smallest number of observations needed
to have at least a specified probability of coincidence.
1 2 
classes 
How many distinct categories the people could fall into 
prob 
The desired probability of coincidence 
n 
The number of people 
coincident 
The number of people to fall in the same category 
The birthday paradox is that a very small number of people, 23, suffices to have a 50–50 chance that two or more of them have the same birthday. This function generalises the calculation to probabilities other than 0.5, numbers of coincident events other than 2, and numbers of classes other than 365.
The formula used is approximate for coincident > 2
. The
approximation is very good for moderate values of prob
but less
good for very small probabilities.
qbirthday 
Minimum number of people needed for a probability of at least

pbirthday 
Probability of the specified coincidence. 
Diaconis, P. and Mosteller F. (1989) Methods for studying coincidences. J. American Statistical Association, 84, 853–861.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  require(graphics)
## the standard version
qbirthday() # 23
## probability of > 2 people with the same birthday
pbirthday(23, coincident = 3)
## examples from Diaconis & Mosteller p. 858.
## 'coincidence' is that husband, wife, daughter all born on the 16th
qbirthday(classes = 30, coincident = 3) # approximately 18
qbirthday(coincident = 4) # exact value 187
qbirthday(coincident = 10) # exact value 1181
## same 4digit PIN number
qbirthday(classes = 10^4)
## 0.9 probability of three or more coincident birthdays
qbirthday(coincident = 3, prob = 0.9)
## Chance of 4 or more coincident birthdays in 150 people
pbirthday(150, coincident = 4)
## 100 or more coincident birthdays in 1000 people: very rare
pbirthday(1000, coincident = 100)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.