Skip to content
Permalink
Browse files
MATH-1644: Prevent computed probability from exceeding 1.
  • Loading branch information
Gilles Sadowski committed Apr 9, 2022
1 parent cfb9bda commit f067b2b4bae9d7690a84cd65bedd45bca5691441
Showing 2 changed files with 8 additions and 1 deletion.
@@ -138,7 +138,7 @@ public double binomialTest(int numberOfTrials, int numberOfSuccesses, double pro
if (criticalValueLow == criticalValueHigh) {
pTotal += pLow;
} else {
pTotal += 2 * pLow;
pTotal += 2 * Math.nextDown(pLow);
}
criticalValueLow++;
criticalValueHigh--;
@@ -126,4 +126,11 @@ public void testBinomialTestAcceptReject() {
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);
}
}

0 comments on commit f067b2b

Please sign in to comment.