| bin(x,n,p) = | n! | px (1-p)n-x. |
| x!(n-x)! |
Computer packages, including S-Plus and the statistics toolbox in Matlab,
evaluate the probabilities using the representation
This is better than direct evaluation, but loss-of-precision can still occur, typically becoming noticeable for n about 106. To overcome this limitation, I developed an alternative set of algorithms, based on saddle point methods and Stirling's formula, that significantly improve accuracy in large samples.
Similar problems occur for many common distributions. My DBinom library provides a stable implementation for the Binomial, Poisson, Hypergeometric, Gamma (incl. Chi-Square), Student's t, F, negative Binomial and Beta distributions.
The R programming environment incorporates a version of this code.
The saddle point algorithm (indicated by +) obtains the full accuracy of computer double precision (about 16 digits) for large n. The `classic' algorithm obtains similar results for n up to 107, then loses precision after that.