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 2025/09/16 13:02:42 UTC
(commons-math) branch master updated: Removed o.a.c.m.legacy.stat.interval package.
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
The following commit(s) were added to refs/heads/master by this push:
new 1ce3e824a Removed o.a.c.m.legacy.stat.interval package.
1ce3e824a is described below
commit 1ce3e824a04e299b57072e8d53bcdcb099678cfd
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Tue Sep 16 13:49:07 2025 +0100
Removed o.a.c.m.legacy.stat.interval package.
Functionality has been transferred to Commons Statistics interval.
---
.../legacy/stat/interval/AgrestiCoullInterval.java | 48 ------
.../stat/interval/BinomialConfidenceInterval.java | 60 -------
.../stat/interval/ClopperPearsonInterval.java | 55 -------
.../legacy/stat/interval/ConfidenceInterval.java | 108 -------------
.../math4/legacy/stat/interval/IntervalUtils.java | 172 ---------------------
.../stat/interval/NormalApproximationInterval.java | 44 ------
.../legacy/stat/interval/WilsonScoreInterval.java | 51 ------
.../math4/legacy/stat/interval/package-info.java | 22 ---
.../stat/interval/AgrestiCoullIntervalTest.java | 39 -----
.../BinomialConfidenceIntervalAbstractTest.java | 80 ----------
.../stat/interval/ClopperPearsonIntervalTest.java | 126 ---------------
.../legacy/stat/interval/IntervalUtilsTest.java | 64 --------
.../interval/NormalApproximationIntervalTest.java | 39 -----
.../stat/interval/WilsonScoreIntervalTest.java | 45 ------
src/changes/changes.xml | 4 +
15 files changed, 4 insertions(+), 953 deletions(-)
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
deleted file mode 100644
index 37dde0504..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullInterval.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.statistics.distribution.NormalDistribution;
-import org.apache.commons.math4.core.jdkmath.JdkMath;
-
-/**
- * Implements the Agresti-Coull method for creating a binomial proportion confidence interval.
- *
- * @see <a
- * href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Agresti-Coull_Interval">
- * Agresti-Coull interval (Wikipedia)</a>
- * @since 3.3
- */
-public class AgrestiCoullInterval implements BinomialConfidenceInterval {
-
- /** {@inheritDoc} */
- @Override
- public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
- IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
- final double alpha = (1.0 - confidenceLevel) / 2;
- final NormalDistribution normalDistribution = NormalDistribution.of(0, 1);
- final double z = normalDistribution.inverseSurvivalProbability(alpha);
- final double zSquared = z * z;
- final double modifiedNumberOfTrials = numberOfTrials + zSquared;
- final double modifiedSuccessesRatio = (1.0 / modifiedNumberOfTrials) * (numberOfSuccesses + 0.5 * zSquared);
- final double difference = z *
- JdkMath.sqrt(1.0 / modifiedNumberOfTrials * modifiedSuccessesRatio *
- (1 - modifiedSuccessesRatio));
- return new ConfidenceInterval(modifiedSuccessesRatio - difference, modifiedSuccessesRatio + difference,
- confidenceLevel);
- }
-}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceInterval.java
deleted file mode 100644
index bddcb23d6..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceInterval.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.math4.legacy.exception.NotPositiveException;
-import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-
-/**
- * Interface to generate confidence intervals for a binomial proportion.
- *
- * @see <a
- * href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval">Binomial
- * proportion confidence interval (Wikipedia)</a>
- * @since 3.3
- */
-public interface BinomialConfidenceInterval {
-
- /**
- * Create a confidence interval for the true probability of success
- * of an unknown binomial distribution with the given observed number
- * of trials, successes and confidence level.
- * <p>
- * Preconditions:
- * <ul>
- * <li>{@code numberOfTrials} must be positive</li>
- * <li>{@code numberOfSuccesses} may not exceed {@code numberOfTrials}</li>
- * <li>{@code confidenceLevel} must be strictly between 0 and 1 (exclusive)</li>
- * </ul>
- *
- * @param numberOfTrials number of trials
- * @param numberOfSuccesses number of successes
- * @param confidenceLevel desired probability that the true probability of
- * success falls within the returned interval
- * @return Confidence interval containing the probability of success with
- * probability {@code confidenceLevel}
- * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
- * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
- * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
- * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
- */
- ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel)
- throws NotStrictlyPositiveException, NotPositiveException,
- NumberIsTooLargeException, OutOfRangeException;
-}
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
deleted file mode 100644
index 8f8ef5f33..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonInterval.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.statistics.distribution.BetaDistribution;
-
-/**
- * Implements the Clopper-Pearson method for creating a binomial proportion confidence interval.
- *
- * @see <a
- * href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Clopper-Pearson_interval">
- * Clopper-Pearson interval (Wikipedia)</a>
- * @since 3.3
- */
-public class ClopperPearsonInterval implements BinomialConfidenceInterval {
-
- /** {@inheritDoc} */
- @Override
- public ConfidenceInterval createInterval(int numberOfTrials,
- int numberOfSuccesses,
- double confidenceLevel) {
- IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
- double lowerBound = 0;
- double upperBound = 1;
-
- // alpha = 1 - confidence level
- final double halfAlpha = 0.5 * (1 - confidenceLevel);
- final int n = numberOfTrials;
- final int x = numberOfSuccesses;
-
- if (numberOfSuccesses > 0) {
- lowerBound = BetaDistribution.of(x, n - x + 1).inverseCumulativeProbability(halfAlpha);
- }
-
- if (numberOfSuccesses < numberOfTrials) {
- upperBound = BetaDistribution.of(x + 1, n - x).inverseSurvivalProbability(halfAlpha);
- }
-
- return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
- }
-}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ConfidenceInterval.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ConfidenceInterval.java
deleted file mode 100644
index acd3af6c5..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/ConfidenceInterval.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-
-/**
- * Represents an interval estimate of a population parameter.
- *
- * @since 3.3
- */
-public class ConfidenceInterval {
-
- /** Lower endpoint of the interval. */
- private double lowerBound;
-
- /** Upper endpoint of the interval. */
- private double upperBound;
-
- /**
- * The asserted probability that the interval contains the population.
- * parameter
- */
- private double confidenceLevel;
-
- /**
- * Create a confidence interval with the given bounds and confidence level.
- * <p>
- * Preconditions:
- * <ul>
- * <li>{@code lower} must be strictly less than {@code upper}</li>
- * <li>{@code confidenceLevel} must be strictly between 0 and 1 (exclusive)</li>
- * </ul>
- *
- * @param lowerBound lower endpoint of the interval
- * @param upperBound upper endpoint of the interval
- * @param confidenceLevel coverage probability
- * @throws MathIllegalArgumentException if the preconditions are not met
- */
- public ConfidenceInterval(double lowerBound, double upperBound, double confidenceLevel) {
- checkParameters(lowerBound, upperBound, confidenceLevel);
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
- this.confidenceLevel = confidenceLevel;
- }
-
- /**
- * @return the lower endpoint of the interval
- */
- public double getLowerBound() {
- return lowerBound;
- }
-
- /**
- * @return the upper endpoint of the interval
- */
- public double getUpperBound() {
- return upperBound;
- }
-
- /**
- * @return the asserted probability that the interval contains the
- * population parameter
- */
- public double getConfidenceLevel() {
- return confidenceLevel;
- }
-
- /**
- * @return String representation of the confidence interval
- */
- @Override
- public String toString() {
- return "[" + lowerBound + ";" + upperBound + "] (confidence level:" + confidenceLevel + ")";
- }
-
- /**
- * Verifies that (lower, upper) is a valid non-empty interval and confidence
- * is strictly between 0 and 1.
- *
- * @param lower lower endpoint
- * @param upper upper endpoint
- * @param confidence confidence level
- */
- private void checkParameters(double lower, double upper, double confidence) {
- if (lower >= upper) {
- throw new MathIllegalArgumentException(LocalizedFormats.LOWER_BOUND_NOT_BELOW_UPPER_BOUND, lower, upper);
- }
- if (confidence <= 0 || confidence >= 1) {
- throw new MathIllegalArgumentException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL, confidence, 0, 1);
- }
- }
-}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtils.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtils.java
deleted file mode 100644
index 41efa0c61..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtils.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.math4.legacy.exception.NotPositiveException;
-import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
-import org.apache.commons.math4.legacy.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.legacy.exception.OutOfRangeException;
-import org.apache.commons.math4.legacy.exception.util.LocalizedFormats;
-
-/**
- * Factory methods to generate confidence intervals for a binomial proportion.
- * The supported methods are:
- * <ul>
- * <li>Agresti-Coull interval</li>
- * <li>Clopper-Pearson method (exact method)</li>
- * <li>Normal approximation (based on central limit theorem)</li>
- * <li>Wilson score interval</li>
- * </ul>
- *
- * @since 3.3
- */
-public final class IntervalUtils {
-
- /** Singleton Agresti-Coull instance. */
- private static final BinomialConfidenceInterval AGRESTI_COULL = new AgrestiCoullInterval();
-
- /** Singleton Clopper-Pearson instance. */
- private static final BinomialConfidenceInterval CLOPPER_PEARSON = new ClopperPearsonInterval();
-
- /** Singleton NormalApproximation instance. */
- private static final BinomialConfidenceInterval NORMAL_APPROXIMATION = new NormalApproximationInterval();
-
- /** Singleton Wilson score instance. */
- private static final BinomialConfidenceInterval WILSON_SCORE = new WilsonScoreInterval();
-
- /**
- * Prevent instantiation.
- */
- private IntervalUtils() {
- }
-
- /**
- * Create an Agresti-Coull binomial confidence interval for the true
- * probability of success of an unknown binomial distribution with the given
- * observed number of trials, successes and confidence level.
- *
- * @param numberOfTrials number of trials
- * @param numberOfSuccesses number of successes
- * @param confidenceLevel desired probability that the true probability of
- * success falls within the returned interval
- * @return Confidence interval containing the probability of success with
- * probability {@code confidenceLevel}
- * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
- * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
- * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
- * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
- */
- public static ConfidenceInterval getAgrestiCoullInterval(int numberOfTrials, int numberOfSuccesses,
- double confidenceLevel) {
- return AGRESTI_COULL.createInterval(numberOfTrials, numberOfSuccesses, confidenceLevel);
- }
-
- /**
- * Create a Clopper-Pearson binomial confidence interval for the true
- * probability of success of an unknown binomial distribution with the given
- * observed number of trials, successes and confidence level.
- * <p>
- * Preconditions:
- * <ul>
- * <li>{@code numberOfTrials} must be positive</li>
- * <li>{@code numberOfSuccesses} may not exceed {@code numberOfTrials}</li>
- * <li>{@code confidenceLevel} must be strictly between 0 and 1 (exclusive)</li>
- * </ul>
- *
- * @param numberOfTrials number of trials
- * @param numberOfSuccesses number of successes
- * @param confidenceLevel desired probability that the true probability of
- * success falls within the returned interval
- * @return Confidence interval containing the probability of success with
- * probability {@code confidenceLevel}
- * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
- * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
- * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
- * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
- */
- public static ConfidenceInterval getClopperPearsonInterval(int numberOfTrials, int numberOfSuccesses,
- double confidenceLevel) {
- return CLOPPER_PEARSON.createInterval(numberOfTrials, numberOfSuccesses, confidenceLevel);
- }
-
- /**
- * Create a binomial confidence interval for the true probability of success
- * of an unknown binomial distribution with the given observed number of
- * trials, successes and confidence level using the Normal approximation to
- * the binomial distribution.
- *
- * @param numberOfTrials number of trials
- * @param numberOfSuccesses number of successes
- * @param confidenceLevel desired probability that the true probability of
- * success falls within the interval
- * @return Confidence interval containing the probability of success with
- * probability {@code confidenceLevel}
- */
- public static ConfidenceInterval getNormalApproximationInterval(int numberOfTrials, int numberOfSuccesses,
- double confidenceLevel) {
- return NORMAL_APPROXIMATION.createInterval(numberOfTrials, numberOfSuccesses, confidenceLevel);
- }
-
- /**
- * Create a Wilson score binomial confidence interval for the true
- * probability of success of an unknown binomial distribution with the given
- * observed number of trials, successes and confidence level.
- *
- * @param numberOfTrials number of trials
- * @param numberOfSuccesses number of successes
- * @param confidenceLevel desired probability that the true probability of
- * success falls within the returned interval
- * @return Confidence interval containing the probability of success with
- * probability {@code confidenceLevel}
- * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
- * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
- * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
- * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
- */
- public static ConfidenceInterval getWilsonScoreInterval(int numberOfTrials, int numberOfSuccesses,
- double confidenceLevel) {
- return WILSON_SCORE.createInterval(numberOfTrials, numberOfSuccesses, confidenceLevel);
- }
-
- /**
- * Verifies that parameters satisfy preconditions.
- *
- * @param numberOfTrials number of trials (must be positive)
- * @param numberOfSuccesses number of successes (must not exceed numberOfTrials)
- * @param confidenceLevel confidence level (must be strictly between 0 and 1)
- * @throws NotStrictlyPositiveException if {@code numberOfTrials <= 0}.
- * @throws NotPositiveException if {@code numberOfSuccesses < 0}.
- * @throws NumberIsTooLargeException if {@code numberOfSuccesses > numberOfTrials}.
- * @throws OutOfRangeException if {@code confidenceLevel} is not in the interval {@code (0, 1)}.
- */
- static void checkParameters(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
- if (numberOfTrials <= 0) {
- throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_TRIALS, numberOfTrials);
- }
- if (numberOfSuccesses < 0) {
- throw new NotPositiveException(LocalizedFormats.NEGATIVE_NUMBER_OF_SUCCESSES, numberOfSuccesses);
- }
- if (numberOfSuccesses > numberOfTrials) {
- throw new NumberIsTooLargeException(LocalizedFormats.NUMBER_OF_SUCCESS_LARGER_THAN_POPULATION_SIZE,
- numberOfSuccesses, numberOfTrials, true);
- }
- if (confidenceLevel <= 0 || confidenceLevel >= 1) {
- throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUNDS_CONFIDENCE_LEVEL,
- confidenceLevel, 0, 1);
- }
- }
-}
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
deleted file mode 100644
index 8871fcaa3..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationInterval.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.statistics.distribution.NormalDistribution;
-import org.apache.commons.math4.core.jdkmath.JdkMath;
-
-/**
- * Implements the normal approximation method for creating a binomial proportion confidence interval.
- *
- * @see <a
- * href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Normal_approximation_interval">
- * Normal approximation interval (Wikipedia)</a>
- * @since 3.3
- */
-public class NormalApproximationInterval implements BinomialConfidenceInterval {
-
- /** {@inheritDoc} */
- @Override
- public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses,
- double confidenceLevel) {
- IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
- 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.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
deleted file mode 100644
index c57c122df..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreInterval.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.statistics.distribution.NormalDistribution;
-import org.apache.commons.math4.core.jdkmath.JdkMath;
-
-/**
- * Implements the <a href="http://en.wikipedia.org/wiki/Binomial_proportion_confidence_interval#Wilson_score_interval">
- * Wilson score method</a> for creating a binomial proportion confidence interval.
- *
- * @since 3.3
- */
-public class WilsonScoreInterval implements BinomialConfidenceInterval {
-
- /** {@inheritDoc} */
- @Override
- public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
- IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
- final double alpha = (1 - confidenceLevel) / 2;
- final NormalDistribution normalDistribution = NormalDistribution.of(0, 1);
- final double z = normalDistribution.inverseSurvivalProbability(alpha);
- final double zSquared = z * z;
- final double oneOverNumTrials = 1d / numberOfTrials;
- final double zSquaredOverNumTrials = zSquared * oneOverNumTrials;
- final double mean = oneOverNumTrials * numberOfSuccesses;
-
- final double factor = 1 / (1 + zSquaredOverNumTrials);
- final double modifiedSuccessRatio = mean + zSquaredOverNumTrials / 2;
- final double difference = z * JdkMath.sqrt(oneOverNumTrials * mean * (1 - mean) +
- (oneOverNumTrials * zSquaredOverNumTrials / 4));
-
- final double lowerBound = factor * (modifiedSuccessRatio - difference);
- final double upperBound = factor * (modifiedSuccessRatio + difference);
- return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
- }
-}
diff --git a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/package-info.java b/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/package-info.java
deleted file mode 100644
index abd422fed..000000000
--- a/commons-math-legacy/src/main/java/org/apache/commons/math4/legacy/stat/interval/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/**
- *
- * Classes providing binomial proportion confidence interval construction.
- *
- */
-package org.apache.commons.math4.legacy.stat.interval;
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullIntervalTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullIntervalTest.java
deleted file mode 100644
index 2a0a70b0e..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/AgrestiCoullIntervalTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the AgrestiCoullInterval class.
- *
- */
-public class AgrestiCoullIntervalTest extends BinomialConfidenceIntervalAbstractTest {
-
- @Override
- protected BinomialConfidenceInterval createBinomialConfidenceInterval() {
- return new AgrestiCoullInterval();
- }
-
- @Test
- public void testStandardInterval() {
- ConfidenceInterval confidenceInterval = createStandardTestInterval();
- Assert.assertEquals(0.07993521, confidenceInterval.getLowerBound(), 1E-5);
- Assert.assertEquals(0.1243704, confidenceInterval.getUpperBound(), 1E-5);
- }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceIntervalAbstractTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceIntervalAbstractTest.java
deleted file mode 100644
index e43dda99b..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/BinomialConfidenceIntervalAbstractTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.apache.commons.math4.legacy.exception.MathIllegalArgumentException;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test cases for the BinomialConfidenceInterval implementations.
- *
- */
-public abstract class BinomialConfidenceIntervalAbstractTest {
-
- protected BinomialConfidenceInterval testStatistic;
-
- private final int successes = 50;
- private final int trials = 500;
- private final double confidenceLevel = 0.9;
-
- protected abstract BinomialConfidenceInterval createBinomialConfidenceInterval();
-
- /**
- * Returns the confidence interval for the given statistic with the following values:
- *
- * <ul>
- * <li>trials: 500</li>
- * <li>successes: 50</li>
- * <li>confidenceLevel: 0.9</li>
- * </ul>
- * @return the Confidence Interval for the given values
- */
- protected ConfidenceInterval createStandardTestInterval() {
- return testStatistic.createInterval(trials, successes, confidenceLevel);
- }
-
- @Before
- public void setUp() {
- testStatistic = createBinomialConfidenceInterval();
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testZeroConfidencelevel() {
- testStatistic.createInterval(trials, successes, 0d);
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testOneConfidencelevel() {
- testStatistic.createInterval(trials, successes, 1d);
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testZeroTrials() {
- testStatistic.createInterval(0, 0, confidenceLevel);
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testNegativeSuccesses() {
- testStatistic.createInterval(trials, -1, confidenceLevel);
- }
-
- @Test(expected = MathIllegalArgumentException.class)
- public void testSuccessesExceedingTrials() {
- testStatistic.createInterval(trials, trials + 1, confidenceLevel);
- }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonIntervalTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonIntervalTest.java
deleted file mode 100644
index f72787d3e..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/ClopperPearsonIntervalTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the ClopperPearsonInterval class.
- *
- */
-public class ClopperPearsonIntervalTest extends BinomialConfidenceIntervalAbstractTest {
-
- @Override
- protected BinomialConfidenceInterval createBinomialConfidenceInterval() {
- return new ClopperPearsonInterval();
- }
-
- @Test
- public void testStandardInterval() {
- ConfidenceInterval confidenceInterval = createStandardTestInterval();
- Assert.assertEquals(0.07873857, confidenceInterval.getLowerBound(), 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);
- }
-
- // number of successes = 0, number of trials = N
- @Test
- public void testCase1() {
- // Check correctness against values obtained with the Python statsmodels.stats.proportion.proportion_confint
- final int successes = 0;
- final int trials = 10;
- final double confidenceLevel = 0.95;
-
- // proportion_confint(0,10,method='beta') = (0, 0.3084971078187608)
- final ConfidenceInterval expected = new ConfidenceInterval(0,
- 0.3084971078187608,
- confidenceLevel);
-
- check(expected, createBinomialConfidenceInterval().createInterval(trials, successes, confidenceLevel));
- }
-
- // number of successes = number of trials = N
- @Test
- public void testCase2() {
- // Check correctness against values obtained with the Python statsmodels.stats.proportion.proportion_confint
- final int successes = 10;
- final int trials = 10;
- final double confidenceLevel = 0.95;
-
- // prop.proportion_confint(10,10,method='beta') = (0.6915028921812392, 1)
- final ConfidenceInterval expected = new ConfidenceInterval(0.6915028921812392,
- 1,
- confidenceLevel);
-
- check(expected, createBinomialConfidenceInterval().createInterval(trials, successes, confidenceLevel));
- }
-
- // number of successes = k, number of trials = N, 0 < k < N
- @Test
- public void testCase3() {
- // Check correctness against values obtained with the Python statsmodels.stats.proportion.proportion_confint
- final int successes = 3;
- final int trials = 10;
- final double confidenceLevel = 0.95;
-
- // prop.proportion_confint(3,10,method='beta') = (0.06673951117773447, 0.6524528500599972)
- final ConfidenceInterval expected = new ConfidenceInterval(0.06673951117773447,
- 0.6524528500599972,
- confidenceLevel);
-
- check(expected, createBinomialConfidenceInterval().createInterval(trials, successes, confidenceLevel));
- }
-
- @Test
- public void testCase4() {
- final int successes = 20;
- final int trials = 400;
- final double confidenceLevel = 0.95;
-
- // Check using scipy.stats.beta
- // k, n, alpha = 20, 400, 0.05
- // p_l, p_u = beta.ppf([alpha / 2, 1 - alpha / 2], [k, k + 1], [n - k + 1, n - k])
- final ConfidenceInterval expected = new ConfidenceInterval(0.030805241143265938,
- 0.07616697275514255,
- confidenceLevel);
-
- check(expected, createBinomialConfidenceInterval().createInterval(trials, successes, confidenceLevel));
- }
-
- private void check(ConfidenceInterval expected,
- ConfidenceInterval actual) {
- final double relTol = 1.0e-6; // Reasonable relative tolerance for floating point comparison
- // Compare bounds using a relative tolerance
- Assert.assertEquals(expected.getLowerBound(),
- actual.getLowerBound(),
- relTol * expected.getLowerBound());
- Assert.assertEquals(expected.getUpperBound(),
- actual.getUpperBound(),
- relTol * expected.getUpperBound());
- // The confidence level must be exact
- Assert.assertEquals(expected.getConfidenceLevel(),
- actual.getConfidenceLevel(),
- 0.0);
- }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtilsTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtilsTest.java
deleted file mode 100644
index 1103eaf96..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/IntervalUtilsTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the IntervalUtils class.
- *
- */
-public class IntervalUtilsTest {
-
- private final int successes = 50;
- private final int trials = 500;
- private final double confidenceLevel = 0.9;
-
- // values to test must be exactly the same
- private final double eps = 0.0;
-
- @Test
- public void testAgrestiCoull() {
- checkConfidenceIntervals(new AgrestiCoullInterval().createInterval(trials, successes, confidenceLevel),
- IntervalUtils.getAgrestiCoullInterval(trials, successes, confidenceLevel));
- }
-
- @Test
- public void testClopperPearson() {
- checkConfidenceIntervals(new ClopperPearsonInterval().createInterval(trials, successes, confidenceLevel),
- IntervalUtils.getClopperPearsonInterval(trials, successes, confidenceLevel));
- }
-
- @Test
- public void testNormalApproximation() {
- checkConfidenceIntervals(new NormalApproximationInterval().createInterval(trials, successes, confidenceLevel),
- IntervalUtils.getNormalApproximationInterval(trials, successes, confidenceLevel));
- }
-
- @Test
- public void testWilsonScore() {
- checkConfidenceIntervals(new WilsonScoreInterval().createInterval(trials, successes, confidenceLevel),
- IntervalUtils.getWilsonScoreInterval(trials, successes, confidenceLevel));
- }
-
- private void checkConfidenceIntervals(ConfidenceInterval expected, ConfidenceInterval actual) {
- Assert.assertEquals(expected.getLowerBound(), actual.getLowerBound(), eps);
- Assert.assertEquals(expected.getUpperBound(), actual.getUpperBound(), eps);
- Assert.assertEquals(expected.getConfidenceLevel(), actual.getConfidenceLevel(), eps);
- }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationIntervalTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationIntervalTest.java
deleted file mode 100644
index 78ad9bee3..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/NormalApproximationIntervalTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the NormalApproximationInterval class.
- *
- */
-public class NormalApproximationIntervalTest extends BinomialConfidenceIntervalAbstractTest {
-
- @Override
- protected BinomialConfidenceInterval createBinomialConfidenceInterval() {
- return new NormalApproximationInterval();
- }
-
- @Test
- public void testStandardInterval() {
- ConfidenceInterval confidenceInterval = createStandardTestInterval();
- Assert.assertEquals(0.07793197, confidenceInterval.getLowerBound(), 1E-5);
- Assert.assertEquals(0.1220680, confidenceInterval.getUpperBound(), 1E-5);
- }
-}
diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreIntervalTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreIntervalTest.java
deleted file mode 100644
index 28d49a83b..000000000
--- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/stat/interval/WilsonScoreIntervalTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.math4.legacy.stat.interval;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- * Test cases for the WilsonScoreInterval class.
- *
- */
-public class WilsonScoreIntervalTest extends BinomialConfidenceIntervalAbstractTest {
-
- @Override
- protected BinomialConfidenceInterval createBinomialConfidenceInterval() {
- return new WilsonScoreInterval();
- }
-
- @Test
- public void testStandardInterval() {
- ConfidenceInterval confidenceInterval = createStandardTestInterval();
- Assert.assertEquals(0.08003919, confidenceInterval.getLowerBound(), 1E-5);
- Assert.assertEquals(0.1242664, confidenceInterval.getUpperBound(), 1E-5);
- }
-
- @Test
- public void testMath1421() {
- double lo = new WilsonScoreInterval().createInterval(19436, 0, 0.95).getLowerBound();
- Assert.assertTrue(lo + " < 0", lo >= 0);
- }
-}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 919a99459..eed1cb04c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -96,6 +96,10 @@ Caveat:
to support the whole codebase (it was one of the main reasons for
creating more focused components).
">
+ <action dev="aherbert" type="update">
+ Removed o.a.c.m.legacy.stat.interval package. Functionality has been
+ transferred to Commons Statistics interval.
+ </action>
<action dev="erans" type="fix" issue="MATH-1681" due-to="Ruiqi Dong">
"ComplexFormat": Throw exception when parsing fails.
</action>