Repository navigation
STATISTICS-104: Fix comparisons with rounding errors - #142
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #142 +/- ##
============================================
+ Coverage 99.62% 99.71% +0.09%
+ Complexity 2441 659 -1782
============================================
Files 116 122 +6
Lines 6087 6785 +698
Branches 951 1043 +92
============================================
+ Hits 6064 6766 +702
+ Misses 10 6 -4
Partials 13 13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Rounding errors in values used for comparisons create incorrect p-value computations in inference tests: BinomialTest; FisherExactTest; and UnconditionedExactTest. Update the binomial distribution log probability computation. This now handles symmetry in x or (n - x); sums terms in magnitude order; and detects a bimodal distribution and returns only 1 value for both modes. This impacts both the binomial distribution, and the hypergeometric distribution. The binomial distribution is now symmetric at the mode for bimodal distributions; and is symmetric when the probability of success is 0.5. The hypergeometric distribution is defined by the log probability function for its PMF and cumulative probability functions. It sums 3 binomial log probabilities. This is now done in magnitude order. A bimodal distribution is detected and the value of the upper mode in this case is always used. The PMF now exploits parameter symmetry in the number of successes (K) and sample size (n): f(k; N, K, n) = f(k; N, n, K) where N is the population size. The K or n that chooses a binomial probability closest to 0.5 is chosen. This ensures the distribution is symmetric when p=0.5. A bug in the BinomialTest and FisherExactTest two-sided p-value computation is now fixed at the mode. When k=mode then all other values have equal or lower probability and the significance result is 1.0. A bug in the BinomialTest where one side of a symmetric binomial distribution computed values p(n-k) != p(k) is now fixed. The FisherExactTest computes p-values for all possible 2x2 contingency tables using the hypergeometric distribution. Because this now supports parameter symmetry two symmetric contingency tables have the same p-value. This also fixes Boschloo's method in the UnconditionedExactTest which computes Fisher p-values as a score to compare candidate contingency tables. The Z pooled/unpooled method of the UnconditionedExactTest has been updated to use rational numbers for p-values and exploit symmetry to compute the Z scores. Two scores from symmetric contingency tables now have the same magnitude.
aherbert
force-pushed
the
statistics-104-tolerance
branch
from
December 4, 2026 07:41
2c01287 to
7fe52db
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rounding errors in values used for comparisons create incorrect p-value computations in inference tests: BinomialTest; FisherExactTest; and UnconditionedExactTest.
Update the binomial distribution log probability computation. This now handles symmetry in x or (n - x); sums terms in magnitude order; and detects a bimodal distribution and returns only 1 value for both modes. This impacts both the binomial distribution, and the hypergeometric distribution.
The binomial distribution is now symmetric at the mode for bimodal distributions; and is symmetric when the probability of success is 0.5.
The hypergeometric distribution is defined by the log probability function for its PMF and cumulative probability functions. It sums 3 binomial log probabilities. This is now done in magnitude order. A bimodal distribution is detected and the value of the upper mode in this case is always used. The PMF now exploits parameter symmetry in the number of successes (K) and sample size (n):
f(k; N, K, n) = f(k; N, n, K)
where N is the population size. The K or n that chooses a binomial probability closest to 0.5 is chosen. This ensures the distribution is symmetric when p=0.5.
A bug in the BinomialTest and FisherExactTest two-sided p-value computation is now fixed at the mode. When k=mode then all other values have equal or lower probability and the significance result is 1.0.
A bug in the BinomialTest where one side of a symmetric binomial distribution computed values p(n-k) != p(k) is now fixed.
The FisherExactTest computes p-values for all possible 2x2 contingency tables using the hypergeometric distribution. Because this now supports parameter symmetry two symmetric contingency tables have the same p-value.
This also fixes Boschloo's method in the UnconditionedExactTest which computes Fisher p-values as a score to compare candidate contingency tables.
The Z pooled/unpooled method of the UnconditionedExactTest has been updated to use rational numbers for p-values and exploit symmetry to compute the Z scores. Two scores from symmetric contingency tables now have the same magnitude.
mvn; that'smvnon the command line by itself.