On Sun, 28 Sep 2008, J?rg Gro? wrote:

Hi,

I tried to calculate the formula for the birthday problem
(the probability that at least two people out of a group of n people share the same birthday)

But the factorial-function allows me only to calculate factorials up to 170.


You might want to look at the pbirthday() and qbirthday() functions and the examples on their help page. The function implements Diaconis & Mosteller's approximation, which works for different values of two as well as of n and 365. One of the examples compares to the exact calculation, which it computes as x2<- 1-sapply(10:100, function(n)prod((365:(365-n+1))/rep(365,n)))

This is obviously slow compared to the formula with factorials, but it does only take two milliseconds on my laptop, so it's not *that* slow. The phrase "premature optimization" springs to mind.


        -thomas
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to