You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2022/12/02 15:10:17 UTC
[commons-math] 02/05: Use survival probability
This is an automated email from the ASF dual-hosted git repository.
aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit 7ed772e474316be2c4028775a37b8da991b97902
Author: aherbert <ah...@apache.org>
AuthorDate: Fri Dec 2 13:30:10 2022 +0000
Use survival probability
---
.../math4/legacy/stat/inference/BinomialTest.java | 2 +-
.../math4/legacy/stat/inference/ChiSquareTest.java | 6 +++---
.../commons/math4/legacy/stat/inference/GTest.java | 6 +++---
.../math4/legacy/stat/inference/OneWayAnova.java | 22 +++++++++++-----------
.../legacy/stat/interval/AgrestiCoullInterval.java | 2 +-
.../stat/interval/ClopperPearsonInterval.java | 4 ++--
.../stat/interval/NormalApproximationInterval.java | 2 +-
.../legacy/stat/interval/WilsonScoreInterval.java | 2 +-
.../legacy/stat/regression/SimpleRegression.java | 4 ++--
.../stat/correlation/PearsonsCorrelationTest.java | 2 +-
10 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/BinomialTest.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/BinomialTest.java
index a7deb3187..9a601bb38 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/BinomialTest.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/BinomialTest.java
@@ -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:
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/ChiSquareTest.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/ChiSquareTest.java
index eef09933f..3cf36875d 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/ChiSquareTest.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/ChiSquareTest.java
@@ -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));
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/GTest.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/GTest.java
index 42273e625..3b82b74a7 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/GTest.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/GTest.java
@@ -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));
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java
index 2643270e0..8b93f1775 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/inference/OneWayAnova.java
@@ -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>
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullInterval.java
index 1002abb7e..95d4caea6 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullInterval.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullInterval.java
@@ -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);
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonInterval.java
index a28522cdc..b8b23034e 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonInterval.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonInterval.java
@@ -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);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationInterval.java
index fb085432d..8871fcaa3 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationInterval.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationInterval.java
@@ -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);
}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreInterval.java
index e08d58714..c57c122df 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreInterval.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreInterval.java
@@ -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;
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/regression/SimpleRegression.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/regression/SimpleRegression.java
index ada0c3b2a..44d73219c 100644
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/regression/SimpleRegression.java
+++ b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/regression/SimpleRegression.java
@@ -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()));
}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelationTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelationTest.java
index 87f5631f9..cb1d36a6b 100644
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelationTest.java
+++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/correlation/PearsonsCorrelationTest.java
@@ -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);
}
}