diff --git a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java index 07b9cd883..407b082ea 100644 --- a/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java +++ b/src/main/java/org/apache/commons/math/stat/inference/ChiSquareTestImpl.java @@ -36,6 +36,9 @@ import org.apache.commons.math.util.FastMath; */ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { + /** Distribution used to compute inference statistics. */ + private ChiSquaredDistribution distribution; + /** * Construct a ChiSquareTestImpl */ @@ -112,7 +115,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { */ public double chiSquareTest(double[] expected, long[] observed) throws MathException { - ChiSquaredDistributionImpl distribution = new ChiSquaredDistributionImpl(expected.length - 1.0); + distribution = new ChiSquaredDistributionImpl(expected.length - 1.0); return 1.0 - distribution.cumulativeProbability( chiSquare(expected, observed)); } @@ -186,7 +189,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { throws MathException { checkArray(counts); double df = ((double) counts.length -1) * ((double) counts[0].length - 1); - ChiSquaredDistributionImpl distribution = new ChiSquaredDistributionImpl(df); + distribution = new ChiSquaredDistributionImpl(df); return 1 - distribution.cumulativeProbability(chiSquare(counts)); } @@ -280,7 +283,7 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { */ public double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2) throws MathException { - ChiSquaredDistributionImpl distribution = new ChiSquaredDistributionImpl((double) observed1.length - 1); + distribution = new ChiSquaredDistributionImpl((double) observed1.length - 1); return 1 - distribution.cumulativeProbability( chiSquareDataSetsComparison(observed1, observed2)); } @@ -390,4 +393,14 @@ public class ChiSquareTestImpl implements UnknownDistributionChiSquareTest { } } + /** + * Modify the distribution used to compute inference statistics. + * + * @param value + * the new distribution + * @since 1.2 + */ + public void setDistribution(ChiSquaredDistribution value) { + distribution = value; + } } diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml index ecab662ef..8f7af9139 100644 --- a/src/site/xdoc/changes.xml +++ b/src/site/xdoc/changes.xml @@ -52,10 +52,6 @@ The type attribute can be add,update,fix,remove. If the output is not quite correct, check for invisible trailing spaces! --> - - The static field ChiSquareTestImpl.distribution serves no purpose. - Removed setter and static field, and made other instances local variables. - TestUtils is thread-hostile. Remove getters and setters, and make static variables final.