org.apache.commons.math3.stat.inference

## Class TestUtils

- java.lang.Object
- - org.apache.commons.math3.stat.inference.TestUtils

-     public class TestUtils
      extends Object

  A collection of static methods to create inference test instances or to perform inference tests.
  Since:
    1.1
  Version:
    $Id: TestUtils.java 1422313 2012-12-15 18:53:41Z psteitz $

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static ChiSquareTest` | `CHI_SQUARE_TEST` Singleton ChiSquareTest instance.
    `private static GTest` | `G_TEST` Singleton G-Test instance.
    `private static OneWayAnova` | `ONE_WAY_ANANOVA` Singleton OneWayAnova instance.
    `private static TTest` | `T_TEST` Singleton TTest instance.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `private` | `TestUtils()` Prevent instantiation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static double` | `chiSquare(double[] expected, long[] observed)`
    `static double` | `chiSquare(long[][] counts)`
    `static double` | `chiSquareDataSetsComparison(long[] observed1, long[] observed2)`
    `static double` | `chiSquareTest(double[] expected, long[] observed)`
    `static boolean` | `chiSquareTest(double[] expected, long[] observed, double alpha)`
    `static double` | `chiSquareTest(long[][] counts)`
    `static boolean` | `chiSquareTest(long[][] counts, double alpha)`
    `static double` | `chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)`
    `static boolean` | `chiSquareTestDataSetsComparison(long[] observed1, long[] observed2, double alpha)`
    `static double` | `g(double[] expected, long[] observed)`
    `static double` | `gDataSetsComparison(long[] observed1, long[] observed2)`
    `static double` | `gTest(double[] expected, long[] observed)`
    `static boolean` | `gTest(double[] expected, long[] observed, double alpha)`
    `static double` | `gTestDataSetsComparison(long[] observed1, long[] observed2)`
    `static boolean` | `gTestDataSetsComparison(long[] observed1, long[] observed2, double alpha)`
    `static double` | `gTestIntrinsic(double[] expected, long[] observed)`
    `static double` | `homoscedasticT(double[] sample1, double[] sample2)`
    `static double` | `homoscedasticT(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)`
    `static double` | `homoscedasticTTest(double[] sample1, double[] sample2)`
    `static boolean` | `homoscedasticTTest(double[] sample1, double[] sample2, double alpha)`
    `static double` | `homoscedasticTTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)`
    `static double` | `oneWayAnovaFValue(Collection<double[]> categoryData)`
    `static double` | `oneWayAnovaPValue(Collection<double[]> categoryData)`
    `static boolean` | `oneWayAnovaTest(Collection<double[]> categoryData, double alpha)`
    `static double` | `pairedT(double[] sample1, double[] sample2)`
    `static double` | `pairedTTest(double[] sample1, double[] sample2)`
    `static boolean` | `pairedTTest(double[] sample1, double[] sample2, double alpha)`
    `static double` | `rootLogLikelihoodRatio(long k11, long k12, long k21, long k22)`
    `static double` | `t(double[] sample1, double[] sample2)`
    `static double` | `t(double mu, double[] observed)`
    `static double` | `t(double mu, StatisticalSummary sampleStats)`
    `static double` | `t(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)`
    `static double` | `tTest(double[] sample1, double[] sample2)`
    `static boolean` | `tTest(double[] sample1, double[] sample2, double alpha)`
    `static double` | `tTest(double mu, double[] sample)`
    `static boolean` | `tTest(double mu, double[] sample, double alpha)`
    `static double` | `tTest(double mu, StatisticalSummary sampleStats)`
    `static boolean` | `tTest(double mu, StatisticalSummary sampleStats, double alpha)`
    `static double` | `tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2)`
    `static boolean` | `tTest(StatisticalSummary sampleStats1, StatisticalSummary sampleStats2, double alpha)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### T_TEST

          private static final TTest T_TEST

      Singleton TTest instance.

    - #### CHI_SQUARE_TEST

          private static final ChiSquareTest CHI_SQUARE_TEST

      Singleton ChiSquareTest instance.

    - #### ONE_WAY_ANANOVA

          private static final OneWayAnova ONE_WAY_ANANOVA

      Singleton OneWayAnova instance.

    - #### G_TEST

          private static final GTest G_TEST

      Singleton G-Test instance.

  - ### Constructor Detail

    - #### TestUtils

          private TestUtils()

      Prevent instantiation.

  - ### Method Detail

    - #### homoscedasticT

          public static double homoscedasticT(double[] sample1,
                              double[] sample2)
                                       throws NullArgumentException,
                                              NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.homoscedasticT(double[], double[])`

    - #### homoscedasticT

          public static double homoscedasticT(StatisticalSummary sampleStats1,
                              StatisticalSummary sampleStats2)
                                       throws NullArgumentException,
                                              NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.homoscedasticT(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### homoscedasticTTest

          public static boolean homoscedasticTTest(double[] sample1,
                                   double[] sample2,
                                   double alpha)
                                            throws NullArgumentException,
                                                   NumberIsTooSmallException,
                                                   OutOfRangeException,
                                                   MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.homoscedasticTTest(double[], double[], double)`

    - #### homoscedasticTTest

          public static double homoscedasticTTest(double[] sample1,
                                  double[] sample2)
                                           throws NullArgumentException,
                                                  NumberIsTooSmallException,
                                                  MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.homoscedasticTTest(double[], double[])`

    - #### homoscedasticTTest

          public static double homoscedasticTTest(StatisticalSummary sampleStats1,
                                  StatisticalSummary sampleStats2)
                                           throws NullArgumentException,
                                                  NumberIsTooSmallException,
                                                  MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.homoscedasticTTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### pairedT

          public static double pairedT(double[] sample1,
                       double[] sample2)
                                throws NullArgumentException,
                                       NoDataException,
                                       DimensionMismatchException,
                                       NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NoDataException`
        `DimensionMismatchException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.pairedT(double[], double[])`

    - #### pairedTTest

          public static boolean pairedTTest(double[] sample1,
                            double[] sample2,
                            double alpha)
                                     throws NullArgumentException,
                                            NoDataException,
                                            DimensionMismatchException,
                                            NumberIsTooSmallException,
                                            OutOfRangeException,
                                            MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NoDataException`
        `DimensionMismatchException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.pairedTTest(double[], double[], double)`

    - #### pairedTTest

          public static double pairedTTest(double[] sample1,
                           double[] sample2)
                                    throws NullArgumentException,
                                           NoDataException,
                                           DimensionMismatchException,
                                           NumberIsTooSmallException,
                                           MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NoDataException`
        `DimensionMismatchException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.pairedTTest(double[], double[])`

    - #### t

          public static double t(double mu,
                 double[] observed)
                          throws NullArgumentException,
                                 NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.t(double, double[])`

    - #### t

          public static double t(double mu,
                 StatisticalSummary sampleStats)
                          throws NullArgumentException,
                                 NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.t(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### t

          public static double t(double[] sample1,
                 double[] sample2)
                          throws NullArgumentException,
                                 NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.t(double[], double[])`

    - #### t

          public static double t(StatisticalSummary sampleStats1,
                 StatisticalSummary sampleStats2)
                          throws NullArgumentException,
                                 NumberIsTooSmallException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
      See Also:
        `TTest.t(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### tTest

          public static boolean tTest(double mu,
                      double[] sample,
                      double alpha)
                               throws NullArgumentException,
                                      NumberIsTooSmallException,
                                      OutOfRangeException,
                                      MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double, double[], double)`

    - #### tTest

          public static double tTest(double mu,
                     double[] sample)
                              throws NullArgumentException,
                                     NumberIsTooSmallException,
                                     MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double, double[])`

    - #### tTest

          public static boolean tTest(double mu,
                      StatisticalSummary sampleStats,
                      double alpha)
                               throws NullArgumentException,
                                      NumberIsTooSmallException,
                                      OutOfRangeException,
                                      MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)`

    - #### tTest

          public static double tTest(double mu,
                     StatisticalSummary sampleStats)
                              throws NullArgumentException,
                                     NumberIsTooSmallException,
                                     MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### tTest

          public static boolean tTest(double[] sample1,
                      double[] sample2,
                      double alpha)
                               throws NullArgumentException,
                                      NumberIsTooSmallException,
                                      OutOfRangeException,
                                      MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double[], double[], double)`

    - #### tTest

          public static double tTest(double[] sample1,
                     double[] sample2)
                              throws NullArgumentException,
                                     NumberIsTooSmallException,
                                     MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(double[], double[])`

    - #### tTest

          public static boolean tTest(StatisticalSummary sampleStats1,
                      StatisticalSummary sampleStats2,
                      double alpha)
                               throws NullArgumentException,
                                      NumberIsTooSmallException,
                                      OutOfRangeException,
                                      MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)`

    - #### tTest

          public static double tTest(StatisticalSummary sampleStats1,
                     StatisticalSummary sampleStats2)
                              throws NullArgumentException,
                                     NumberIsTooSmallException,
                                     MaxCountExceededException

      Throws:
        `NullArgumentException`
        `NumberIsTooSmallException`
        `MaxCountExceededException`
      See Also:
        `TTest.tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)`

    - #### chiSquare

          public static double chiSquare(double[] expected,
                         long[] observed)
                                  throws NotPositiveException,
                                         NotStrictlyPositiveException,
                                         DimensionMismatchException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
      See Also:
        `ChiSquareTest.chiSquare(double[], long[])`

    - #### chiSquare

          public static double chiSquare(long[][] counts)
                                  throws NullArgumentException,
                                         NotPositiveException,
                                         DimensionMismatchException

      Throws:
        `NullArgumentException`
        `NotPositiveException`
        `DimensionMismatchException`
      See Also:
        `ChiSquareTest.chiSquare(long[][])`

    - #### chiSquareTest

          public static boolean chiSquareTest(double[] expected,
                              long[] observed,
                              double alpha)
                                       throws NotPositiveException,
                                              NotStrictlyPositiveException,
                                              DimensionMismatchException,
                                              OutOfRangeException,
                                              MaxCountExceededException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `ChiSquareTest.chiSquareTest(double[], long[], double)`

    - #### chiSquareTest

          public static double chiSquareTest(double[] expected,
                             long[] observed)
                                      throws NotPositiveException,
                                             NotStrictlyPositiveException,
                                             DimensionMismatchException,
                                             MaxCountExceededException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
        `MaxCountExceededException`
      See Also:
        `ChiSquareTest.chiSquareTest(double[], long[])`

    - #### chiSquareTest

          public static boolean chiSquareTest(long[][] counts,
                              double alpha)
                                       throws NullArgumentException,
                                              DimensionMismatchException,
                                              NotPositiveException,
                                              OutOfRangeException,
                                              MaxCountExceededException

      Throws:
        `NullArgumentException`
        `DimensionMismatchException`
        `NotPositiveException`
        `OutOfRangeException`
        `MaxCountExceededException`
      See Also:
        `ChiSquareTest.chiSquareTest(long[][], double)`

    - #### chiSquareTest

          public static double chiSquareTest(long[][] counts)
                                      throws NullArgumentException,
                                             DimensionMismatchException,
                                             NotPositiveException,
                                             MaxCountExceededException

      Throws:
        `NullArgumentException`
        `DimensionMismatchException`
        `NotPositiveException`
        `MaxCountExceededException`
      See Also:
        `ChiSquareTest.chiSquareTest(long[][])`

    - #### chiSquareDataSetsComparison

          public static double chiSquareDataSetsComparison(long[] observed1,
                                           long[] observed2)
                                                    throws DimensionMismatchException,
                                                           NotPositiveException,
                                                           ZeroException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
      Since:
        1.2
      See Also:
        `ChiSquareTest.chiSquareDataSetsComparison(long[], long[])`

    - #### chiSquareTestDataSetsComparison

          public static double chiSquareTestDataSetsComparison(long[] observed1,
                                               long[] observed2)
                                                        throws DimensionMismatchException,
                                                               NotPositiveException,
                                                               ZeroException,
                                                               MaxCountExceededException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
        `MaxCountExceededException`
      Since:
        1.2
      See Also:
        `ChiSquareTest.chiSquareTestDataSetsComparison(long[], long[])`

    - #### chiSquareTestDataSetsComparison

          public static boolean chiSquareTestDataSetsComparison(long[] observed1,
                                                long[] observed2,
                                                double alpha)
                                                         throws DimensionMismatchException,
                                                                NotPositiveException,
                                                                ZeroException,
                                                                OutOfRangeException,
                                                                MaxCountExceededException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
        `OutOfRangeException`
        `MaxCountExceededException`
      Since:
        1.2
      See Also:
        `ChiSquareTest.chiSquareTestDataSetsComparison(long[], long[], double)`

    - #### oneWayAnovaFValue

          public static double oneWayAnovaFValue(Collection<double[]> categoryData)
                                          throws NullArgumentException,
                                                 DimensionMismatchException

      Throws:
        `NullArgumentException`
        `DimensionMismatchException`
      Since:
        1.2
      See Also:
        `OneWayAnova.anovaFValue(Collection)`

    - #### oneWayAnovaPValue

          public static double oneWayAnovaPValue(Collection<double[]> categoryData)
                                          throws NullArgumentException,
                                                 DimensionMismatchException,
                                                 ConvergenceException,
                                                 MaxCountExceededException

      Throws:
        `NullArgumentException`
        `DimensionMismatchException`
        `ConvergenceException`
        `MaxCountExceededException`
      Since:
        1.2
      See Also:
        `OneWayAnova.anovaPValue(Collection)`

    - #### oneWayAnovaTest

          public static boolean oneWayAnovaTest(Collection<double[]> categoryData,
                                double alpha)
                                         throws NullArgumentException,
                                                DimensionMismatchException,
                                                OutOfRangeException,
                                                ConvergenceException,
                                                MaxCountExceededException

      Throws:
        `NullArgumentException`
        `DimensionMismatchException`
        `OutOfRangeException`
        `ConvergenceException`
        `MaxCountExceededException`
      Since:
        1.2
      See Also:
        `OneWayAnova.anovaTest(Collection,double)`

    - #### g

          public static double g(double[] expected,
                 long[] observed)
                          throws NotPositiveException,
                                 NotStrictlyPositiveException,
                                 DimensionMismatchException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
      Since:
        3.1
      See Also:
        `GTest.g(double[], long[])`

    - #### gTest

          public static double gTest(double[] expected,
                     long[] observed)
                              throws NotPositiveException,
                                     NotStrictlyPositiveException,
                                     DimensionMismatchException,
                                     MaxCountExceededException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
        `MaxCountExceededException`
      Since:
        3.1
      See Also:
        `GTest.gTest( double[], long[] )`

    - #### gTestIntrinsic

          public static double gTestIntrinsic(double[] expected,
                              long[] observed)
                                       throws NotPositiveException,
                                              NotStrictlyPositiveException,
                                              DimensionMismatchException,
                                              MaxCountExceededException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
        `MaxCountExceededException`
      Since:
        3.1
      See Also:
        `GTest.gTestIntrinsic(double[], long[] )`

    - #### gTest

          public static boolean gTest(double[] expected,
                      long[] observed,
                      double alpha)
                               throws NotPositiveException,
                                      NotStrictlyPositiveException,
                                      DimensionMismatchException,
                                      OutOfRangeException,
                                      MaxCountExceededException

      Throws:
        `NotPositiveException`
        `NotStrictlyPositiveException`
        `DimensionMismatchException`
        `OutOfRangeException`
        `MaxCountExceededException`
      Since:
        3.1
      See Also:
        `GTest.gTest( double[],long[],double)`

    - #### gDataSetsComparison

          public static double gDataSetsComparison(long[] observed1,
                                   long[] observed2)
                                            throws DimensionMismatchException,
                                                   NotPositiveException,
                                                   ZeroException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
      Since:
        3.1
      See Also:
        `GTest.gDataSetsComparison(long[], long[])`

    - #### rootLogLikelihoodRatio

          public static double rootLogLikelihoodRatio(long k11,
                                      long k12,
                                      long k21,
                                      long k22)
                                               throws DimensionMismatchException,
                                                      NotPositiveException,
                                                      ZeroException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
      Since:
        3.1
      See Also:
        `GTest.rootLogLikelihoodRatio(long, long, long, long)`

    - #### gTestDataSetsComparison

          public static double gTestDataSetsComparison(long[] observed1,
                                       long[] observed2)
                                                throws DimensionMismatchException,
                                                       NotPositiveException,
                                                       ZeroException,
                                                       MaxCountExceededException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
        `MaxCountExceededException`
      Since:
        3.1
      See Also:
        `GTest.gTestDataSetsComparison(long[], long[])`

    - #### gTestDataSetsComparison

          public static boolean gTestDataSetsComparison(long[] observed1,
                                        long[] observed2,
                                        double alpha)
                                                 throws DimensionMismatchException,
                                                        NotPositiveException,
                                                        ZeroException,
                                                        OutOfRangeException,
                                                        MaxCountExceededException

      Throws:
        `DimensionMismatchException`
        `NotPositiveException`
        `ZeroException`
        `OutOfRangeException`
        `MaxCountExceededException`
      Since:
        3.1
      See Also:
        `GTest.gTestDataSetsComparison(long[],long[],double)`

Copyright (c) 2003-2013 Apache Software Foundation