Use survival probability

This commit is contained in:
aherbert 2022-12-02 13:30:10 +00:00
parent 6d767220ed
commit 7ed772e474
10 changed files with 26 additions and 26 deletions

View File

@ -122,7 +122,7 @@ public class BinomialTest {
final BinomialDistribution distribution = BinomialDistribution.of(numberOfTrials, probability);
switch (alternativeHypothesis) {
case GREATER_THAN:
return 1 - distribution.cumulativeProbability(numberOfSuccesses - 1);
return distribution.survivalProbability(numberOfSuccesses - 1);
case LESS_THAN:
return distribution.cumulativeProbability(numberOfSuccesses);
case TWO_SIDED:

View File

@ -157,7 +157,7 @@ public class ChiSquareTest {
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
ChiSquaredDistribution.of(expected.length - 1.0);
return 1.0 - distribution.cumulativeProbability(chiSquare(expected, observed));
return distribution.survivalProbability(chiSquare(expected, observed));
}
/**
@ -330,7 +330,7 @@ public class ChiSquareTest {
double df = ((double) counts.length -1) * ((double) counts[0].length - 1);
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution = ChiSquaredDistribution.of(df);
return 1 - distribution.cumulativeProbability(chiSquare(counts));
return distribution.survivalProbability(chiSquare(counts));
}
/**
@ -532,7 +532,7 @@ public class ChiSquareTest {
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
ChiSquaredDistribution.of((double) observed1.length - 1);
return 1 - distribution.cumulativeProbability(
return distribution.survivalProbability(
chiSquareDataSetsComparison(observed1, observed2));
}

View File

@ -155,7 +155,7 @@ public class GTest {
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
ChiSquaredDistribution.of(expected.length - 1.0);
return 1.0 - distribution.cumulativeProbability(g(expected, observed));
return distribution.survivalProbability(g(expected, observed));
}
/**
@ -186,7 +186,7 @@ public class GTest {
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
ChiSquaredDistribution.of(expected.length - 2.0);
return 1.0 - distribution.cumulativeProbability(g(expected, observed));
return distribution.survivalProbability(g(expected, observed));
}
/**
@ -476,7 +476,7 @@ public class GTest {
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final ChiSquaredDistribution distribution =
ChiSquaredDistribution.of((double) observed1.length - 1);
return 1 - distribution.cumulativeProbability(
return distribution.survivalProbability(
gDataSetsComparison(observed1, observed2));
}

View File

@ -104,9 +104,9 @@ public class OneWayAnova {
* {@link org.apache.commons.statistics.distribution.FDistribution
* commons-math F Distribution implementation} to estimate the exact
* p-value, using the formula<pre>
* p = 1 - cumulativeProbability(F)</pre>
* where <code>F</code> is the F value and <code>cumulativeProbability</code>
* is the commons-math implementation of the F distribution.
* p = survivalProbability(F)</pre>
* where <code>F</code> is the F value and <code>survivalProbability = 1 - cumulativeProbability</code>
* is the commons-statistics implementation of the F distribution.
*
* @param categoryData <code>Collection</code> of <code>double[]</code>
* arrays each containing data for one category
@ -126,7 +126,7 @@ public class OneWayAnova {
// No try-catch or advertised exception because args are valid
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final FDistribution fdist = FDistribution.of(a.dfbg, a.dfwg);
return 1.0 - fdist.cumulativeProbability(a.f);
return fdist.survivalProbability(a.f);
}
/**
@ -142,9 +142,9 @@ public class OneWayAnova {
* {@link org.apache.commons.statistics.distribution.FDistribution
* commons-math F Distribution implementation} to estimate the exact
* p-value, using the formula<pre>
* p = 1 - cumulativeProbability(F)</pre>
* where <code>F</code> is the F value and <code>cumulativeProbability</code>
* is the commons-math implementation of the F distribution.
* p = survivalProbability(F)</pre>
* where <code>F</code> is the F value and <code>survivalProbability = 1 - cumulativeProbability</code>
* is the commons-statistics implementation of the F distribution.
*
* @param categoryData <code>Collection</code> of {@link SummaryStatistics}
* each containing data for one category
@ -167,7 +167,7 @@ public class OneWayAnova {
final AnovaStats a = anovaStats(categoryData, allowOneElementData);
// pass a null rng to avoid unneeded overhead as we will not sample from this distribution
final FDistribution fdist = FDistribution.of(a.dfbg, a.dfwg);
return 1.0 - fdist.cumulativeProbability(a.f);
return fdist.survivalProbability(a.f);
}
/**
@ -221,9 +221,9 @@ public class OneWayAnova {
* {@link org.apache.commons.statistics.distribution.FDistribution
* commons-math F Distribution implementation} to estimate the exact
* p-value, using the formula<pre>
* p = 1 - cumulativeProbability(F)</pre>
* where <code>F</code> is the F value and <code>cumulativeProbability</code>
* is the commons-math implementation of the F distribution.
* p = survivalProbability(F)</pre>
* where <code>F</code> is the F value and <code>survivalProbability = 1 - cumulativeProbability</code>
* is the commons-statistics implementation of the F distribution.
* <p>True is returned iff the estimated p-value is less than alpha.</p>
*
* @param categoryData <code>Collection</code> of <code>double[]</code>

View File

@ -35,7 +35,7 @@ public class AgrestiCoullInterval implements BinomialConfidenceInterval {
IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
final double alpha = (1.0 - confidenceLevel) / 2;
final NormalDistribution normalDistribution = NormalDistribution.of(0, 1);
final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
final double z = normalDistribution.inverseSurvivalProbability(alpha);
final double zSquared = JdkMath.pow(z, 2);
final double modifiedNumberOfTrials = numberOfTrials + zSquared;
final double modifiedSuccessesRatio = (1.0 / modifiedNumberOfTrials) * (numberOfSuccesses + 0.5 * zSquared);

View File

@ -42,7 +42,7 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
if (numberOfSuccesses > 0) {
final FDistribution distributionLowerBound = FDistribution.of(2.0 * (numberOfTrials - numberOfSuccesses + 1),
2.0 * numberOfSuccesses);
final double fValueLowerBound = distributionLowerBound.inverseCumulativeProbability(1 - alpha);
final double fValueLowerBound = distributionLowerBound.inverseSurvivalProbability(alpha);
lowerBound = numberOfSuccesses /
(numberOfSuccesses + (numberOfTrials - numberOfSuccesses + 1) * fValueLowerBound);
}
@ -50,7 +50,7 @@ public class ClopperPearsonInterval implements BinomialConfidenceInterval {
if (numberOfSuccesses < numberOfTrials) {
final FDistribution distributionUpperBound = FDistribution.of(2.0 * (numberOfSuccesses + 1),
2.0 * (numberOfTrials - numberOfSuccesses));
final double fValueUpperBound = distributionUpperBound.inverseCumulativeProbability(1 - alpha);
final double fValueUpperBound = distributionUpperBound.inverseSurvivalProbability(alpha);
upperBound = (numberOfSuccesses + 1) * fValueUpperBound /
(numberOfTrials - numberOfSuccesses + (numberOfSuccesses + 1) * fValueUpperBound);
}

View File

@ -37,7 +37,7 @@ public class NormalApproximationInterval implements BinomialConfidenceInterval {
final double mean = (double) numberOfSuccesses / (double) numberOfTrials;
final double alpha = (1.0 - confidenceLevel) / 2;
final NormalDistribution normalDistribution = NormalDistribution.of(0, 1);
final double difference = normalDistribution.inverseCumulativeProbability(1 - alpha) *
final double difference = normalDistribution.inverseSurvivalProbability(alpha) *
JdkMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean));
return new ConfidenceInterval(mean - difference, mean + difference, confidenceLevel);
}

View File

@ -33,7 +33,7 @@ public class WilsonScoreInterval implements BinomialConfidenceInterval {
IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
final double alpha = (1 - confidenceLevel) / 2;
final NormalDistribution normalDistribution = NormalDistribution.of(0, 1);
final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
final double z = normalDistribution.inverseSurvivalProbability(alpha);
final double zSquared = z * z;
final double oneOverNumTrials = 1d / numberOfTrials;
final double zSquaredOverNumTrials = zSquared * oneOverNumTrials;

View File

@ -695,7 +695,7 @@ public class SimpleRegression implements UpdatingMultipleLinearRegression {
// No advertised NotStrictlyPositiveException here - will return NaN above
TDistribution distribution = TDistribution.of(n - 2d);
return getSlopeStdErr() *
distribution.inverseCumulativeProbability(1d - alpha / 2d);
distribution.inverseSurvivalProbability(alpha / 2d);
}
/**
@ -726,7 +726,7 @@ public class SimpleRegression implements UpdatingMultipleLinearRegression {
}
// No advertised NotStrictlyPositiveException here - will return NaN above
TDistribution distribution = TDistribution.of(n - 2d);
return 2d * (1.0 - distribution.cumulativeProbability(
return 2d * (distribution.survivalProbability(
JdkMath.abs(getSlope()) / getSlopeStdErr()));
}

View File

@ -237,7 +237,7 @@ public class PearsonsCorrelationTest {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < i; j++) {
double t = JdkMath.abs(rValues.getEntry(i, j)) / stdErrors.getEntry(i, j);
double p = 2 * (1 - tDistribution.cumulativeProbability(t));
double p = 2 * tDistribution.survivalProbability(t);
Assert.assertEquals(p, pValues.getEntry(i, j), 10E-15);
}
}