Bug 51083 - Mathematical error in BINOMDIST
Summary: Mathematical error in BINOMDIST
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
3.5.4 release
Hardware: All All
: low normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: needsDevEval
: 51087 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-06-14 09:03 UTC by Jacques MAROT
Modified: 2015-12-16 22:31 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
experimental spreadsheet to find error with formula BINOMDIST = (391, 462, 0.8, TRUE ()) (650.50 KB, application/vnd.oasis.opendocument.spreadsheet)
2012-06-14 09:03 UTC, Jacques MAROT
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacques MAROT 2012-06-14 09:03:12 UTC
Created attachment 63034 [details]
experimental spreadsheet to find error with formula   BINOMDIST = (391, 462, 0.8, TRUE ())

I find abberrants results in open-office-calc on the binomial distribution B(n,p). Only certain values ​​of n and p in a timely manner produce random errors.
This calculation.

   BINOMDIST = (391, 462, 0.8, TRUE ())

should give the probability of obtaining  x=391  success on n=462  random experiment with two issues and success probability p = 0.8. The real calculation in various formal-calculator  Texas or Casio gives 0.995603391, libre-office gives  0,826 .... (Serious difference!)

While a formal calculator gives a probability p with 1-p< 10 ^ {-30} as soon as x>420, libre-office gives results lower than 0.830 for all n <462.
It's only for x = 462 that we  found the expected result: 1.

Most troubling is that the calculations of libre-office  become again consistent for n <> 462 and p = 0.801 and p = 0799. I have noticed this inconsistency as rare as integer values ​​n = 462, accidentally encountered by testing the binomial distribution under libre-office with this spreadsheet attached (error in cell J7 ).

P, S,: functionality on the same sheet in excel  gives good results!?
Comment 1 Andras Timar 2012-06-20 01:41:40 UTC
*** Bug 51087 has been marked as a duplicate of this bug. ***
Comment 2 Joel Madero 2012-11-21 21:50:22 UTC
Confirmed, also can verify using this calculator http://stattrek.com/online-calculator/binomial.aspx

Marking as NEW and Prioritizing

Normal: Can prevent high quality professional work for anyone doing stats

Low: Not many people would be affected

Thanks for reporting, trying to find someone to tackle it
Comment 3 Werner 2012-12-03 08:56:07 UTC
This bug additionally affects the functions B, CritBinom and NegBinomDist.

In these functions the precision is bad when pow(1-p,n) is a denormalized number.
If pow(1-p,n) is zero an alternative using pow(p,n) is used.

For double, 
  numeric_limits<double>::min() = 2.22507e-308
  numeric_limits<double>::denorm_min() = 4.94066e-324
  0.2^462 = 9.88131e-324
so 0.2^462 has nearly no significant digits.

Changed to select the calculation method depending on size of p, see
https://gerrit.libreoffice.org/1213
Comment 4 Joel Madero 2012-12-03 18:19:57 UTC
Nice catch, I was going to take a shot at this one but I'm glad that it's solved.
Comment 5 Eike Rathke 2012-12-10 14:17:40 UTC
This may have been already fixed by http://cgit.freedesktop.org/libreoffice/core/commit/?id=5cf55f5b7800e443c4f087e72ae05abc8b7fef45

The change submitted as https://gerrit.libreoffice.org/1213 clashes with those code changes.

Please check in a recent daily build or 4.0.0.beta1 if the problem is solved.
Comment 6 Werner 2012-12-12 15:09:02 UTC
The bug is fixed, tested with LibreOffice Version 4.0.0.0.beta1 (Build ID: 87906242e87d3ddb2ba9827818f2d1416d80cc7) on Windows XP and Version 4.1.0.0.alpha0 on Debian.
Comment 7 Robinson Tryon (qubit) 2015-12-16 22:31:16 UTC
Migrating Whiteboard tags to Keywords: (ProposedEasyHack -> needsDevEval)
[NinjaEdit]