MATH-1401: Branch added to prevent passing invalid input to "FDistribution".

Thanks to Michele De Stefano for circumscribing the issue.
This commit is contained in:
Gilles Sadowski 2019-04-16 12:54:04 +02:00
parent 8694f8478b
commit 53d9c7fbfb
3 changed files with 18 additions and 5 deletions

View File

@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="4.0" date="XXXX-XX-XX" description="">
<action dev="erans" type="fix" issue="MATH-1401">
"ClopperPearsonInterval": Fixed case where number of trials equals number of successes.
</action>
<action dev="erans" type="add" issue="MATH-1477" due-to="Chee Sing Lee">
"MillerUpdatingRegression": Fixed "ArrayIndexOutOfBounds" exception.
</action>

View File

@ -46,11 +46,15 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
lowerBound = numberOfSuccesses /
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
2 * (numberOfTrials - numberOfSuccesses));
final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
if (numberOfSuccesses != numberOfTrials) {
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
2 * (numberOfTrials - numberOfSuccesses));
final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
} else {
upperBound = 1;
}
}
return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);

View File

@ -40,4 +40,10 @@ public class ClopperPearsonIntervalTest extends BinomialConfidenceIntervalAbstra
Assert.assertEquals(0.1248658, confidenceInterval.getUpperBound(), 1E-5);
}
@Test
public void testMath1401() {
ConfidenceInterval interval = new ClopperPearsonInterval().createInterval(1, 1, 0.95);
Assert.assertEquals(0.025, interval.getLowerBound(), 1e-16);
Assert.assertEquals(1, interval.getUpperBound(), 0d);
}
}