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.
qbirthday(prob = 0.5, classes = 365, coincident = 2) pbirthday(n, classes = 365, coincident = 2)
- How many distinct categories the people could fall into
- The desired probability of coincidence
- The number of people
- 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.
- Minimum number of people needed for a probability of at least
kor more of them have the same one out of
- Probability of the specified coincidence.
Diaconis, P. and Mosteller F. (1989) Methods for studying coincidences. J. American Statistical Association, 84, 853--861.
Prior to R 2.14.0 the approximate formula was used even for
coincident = 2.
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 4-digit 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)
Documentation reproduced from R 2.15.3. License: GPL-2.