Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#OUT_OF_BOUND_SIGNIFICANCE_LEVEL
The following examples show how to use
org.apache.commons.math3.exception.util.LocalizedFormats#OUT_OF_BOUND_SIGNIFICANCE_LEVEL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a Chi-Square two sample test comparing two binned data * sets. The test evaluates the null hypothesis that the two lists of * observed counts conform to the same frequency distribution, with * significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for * details on the formula used to compute the Chisquare statistic used * in the test. The degrees of of freedom used to perform the test is * one less than the common length of the input observed count arrays. * </p> * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. * </li> * <li>Observed counts for a specific bin must not both be zero. * </li> * <li>Observed counts for a specific sample must not all be 0. * </li> * <li>The arrays <code>observed1</code> and <code>observed2</code> must * have the same length and their common length must be at least 2. * </li> * <li> <code> 0 < alpha < 0.5 </code> * </li></ul><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws DimensionMismatchException the the length of the arrays does not match * @throws NotPositiveException if any entries in <code>observed1</code> or * <code>observed2</code> are negative * @throws ZeroException if either all counts of <code>observed1</code> or * <code>observed2</code> are zero, or if the count at the same index is zero * for both arrays * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test * @since 1.2 */ public boolean chiSquareTestDataSetsComparison(final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTestDataSetsComparison(observed1, observed2) < alpha; }
Example 2
Source File: OneWayAnova.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs an ANOVA test, evaluating the null hypothesis that there * is no difference among the means of the data categories. * * <p><strong>Preconditions</strong>: <ul> * <li>The categoryData <code>Collection</code> must contain * <code>double[]</code> arrays.</li> * <li> There must be at least two <code>double[]</code> arrays in the * <code>categoryData</code> collection and each of these arrays must * contain at least two values.</li> * <li>alpha must be strictly greater than 0 and less than or equal to 0.5. * </li></ul></p><p> * This implementation uses the * {@link org.apache.commons.math3.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> * <p>True is returned iff the estimated p-value is less than alpha.</p> * * @param categoryData <code>Collection</code> of <code>double[]</code> * arrays each containing data for one category * @param alpha significance level of the test * @return true if the null hypothesis can be rejected with * confidence 1 - alpha * @throws NullArgumentException if <code>categoryData</code> is <code>null</code> * @throws DimensionMismatchException if the length of the <code>categoryData</code> * array is less than 2 or a contained <code>double[]</code> array does not have * at least two values * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws ConvergenceException if the p-value can not be computed due to a convergence error * @throws MaxCountExceededException if the maximum number of iterations is exceeded */ public boolean anovaTest(final Collection<double[]> categoryData, final double alpha) throws NullArgumentException, DimensionMismatchException, OutOfRangeException, ConvergenceException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return anovaPValue(categoryData) < alpha; }
Example 3
Source File: KolmogorovSmirnovTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test"> Kolmogorov-Smirnov * test</a> evaluating the null hypothesis that {@code data} conforms to {@code distribution}. * * @param distribution reference distribution * @param data sample being being evaluated * @param alpha significance level of the test * @return true iff the null hypothesis that {@code data} is a sample from {@code distribution} * can be rejected with confidence 1 - {@code alpha} * @throws InsufficientDataException if {@code data} does not have length at least 2 * @throws NullArgumentException if {@code data} is null */ public boolean kolmogorovSmirnovTest(RealDistribution distribution, double[] data, double alpha) { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return kolmogorovSmirnovTest(distribution, data) < alpha; }
Example 4
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a Chi-Square two sample test comparing two binned data * sets. The test evaluates the null hypothesis that the two lists of * observed counts conform to the same frequency distribution, with * significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for * details on the formula used to compute the Chisquare statistic used * in the test. The degrees of of freedom used to perform the test is * one less than the common length of the input observed count arrays. * </p> * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. * </li> * <li>Observed counts for a specific bin must not both be zero. * </li> * <li>Observed counts for a specific sample must not all be 0. * </li> * <li>The arrays <code>observed1</code> and <code>observed2</code> must * have the same length and their common length must be at least 2. * </li> * <li> <code> 0 < alpha < 0.5 </code> * </li></ul><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws DimensionMismatchException the the length of the arrays does not match * @throws NotPositiveException if any entries in <code>observed1</code> or * <code>observed2</code> are negative * @throws ZeroException if either all counts of <code>observed1</code> or * <code>observed2</code> are zero, or if the count at the same index is zero * for both arrays * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test * @since 1.2 */ public boolean chiSquareTestDataSetsComparison(final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTestDataSetsComparison(observed1, observed2) < alpha; }
Example 5
Source File: GTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a G-Test (Log-Likelihood Ratio Test) comparing two binned * data sets. The test evaluates the null hypothesis that the two lists * of observed counts conform to the same frequency distribution, with * significance level {@code alpha}. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #gDataSetsComparison(long[], long[])} for details * on the formula used to compute the G (LLR) statistic used in the test and * {@link #gTest(double[], long[])} for information on how * the observed significance level is computed. The degrees of of freedom used * to perform the test is one less than the common length of the input observed * count arrays. </p> * * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. </li> * <li>Observed counts for a specific bin must not both be zero. </li> * <li>Observed counts for a specific sample must not all be 0. </li> * <li>The arrays {@code observed1} and {@code observed2} must * have the same length and their common length must be at least 2. </li> * <li>{@code 0 < alpha < 0.5} </li></ul></p> * * <p>If any of the preconditions are not met, a * {@code MathIllegalArgumentException} is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data * set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence 1 - * alpha * @throws DimensionMismatchException the the length of the arrays does not * match * @throws NotPositiveException if any of the entries in {@code observed1} or * {@code observed2} are negative * @throws ZeroException if either all counts of {@code observed1} or * {@code observed2} are zero, or if the count at some index is * zero for both arrays * @throws OutOfRangeException if {@code alpha} is not in the range * (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test */ public boolean gTestDataSetsComparison( final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return gTestDataSetsComparison(observed1, observed2) < alpha; }
Example 6
Source File: GTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a G-Test (Log-Likelihood Ratio Test) for goodness of fit * evaluating the null hypothesis that the observed counts conform to the * frequency distribution described by the expected counts, with * significance level {@code alpha}. Returns true iff the null * hypothesis can be rejected with {@code 100 * (1 - alpha)} percent confidence. * * <p><strong>Example:</strong><br> To test the hypothesis that * {@code observed} follows {@code expected} at the 99% level, * use </p><p> * {@code gTest(expected, observed, 0.01)}</p> * * <p>Returns true iff {@link #gTest(double[], long[]) * gTestGoodnessOfFitPValue(expected, observed)} < alpha</p> * * <p><strong>Preconditions</strong>: <ul> * <li>Expected counts must all be positive. </li> * <li>Observed counts must all be ≥ 0. </li> * <li>The observed and expected arrays must have the same length and their * common length must be at least 2. * <li> {@code 0 < alpha < 0.5} </li></ul></p> * * <p>If any of the preconditions are not met, a * {@code MathIllegalArgumentException} is thrown.</p> * * <p><strong>Note:</strong>This implementation rescales the * {@code expected} array if necessary to ensure that the sum of the * expected and observed counts are equal.</p> * * @param observed array of observed frequency counts * @param expected array of expected frequency counts * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence 1 - * alpha * @throws NotPositiveException if {@code observed} has negative entries * @throws NotStrictlyPositiveException if {@code expected} has entries that * are not strictly positive * @throws DimensionMismatchException if the array lengths do not match or * are less than 2. * @throws MaxCountExceededException if an error occurs computing the * p-value. * @throws OutOfRangeException if alpha is not strictly greater than zero * and less than or equal to 0.5 */ public boolean gTest(final double[] expected, final long[] observed, final double alpha) throws NotPositiveException, NotStrictlyPositiveException, DimensionMismatchException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return gTest(expected, observed) < alpha; }
Example 7
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if {@code counts} has any negative entries * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }
Example 8
Source File: OneWayAnova.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs an ANOVA test, evaluating the null hypothesis that there * is no difference among the means of the data categories. * * <p><strong>Preconditions</strong>: <ul> * <li>The categoryData <code>Collection</code> must contain * <code>double[]</code> arrays.</li> * <li> There must be at least two <code>double[]</code> arrays in the * <code>categoryData</code> collection and each of these arrays must * contain at least two values.</li> * <li>alpha must be strictly greater than 0 and less than or equal to 0.5. * </li></ul></p><p> * This implementation uses the * {@link org.apache.commons.math3.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> * <p>True is returned iff the estimated p-value is less than alpha.</p> * * @param categoryData <code>Collection</code> of <code>double[]</code> * arrays each containing data for one category * @param alpha significance level of the test * @return true if the null hypothesis can be rejected with * confidence 1 - alpha * @throws NullArgumentException if <code>categoryData</code> is <code>null</code> * @throws DimensionMismatchException if the length of the <code>categoryData</code> * array is less than 2 or a contained <code>double[]</code> array does not have * at least two values * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws ConvergenceException if the p-value can not be computed due to a convergence error * @throws MaxCountExceededException if the maximum number of iterations is exceeded */ public boolean anovaTest(final Collection<double[]> categoryData, final double alpha) throws NullArgumentException, DimensionMismatchException, OutOfRangeException, ConvergenceException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return anovaPValue(categoryData) < alpha; }
Example 9
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if one entry is not positive * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }
Example 10
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if one entry is not positive * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }
Example 11
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm"> * Chi-square goodness of fit test</a> evaluating the null hypothesis that the * observed counts conform to the frequency distribution described by the expected * counts, with significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * <p> * <strong>Example:</strong><br> * To test the hypothesis that <code>observed</code> follows * <code>expected</code> at the 99% level, use </p><p> * <code>chiSquareTest(expected, observed, 0.01) </code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>Expected counts must all be positive. * </li> * <li>Observed counts must all be ≥ 0. * </li> * <li>The observed and expected arrays must have the same length and * their common length must be at least 2. * <li> <code> 0 < alpha < 0.5 </code> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * <p><strong>Note: </strong>This implementation rescales the * <code>expected</code> array if necessary to ensure that the sum of the * expected and observed counts are equal.</p> * * @param observed array of observed frequency counts * @param expected array of expected frequency counts * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NotPositiveException if <code>observed</code> has negative entries * @throws NotStrictlyPositiveException if <code>expected</code> has entries that are * not strictly positive * @throws DimensionMismatchException if the arrays length is less than 2 * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final double[] expected, final long[] observed, final double alpha) throws NotPositiveException, NotStrictlyPositiveException, DimensionMismatchException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(expected, observed) < alpha; }
Example 12
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a Chi-Square two sample test comparing two binned data * sets. The test evaluates the null hypothesis that the two lists of * observed counts conform to the same frequency distribution, with * significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for * details on the formula used to compute the Chisquare statistic used * in the test. The degrees of of freedom used to perform the test is * one less than the common length of the input observed count arrays. * </p> * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. * </li> * <li>Observed counts for a specific bin must not both be zero. * </li> * <li>Observed counts for a specific sample must not all be 0. * </li> * <li>The arrays <code>observed1</code> and <code>observed2</code> must * have the same length and their common length must be at least 2. * </li> * <li> <code> 0 < alpha < 0.5 </code> * </li></ul><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws DimensionMismatchException the the length of the arrays does not match * @throws NotPositiveException if one entry in <code>observed1</code> or * <code>observed2</code> is not positive * @throws ZeroException if either all counts of <code>observed1</code> or * <code>observed2</code> are zero, or if the count at the same index is zero * for both arrays * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test * @since 1.2 */ public boolean chiSquareTestDataSetsComparison(final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTestDataSetsComparison(observed1, observed2) < alpha; }
Example 13
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if one entry is not positive * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }
Example 14
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm"> * Chi-square goodness of fit test</a> evaluating the null hypothesis that the * observed counts conform to the frequency distribution described by the expected * counts, with significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * <p> * <strong>Example:</strong><br> * To test the hypothesis that <code>observed</code> follows * <code>expected</code> at the 99% level, use </p><p> * <code>chiSquareTest(expected, observed, 0.01) </code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>Expected counts must all be positive. * </li> * <li>Observed counts must all be ≥ 0. * </li> * <li>The observed and expected arrays must have the same length and * their common length must be at least 2. * <li> <code> 0 < alpha < 0.5 </code> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * <p><strong>Note: </strong>This implementation rescales the * <code>expected</code> array if necessary to ensure that the sum of the * expected and observed counts are equal.</p> * * @param observed array of observed frequency counts * @param expected array of expected frequency counts * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NotPositiveException if one element of <code>expected</code> is not * positive * @throws NotStrictlyPositiveException if one element of <code>observed</code> is * not strictly positive * @throws DimensionMismatchException if the arrays length is less than 2 * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final double[] expected, final long[] observed, final double alpha) throws NotPositiveException, NotStrictlyPositiveException, DimensionMismatchException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(expected, observed) < alpha; }
Example 15
Source File: GTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a G-Test (Log-Likelihood Ratio Test) comparing two binned * data sets. The test evaluates the null hypothesis that the two lists * of observed counts conform to the same frequency distribution, with * significance level {@code alpha}. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #gDataSetsComparison(long[], long[])} for details * on the formula used to compute the G (LLR) statistic used in the test and * {@link #gTest(double[], long[])} for information on how * the observed significance level is computed. The degrees of of freedom used * to perform the test is one less than the common length of the input observed * count arrays. </p> * * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. </li> * <li>Observed counts for a specific bin must not both be zero. </li> * <li>Observed counts for a specific sample must not all be 0. </li> * <li>The arrays {@code observed1} and {@code observed2} must * have the same length and their common length must be at least 2. </li> * <li>{@code 0 < alpha < 0.5} </li></ul></p> * * <p>If any of the preconditions are not met, a * {@code MathIllegalArgumentException} is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data * set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence 1 - * alpha * @throws DimensionMismatchException the the length of the arrays does not * match * @throws NotPositiveException if any of the entries in {@code observed1} or * {@code observed2} are negative * @throws ZeroException if either all counts of {@code observed1} or * {@code observed2} are zero, or if the count at some index is * zero for both arrays * @throws OutOfRangeException if {@code alpha} is not in the range * (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test */ public boolean gTestDataSetsComparison( final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException( LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return gTestDataSetsComparison(observed1, observed2) < alpha; }
Example 16
Source File: KolmogorovSmirnovTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test"> Kolmogorov-Smirnov * test</a> evaluating the null hypothesis that {@code data} conforms to {@code distribution}. * * @param distribution reference distribution * @param data sample being being evaluated * @param alpha significance level of the test * @return true iff the null hypothesis that {@code data} is a sample from {@code distribution} * can be rejected with confidence 1 - {@code alpha} * @throws InsufficientDataException if {@code data} does not have length at least 2 * @throws NullArgumentException if {@code data} is null */ public boolean kolmogorovSmirnovTest(RealDistribution distribution, double[] data, double alpha) { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return kolmogorovSmirnovTest(distribution, data) < alpha; }
Example 17
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * <p>Performs a Chi-Square two sample test comparing two binned data * sets. The test evaluates the null hypothesis that the two lists of * observed counts conform to the same frequency distribution, with * significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * </p> * <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for * details on the formula used to compute the Chisquare statistic used * in the test. The degrees of of freedom used to perform the test is * one less than the common length of the input observed count arrays. * </p> * <strong>Preconditions</strong>: <ul> * <li>Observed counts must be non-negative. * </li> * <li>Observed counts for a specific bin must not both be zero. * </li> * <li>Observed counts for a specific sample must not all be 0. * </li> * <li>The arrays <code>observed1</code> and <code>observed2</code> must * have the same length and their common length must be at least 2. * </li> * <li> <code> 0 < alpha < 0.5 </code> * </li></ul><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param observed1 array of observed frequency counts of the first data set * @param observed2 array of observed frequency counts of the second data set * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws DimensionMismatchException the the length of the arrays does not match * @throws NotPositiveException if any entries in <code>observed1</code> or * <code>observed2</code> are negative * @throws ZeroException if either all counts of <code>observed1</code> or * <code>observed2</code> are zero, or if the count at the same index is zero * for both arrays * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs performing the test * @since 1.2 */ public boolean chiSquareTestDataSetsComparison(final long[] observed1, final long[] observed2, final double alpha) throws DimensionMismatchException, NotPositiveException, ZeroException, OutOfRangeException, MaxCountExceededException { if (alpha <= 0 || alpha > 0.5) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTestDataSetsComparison(observed1, observed2) < alpha; }
Example 18
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if {@code counts} has any negative entries * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }
Example 19
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/eda/section3/eda35f.htm"> * Chi-square goodness of fit test</a> evaluating the null hypothesis that the * observed counts conform to the frequency distribution described by the expected * counts, with significance level <code>alpha</code>. Returns true iff the null * hypothesis can be rejected with 100 * (1 - alpha) percent confidence. * <p> * <strong>Example:</strong><br> * To test the hypothesis that <code>observed</code> follows * <code>expected</code> at the 99% level, use </p><p> * <code>chiSquareTest(expected, observed, 0.01) </code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>Expected counts must all be positive. * </li> * <li>Observed counts must all be ≥ 0. * </li> * <li>The observed and expected arrays must have the same length and * their common length must be at least 2. * <li> <code> 0 < alpha < 0.5 </code> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * <p><strong>Note: </strong>This implementation rescales the * <code>expected</code> array if necessary to ensure that the sum of the * expected and observed counts are equal.</p> * * @param observed array of observed frequency counts * @param expected array of expected frequency counts * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NotPositiveException if <code>observed</code> has negative entries * @throws NotStrictlyPositiveException if <code>expected</code> has entries that are * not strictly positive * @throws DimensionMismatchException if the arrays length is less than 2 * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final double[] expected, final long[] observed, final double alpha) throws NotPositiveException, NotStrictlyPositiveException, DimensionMismatchException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(expected, observed) < alpha; }
Example 20
Source File: ChiSquareTest.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Performs a <a href="http://www.itl.nist.gov/div898/handbook/prc/section4/prc45.htm"> * chi-square test of independence</a> evaluating the null hypothesis that the * classifications represented by the counts in the columns of the input 2-way table * are independent of the rows, with significance level <code>alpha</code>. * Returns true iff the null hypothesis can be rejected with 100 * (1 - alpha) percent * confidence. * <p> * The rows of the 2-way table are * <code>count[0], ... , count[count.length - 1] </code></p> * <p> * <strong>Example:</strong><br> * To test the null hypothesis that the counts in * <code>count[0], ... , count[count.length - 1] </code> * all correspond to the same underlying probability distribution at the 99% level, use</p> * <p><code>chiSquareTest(counts, 0.01)</code></p> * <p> * <strong>Preconditions</strong>: <ul> * <li>All counts must be ≥ 0. * </li> * <li>The count array must be rectangular (i.e. all count[i] subarrays must have the * same length).</li> * <li>The 2-way table represented by <code>counts</code> must have at least 2 columns and * at least 2 rows.</li> * </li></ul></p><p> * If any of the preconditions are not met, an * <code>IllegalArgumentException</code> is thrown.</p> * * @param counts array representation of 2-way table * @param alpha significance level of the test * @return true iff null hypothesis can be rejected with confidence * 1 - alpha * @throws NullArgumentException if the array is null * @throws DimensionMismatchException if the array is not rectangular * @throws NotPositiveException if {@code counts} has any negative entries * @throws OutOfRangeException if <code>alpha</code> is not in the range (0, 0.5] * @throws MaxCountExceededException if an error occurs computing the p-value */ public boolean chiSquareTest(final long[][] counts, final double alpha) throws NullArgumentException, DimensionMismatchException, NotPositiveException, OutOfRangeException, MaxCountExceededException { if ((alpha <= 0) || (alpha > 0.5)) { throw new OutOfRangeException(LocalizedFormats.OUT_OF_BOUND_SIGNIFICANCE_LEVEL, alpha, 0, 0.5); } return chiSquareTest(counts) < alpha; }