Perform computation/allocation only if needed.
Thanks to Dave Brosius.
This commit is contained in:
parent
362ab2bc41
commit
fc9d93db68
|
@ -35,19 +35,18 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
|
|||
IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
|
||||
double lowerBound = 0;
|
||||
double upperBound = 0;
|
||||
final double alpha = (1.0 - confidenceLevel) / 2.0;
|
||||
|
||||
final FDistribution distributionLowerBound = new FDistribution(2 * (numberOfTrials - numberOfSuccesses + 1),
|
||||
2 * numberOfSuccesses);
|
||||
if (numberOfSuccesses > 0) {
|
||||
final double alpha = 0.5 * (1 - confidenceLevel);
|
||||
|
||||
final FDistribution distributionLowerBound = new FDistribution(2 * (numberOfTrials - numberOfSuccesses + 1),
|
||||
2 * numberOfSuccesses);
|
||||
final double fValueLowerBound = distributionLowerBound.inverseCumulativeProbability(1 - alpha);
|
||||
lowerBound = numberOfSuccesses /
|
||||
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
|
||||
}
|
||||
|
||||
final FDistribution distributionUpperBound = new FDistribution(2 * (numberOfSuccesses + 1),
|
||||
2 * (numberOfTrials - numberOfSuccesses));
|
||||
if (numberOfSuccesses > 0) {
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue