haskell / statistics

A fast, high quality library for computing with statistics in Haskell.
http://hackage.haskell.org/package/statistics
BSD 2-Clause "Simplified" License
300 stars 68 forks source link

Binomial: Implement more accurate complCumulative. #193

Closed lorinder closed 1 year ago

lorinder commented 1 year ago

The previous implementation was simply 1 - cumulative, with the obvious accuracy problems when the the cumulative value is close to 1. The new implementation uses the symmetry of the incomplete Beta function to achieve more accurate numbers.

Example of the problem:

ghci> p = 16785/32768 :: Double
ghci> complCumulative (binomial 283 p) 232
0.0

The correct answer in this case is 8.565988198569857e-28.

Shimuuar commented 1 year ago

Thank you! I'm glad that you take numerical bugs seriously