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:
parent
8694f8478b
commit
53d9c7fbfb
|
@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
|
||||||
</release>
|
</release>
|
||||||
|
|
||||||
<release version="4.0" date="XXXX-XX-XX" description="">
|
<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">
|
<action dev="erans" type="add" issue="MATH-1477" due-to="Chee Sing Lee">
|
||||||
"MillerUpdatingRegression": Fixed "ArrayIndexOutOfBounds" exception.
|
"MillerUpdatingRegression": Fixed "ArrayIndexOutOfBounds" exception.
|
||||||
</action>
|
</action>
|
||||||
|
|
|
@ -46,11 +46,15 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
|
||||||
lowerBound = numberOfSuccesses /
|
lowerBound = numberOfSuccesses /
|
||||||
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
|
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
|
||||||
|
|
||||||
|
if (numberOfSuccesses != numberOfTrials) {
|
||||||
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
|
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
|
||||||
2 * (numberOfTrials - numberOfSuccesses));
|
2 * (numberOfTrials - numberOfSuccesses));
|
||||||
final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
|
final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
|
||||||
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
|
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
|
||||||
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
|
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
|
||||||
|
} else {
|
||||||
|
upperBound = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
|
return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
|
||||||
|
|
|
@ -40,4 +40,10 @@ public class ClopperPearsonIntervalTest extends BinomialConfidenceIntervalAbstra
|
||||||
Assert.assertEquals(0.1248658, confidenceInterval.getUpperBound(), 1E-5);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue