[Rd] pbirthday() for larger number of classes

Marius Hofert m@r|u@@ho|ert @end|ng |rom uw@ter|oo@c@
Sat May 23 01:07:39 CEST 2020


... and one should include the pigeonhole principle:

pbirthday2 <- function(n, classes = 365) {
    c <- classes # as pbirthday()
    if(n >= 2) {
        if(n > classes) 1 else -expm1(sum(log1p(-(1:(n-1))/classes)))
    } else 0
}



More information about the R-devel mailing list