MATH-1644: Prevent computed probability from exceeding 1.

This commit is contained in:
Gilles Sadowski 2022-04-09 14:07:03 +02:00
parent 69c120c015
commit 3c30a6d520
2 changed files with 8 additions and 1 deletions

View File

@ -138,7 +138,7 @@ public class BinomialTest {
if (criticalValueLow == criticalValueHigh) {
pTotal += pLow;
} else {
pTotal += 2 * pLow;
pTotal += 2 * Math.nextDown(pLow);
}
criticalValueLow++;
criticalValueHigh--;

View File

@ -126,4 +126,11 @@ public class BinomialTestTest {
Assert.assertFalse(testStatistic.binomialTest(trials, successes, probability, AlternativeHypothesis.GREATER_THAN, alpha01));
Assert.assertFalse(testStatistic.binomialTest(trials, successes, probability, AlternativeHypothesis.LESS_THAN, alpha05));
}
@Test
public void testMath1644() {
final BinomialTest bt = new BinomialTest();
final double pval = bt.binomialTest(10, 5, 0.5, AlternativeHypothesis.TWO_SIDED);
Assert.assertTrue("pval=" + pval, pval <= 1);
}
}