Skip to content

STATISTICS-104: Use a tolerance for comparisons - #141

Closed
aherbert wants to merge 1 commit into
apache:masterfrom
aherbert:statistics-104-tolerance
Closed

aherbert wants to merge 1 commit into
apache:masterfrom
aherbert:statistics-104-tolerance

Conversation

@aherbert

Copy link
Copy Markdown
Contributor

The BinomialTest is updated to use a tolerance of 1e-15 when testing if p(i) <= p(k). This avoids small ULP errors when probabilities should be equal causing the observation i to be missed from the p-value sum. The binomial distribution probability is very accurate so a small tolerance can be used.

The FisherExactTest is updated to use a 1e-14 tolerance for the hypergeometric distribution probabilities. This probability is a sum of 3 binomial log probabilities with cancellation.

The UnconditionedExactTest is updated to use the same 1e-14 tolerance when computing Fisher p-values. A tolerance is also used when comparing the Fisher p-values in Boschloo's test.

The computation of Z values in the UnconditionedExactTest has been updated to reduce rounding errors. A ULP tolerance is used when comparing Z values.

The BinomialTest is updated to use a tolerance of 1e-15 when testing if
p(i) <= p(k). This avoids small ULP errors when probabilities should be
equal causing the observation i to be missed from the p-value sum. The
binomial distribution probability is very accurate so a small tolerance
can be used.

The FisherExactTest is updated to use a 1e-14 tolerance for the
hypergeometric distribution probabilities. This probability is a sum of
3 binomial log probabilities with cancellation.

The UnconditionedExactTest is updated to use the same 1e-14 tolerance
when computing Fisher p-values. A tolerance is also used when comparing
the Fisher p-values in Boschloo's test.

The computation of Z values in the UnconditionedExactTest has been
updated to reduce rounding errors. A ULP tolerance is used when
comparing Z values.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.70%. Comparing base (d524259) to head (6a5c37e).
⚠️ Report is 340 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #141      +/-   ##
============================================
+ Coverage     99.62%   99.70%   +0.08%     
+ Complexity     2441      672    -1769     
============================================
  Files           116      122       +6     
  Lines          6087     6779     +692     
  Branches        951     1035      +84     
============================================
+ Hits           6064     6759     +695     
+ Misses           10        6       -4     
- Partials         13       14       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aherbert

aherbert commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Tolerances may not be required. Further investigation is in progress to determine if cases can be found that still fail after accuracy has been improved in the binomial and hypergeometric distributions. Closing for now.

@aherbert aherbert closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants