InferenceTestUtils.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.math4.legacy.stat.inference;

  18. import java.util.Collection;

  19. import org.apache.commons.rng.UniformRandomProvider;
  20. import org.apache.commons.statistics.distribution.ContinuousDistribution;
  21. import org.apache.commons.math4.legacy.exception.ConvergenceException;
  22. import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
  23. import org.apache.commons.math4.legacy.exception.InsufficientDataException;
  24. import org.apache.commons.math4.legacy.exception.MaxCountExceededException;
  25. import org.apache.commons.math4.legacy.exception.NoDataException;
  26. import org.apache.commons.math4.legacy.exception.NotPositiveException;
  27. import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
  28. import org.apache.commons.math4.legacy.exception.NullArgumentException;
  29. import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
  30. import org.apache.commons.math4.legacy.exception.OutOfRangeException;
  31. import org.apache.commons.math4.legacy.exception.ZeroException;
  32. import org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary;

  33. /**
  34.  * A collection of static methods to create inference test instances or to
  35.  * perform inference tests.
  36.  *
  37.  * @since 1.1
  38.  */
  39. public final class InferenceTestUtils {

  40.     /** Singleton TTest instance. */
  41.     private static final TTest T_TEST = new TTest();

  42.     /** Singleton ChiSquareTest instance. */
  43.     private static final ChiSquareTest CHI_SQUARE_TEST = new ChiSquareTest();

  44.     /** Singleton OneWayAnova instance. */
  45.     private static final OneWayAnova ONE_WAY_ANANOVA = new OneWayAnova();

  46.     /** Singleton G-Test instance. */
  47.     private static final GTest G_TEST = new GTest();

  48.     /** Singleton K-S test instance. */
  49.     private static final KolmogorovSmirnovTest KS_TEST = new KolmogorovSmirnovTest();

  50.     /**
  51.      * Prevent instantiation.
  52.      */
  53.     private InferenceTestUtils() {
  54.         super();
  55.     }

  56.     // CHECKSTYLE: stop JavadocMethodCheck

  57.     /**
  58.      * @param sample1 array of sample data values
  59.      * @param sample2 array of sample data values
  60.      * @return t statistic
  61.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticT(double[], double[])
  62.      */
  63.     public static double homoscedasticT(final double[] sample1, final double[] sample2)
  64.         throws NullArgumentException, NumberIsTooSmallException {
  65.         return T_TEST.homoscedasticT(sample1, sample2);
  66.     }

  67.     /**
  68.      * @param sampleStats1 StatisticalSummary describing data from the first sample
  69.      * @param sampleStats2 StatisticalSummary describing data from the second sample
  70.      * @return t statistic
  71.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticT(org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  72.      */
  73.     public static double homoscedasticT(final StatisticalSummary sampleStats1,
  74.                                         final StatisticalSummary sampleStats2)
  75.         throws NullArgumentException, NumberIsTooSmallException {
  76.         return T_TEST.homoscedasticT(sampleStats1, sampleStats2);
  77.     }

  78.     /**
  79.      * @param sample1 array of sample data values
  80.      * @param sample2 array of sample data values
  81.      * @param alpha significance level of the test
  82.      * @return true if the null hypothesis can be rejected with
  83.      * confidence 1 - alpha
  84.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticTTest(double[], double[], double)
  85.      */
  86.     public static boolean homoscedasticTTest(final double[] sample1, final double[] sample2,
  87.                                              final double alpha)
  88.         throws NullArgumentException, NumberIsTooSmallException,
  89.         OutOfRangeException, MaxCountExceededException {
  90.         return T_TEST.homoscedasticTTest(sample1, sample2, alpha);
  91.     }

  92.     /**
  93.      * @param sample1 array of sample data values
  94.      * @param sample2 array of sample data values
  95.      * @return p-value for t-test
  96.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticTTest(double[], double[])
  97.      */
  98.     public static double homoscedasticTTest(final double[] sample1, final double[] sample2)
  99.         throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException {
  100.         return T_TEST.homoscedasticTTest(sample1, sample2);
  101.     }

  102.     /**
  103.      * @param sampleStats1  StatisticalSummary describing data from the first sample
  104.      * @param sampleStats2  StatisticalSummary describing data from the second sample
  105.      * @return p-value for t-test
  106.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticTTest(org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  107.      */
  108.     public static double homoscedasticTTest(final StatisticalSummary sampleStats1,
  109.                                             final StatisticalSummary sampleStats2)
  110.         throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException {
  111.         return T_TEST.homoscedasticTTest(sampleStats1, sampleStats2);
  112.     }

  113.     /**
  114.      * @param sample1 array of sample data values
  115.      * @param sample2 array of sample data values
  116.      * @return t statistic
  117.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedT(double[], double[])
  118.      */
  119.     public static double pairedT(final double[] sample1, final double[] sample2)
  120.         throws NullArgumentException, NoDataException,
  121.         DimensionMismatchException, NumberIsTooSmallException {
  122.         return T_TEST.pairedT(sample1, sample2);
  123.     }

  124.     /**
  125.      * @param sample1 array of sample data values
  126.      * @param sample2 array of sample data values
  127.      * @param alpha significance level of the test
  128.      * @return true if the null hypothesis can be rejected with
  129.      * confidence 1 - alpha
  130.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedTTest(double[], double[], double)
  131.      */
  132.     public static boolean pairedTTest(final double[] sample1, final double[] sample2,
  133.                                       final double alpha)
  134.         throws NullArgumentException, NoDataException, DimensionMismatchException,
  135.         NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException {
  136.         return T_TEST.pairedTTest(sample1, sample2, alpha);
  137.     }

  138.     /**
  139.      * @param sample1 array of sample data values
  140.      * @param sample2 array of sample data values
  141.      * @return p-value for t-test
  142.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedTTest(double[], double[])
  143.      */
  144.     public static double pairedTTest(final double[] sample1, final double[] sample2)
  145.         throws NullArgumentException, NoDataException, DimensionMismatchException,
  146.         NumberIsTooSmallException, MaxCountExceededException {
  147.         return T_TEST.pairedTTest(sample1, sample2);
  148.     }

  149.     /**
  150.      * @param mu comparison constant
  151.      * @param observed array of values
  152.      * @return t statistic
  153.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double, double[])
  154.      */
  155.     public static double t(final double mu, final double[] observed)
  156.         throws NullArgumentException, NumberIsTooSmallException {
  157.         return T_TEST.t(mu, observed);
  158.     }

  159.     /**
  160.      * @param mu comparison constant
  161.      * @param sampleStats DescriptiveStatistics holding sample summary statitstics
  162.      * @return t statistic
  163.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  164.      */
  165.     public static double t(final double mu, final StatisticalSummary sampleStats)
  166.         throws NullArgumentException, NumberIsTooSmallException {
  167.         return T_TEST.t(mu, sampleStats);
  168.     }

  169.     /**
  170.      * @param sample1 array of sample data values
  171.      * @param sample2 array of sample data values
  172.      * @return t statistic
  173.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double[], double[])
  174.      */
  175.     public static double t(final double[] sample1, final double[] sample2)
  176.         throws NullArgumentException, NumberIsTooSmallException {
  177.         return T_TEST.t(sample1, sample2);
  178.     }

  179.     /**
  180.      * @param sampleStats1 StatisticalSummary describing data from the first sample
  181.      * @param sampleStats2 StatisticalSummary describing data from the second sample
  182.      * @return t statistic
  183.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  184.      */
  185.     public static double t(final StatisticalSummary sampleStats1,
  186.                            final StatisticalSummary sampleStats2)
  187.         throws NullArgumentException, NumberIsTooSmallException {
  188.         return T_TEST.t(sampleStats1, sampleStats2);
  189.     }

  190.     /**
  191.      * @param mu constant value to compare sample mean against
  192.      * @param sample array of sample data values
  193.      * @param alpha significance level of the test
  194.      * @return p-value
  195.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, double[], double)
  196.      */
  197.     public static boolean tTest(final double mu, final double[] sample, final double alpha)
  198.         throws NullArgumentException, NumberIsTooSmallException,
  199.         OutOfRangeException, MaxCountExceededException {
  200.         return T_TEST.tTest(mu, sample, alpha);
  201.     }

  202.     /**
  203.      * @param mu constant value to compare sample mean against
  204.      * @param sample array of sample data values
  205.      * @return p-value
  206.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, double[])
  207.      */
  208.     public static double tTest(final double mu, final double[] sample)
  209.         throws NullArgumentException, NumberIsTooSmallException,
  210.         MaxCountExceededException {
  211.         return T_TEST.tTest(mu, sample);
  212.     }

  213.     /**
  214.      * @param mu constant value to compare sample mean against
  215.      * @param sampleStats StatisticalSummary describing sample data values
  216.      * @param alpha significance level of the test
  217.      * @return p-value
  218.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, double)
  219.      */
  220.     public static boolean tTest(final double mu, final StatisticalSummary sampleStats,
  221.                                 final double alpha)
  222.         throws NullArgumentException, NumberIsTooSmallException,
  223.         OutOfRangeException, MaxCountExceededException {
  224.         return T_TEST.tTest(mu, sampleStats, alpha);
  225.     }

  226.     /**
  227.      * @param mu constant value to compare sample mean against
  228.      * @param sampleStats StatisticalSummary describing sample data
  229.      * @return p-value
  230.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  231.      */
  232.     public static double tTest(final double mu, final StatisticalSummary sampleStats)
  233.         throws NullArgumentException, NumberIsTooSmallException,
  234.         MaxCountExceededException {
  235.         return T_TEST.tTest(mu, sampleStats);
  236.     }

  237.     /**
  238.      * @param sample1 array of sample data values
  239.      * @param sample2 array of sample data values
  240.      * @param alpha significance level of the test
  241.      * @return true if the null hypothesis can be rejected with
  242.      * confidence 1 - alpha
  243.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double[], double[], double)
  244.      */
  245.     public static boolean tTest(final double[] sample1, final double[] sample2,
  246.                                 final double alpha)
  247.         throws NullArgumentException, NumberIsTooSmallException,
  248.         OutOfRangeException, MaxCountExceededException {
  249.         return T_TEST.tTest(sample1, sample2, alpha);
  250.     }

  251.     /**
  252.      * @param sample1 array of sample data values
  253.      * @param sample2 array of sample data values
  254.      * @return p-value for t-test
  255.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double[], double[])
  256.      */
  257.     public static double tTest(final double[] sample1, final double[] sample2)
  258.         throws NullArgumentException, NumberIsTooSmallException,
  259.         MaxCountExceededException {
  260.         return T_TEST.tTest(sample1, sample2);
  261.     }

  262.     /**
  263.      * @param sampleStats1 StatisticalSummary describing sample data values
  264.      * @param sampleStats2 StatisticalSummary describing sample data values
  265.      * @param alpha significance level of the test
  266.      * @return true if the null hypothesis can be rejected with
  267.      * confidence 1 - alpha
  268.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, double)
  269.      */
  270.     public static boolean tTest(final StatisticalSummary sampleStats1,
  271.                                 final StatisticalSummary sampleStats2,
  272.                                 final double alpha)
  273.         throws NullArgumentException, NumberIsTooSmallException,
  274.         OutOfRangeException, MaxCountExceededException {
  275.         return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
  276.     }

  277.     /**
  278.      * @param sampleStats1  StatisticalSummary describing data from the first sample
  279.      * @param sampleStats2  StatisticalSummary describing data from the second sample
  280.      * @return p-value for t-test
  281.      * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
  282.      */
  283.     public static double tTest(final StatisticalSummary sampleStats1,
  284.                                final StatisticalSummary sampleStats2)
  285.         throws NullArgumentException, NumberIsTooSmallException,
  286.         MaxCountExceededException {
  287.         return T_TEST.tTest(sampleStats1, sampleStats2);
  288.     }

  289.     /**
  290.      * @param observed array of observed frequency counts
  291.      * @param expected array of expected frequency counts
  292.      * @return chiSquare test statistic
  293. * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquare(double[], long[])
  294.      */
  295.     public static double chiSquare(final double[] expected, final long[] observed)
  296.         throws NotPositiveException, NotStrictlyPositiveException,
  297.         DimensionMismatchException {
  298.         return CHI_SQUARE_TEST.chiSquare(expected, observed);
  299.     }

  300.     /**
  301.      * @param counts array representation of 2-way table
  302.      * @return chiSquare test statistic
  303.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquare(long[][])
  304.      */
  305.     public static double chiSquare(final long[][] counts)
  306.         throws NullArgumentException, NotPositiveException,
  307.         DimensionMismatchException {
  308.         return CHI_SQUARE_TEST.chiSquare(counts);
  309.     }

  310.     /**
  311.      * @param observed array of observed frequency counts
  312.      * @param expected array of expected frequency counts
  313.      * @param alpha significance level of the test
  314.      * @return true iff null hypothesis can be rejected with confidence
  315.      * 1 - alpha
  316.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(double[], long[], double)
  317.      */
  318.     public static boolean chiSquareTest(final double[] expected, final long[] observed,
  319.                                         final double alpha)
  320.         throws NotPositiveException, NotStrictlyPositiveException,
  321.         DimensionMismatchException, OutOfRangeException, MaxCountExceededException {
  322.         return CHI_SQUARE_TEST.chiSquareTest(expected, observed, alpha);
  323.     }

  324.     /**
  325.      * @param observed array of observed frequency counts
  326.      * @param expected array of expected frequency counts
  327.      * @return p-value
  328.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(double[], long[])
  329.      */
  330.     public static double chiSquareTest(final double[] expected, final long[] observed)
  331.         throws NotPositiveException, NotStrictlyPositiveException,
  332.         DimensionMismatchException, MaxCountExceededException {
  333.         return CHI_SQUARE_TEST.chiSquareTest(expected, observed);
  334.     }

  335.     /**
  336.      * @param counts array representation of 2-way table
  337.      * @param alpha significance level of the test
  338.      * @return true iff null hypothesis can be rejected with confidence
  339.      * 1 - alpha
  340.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(long[][], double)
  341.      */
  342.     public static boolean chiSquareTest(final long[][] counts, final double alpha)
  343.         throws NullArgumentException, DimensionMismatchException,
  344.         NotPositiveException, OutOfRangeException, MaxCountExceededException {
  345.         return CHI_SQUARE_TEST.chiSquareTest(counts, alpha);
  346.     }

  347.     /**
  348.      * @param counts array representation of 2-way table
  349.      * @return p-value
  350.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(long[][])
  351.      */
  352.     public static double chiSquareTest(final long[][] counts)
  353.         throws NullArgumentException, DimensionMismatchException,
  354.         NotPositiveException, MaxCountExceededException {
  355.         return CHI_SQUARE_TEST.chiSquareTest(counts);
  356.     }

  357.     /**
  358.      * @param observed1 array of observed frequency counts of the first data set
  359.      * @param observed2 array of observed frequency counts of the second data set
  360.      * @return chiSquare test statistic
  361.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareDataSetsComparison(long[], long[])
  362.      *
  363.      * @since 1.2
  364.      */
  365.     public static double chiSquareDataSetsComparison(final long[] observed1,
  366.                                                      final long[] observed2)
  367.         throws DimensionMismatchException, NotPositiveException, ZeroException {
  368.         return CHI_SQUARE_TEST.chiSquareDataSetsComparison(observed1, observed2);
  369.     }

  370.     /**
  371.      * @param observed1 array of observed frequency counts of the first data set
  372.      * @param observed2 array of observed frequency counts of the second data set
  373.      * @return p-value
  374.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTestDataSetsComparison(long[], long[])
  375.      *
  376.      * @since 1.2
  377.      */
  378.     public static double chiSquareTestDataSetsComparison(final long[] observed1,
  379.                                                          final long[] observed2)
  380.         throws DimensionMismatchException, NotPositiveException, ZeroException,
  381.         MaxCountExceededException {
  382.         return CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2);
  383.     }

  384.     /**
  385.      * @param observed1 array of observed frequency counts of the first data set
  386.      * @param observed2 array of observed frequency counts of the second data set
  387.      * @param alpha significance level of the test
  388.      * @return true iff null hypothesis can be rejected with confidence
  389.      * 1 - alpha
  390.      * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTestDataSetsComparison(long[], long[], double)
  391.      *
  392.      * @since 1.2
  393.      */
  394.     public static boolean chiSquareTestDataSetsComparison(final long[] observed1,
  395.                                                           final long[] observed2,
  396.                                                           final double alpha)
  397.         throws DimensionMismatchException, NotPositiveException,
  398.         ZeroException, OutOfRangeException, MaxCountExceededException {
  399.         return CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2, alpha);
  400.     }

  401.     /**
  402.      * @param categoryData <code>Collection</code> of <code>double[]</code>
  403.      * arrays each containing data for one category
  404.      * @return Fvalue
  405.      * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaFValue(Collection)
  406.      *
  407.      * @since 1.2
  408.      */
  409.     public static double oneWayAnovaFValue(final Collection<double[]> categoryData)
  410.         throws NullArgumentException, DimensionMismatchException {
  411.         return ONE_WAY_ANANOVA.anovaFValue(categoryData);
  412.     }

  413.     /**
  414.      * @param categoryData <code>Collection</code> of <code>double[]</code>
  415.      * arrays each containing data for one category
  416.      * @return Pvalue
  417.      * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaPValue(Collection)
  418.      *
  419.      * @since 1.2
  420.      */
  421.     public static double oneWayAnovaPValue(final Collection<double[]> categoryData)
  422.         throws NullArgumentException, DimensionMismatchException,
  423.         ConvergenceException, MaxCountExceededException {
  424.         return ONE_WAY_ANANOVA.anovaPValue(categoryData);
  425.     }

  426.     /**
  427.      * @param categoryData <code>Collection</code> of <code>double[]</code>
  428.      * arrays each containing data for one category
  429.      * @param alpha significance level of the test
  430.      * @return true if the null hypothesis can be rejected with
  431.      * confidence 1 - alpha
  432.      * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaTest(Collection,double)
  433.      *
  434.      * @since 1.2
  435.      */
  436.     public static boolean oneWayAnovaTest(final Collection<double[]> categoryData,
  437.                                           final double alpha)
  438.         throws NullArgumentException, DimensionMismatchException,
  439.         OutOfRangeException, ConvergenceException, MaxCountExceededException {
  440.         return ONE_WAY_ANANOVA.anovaTest(categoryData, alpha);
  441.     }

  442.      /**
  443.      * @param observed array of observed frequency counts
  444.      * @param expected array of expected frequency counts
  445.      * @return G-Test statistic
  446.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#g(double[], long[])
  447.      * @since 3.1
  448.      */
  449.     public static double g(final double[] expected, final long[] observed)
  450.         throws NotPositiveException, NotStrictlyPositiveException,
  451.         DimensionMismatchException {
  452.         return G_TEST.g(expected, observed);
  453.     }

  454.     /**
  455.      * @param observed array of observed frequency counts
  456.      * @param expected array of expected frequency counts
  457.      * @return p-value
  458.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTest( double[],  long[] )
  459.      * @since 3.1
  460.      */
  461.     public static double gTest(final double[] expected, final long[] observed)
  462.         throws NotPositiveException, NotStrictlyPositiveException,
  463.         DimensionMismatchException, MaxCountExceededException {
  464.         return G_TEST.gTest(expected, observed);
  465.     }

  466.     /**
  467.      * @param observed array of observed frequency counts
  468.      * @param expected array of expected frequency counts
  469.      * @return p-value
  470.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestIntrinsic(double[], long[] )
  471.      * @since 3.1
  472.      */
  473.     public static double gTestIntrinsic(final double[] expected, final long[] observed)
  474.         throws NotPositiveException, NotStrictlyPositiveException,
  475.         DimensionMismatchException, MaxCountExceededException {
  476.         return G_TEST.gTestIntrinsic(expected, observed);
  477.     }

  478.      /**
  479.      * @param observed array of observed frequency counts
  480.      * @param expected array of expected frequency counts
  481.      * @param alpha significance level of the test
  482.      * @return true iff null hypothesis can be rejected with confidence 1 -
  483.      * alpha
  484.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTest( double[],long[],double)
  485.      * @since 3.1
  486.      */
  487.     public static boolean gTest(final double[] expected, final long[] observed,
  488.                                 final double alpha)
  489.         throws NotPositiveException, NotStrictlyPositiveException,
  490.         DimensionMismatchException, OutOfRangeException, MaxCountExceededException {
  491.         return G_TEST.gTest(expected, observed, alpha);
  492.     }

  493.     /**
  494.      * @param observed1 array of observed frequency counts of the first data set
  495.      * @param observed2 array of observed frequency counts of the second data
  496.      * set
  497.      * @return G-Test statistic
  498.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gDataSetsComparison(long[], long[])
  499.      * @since 3.1
  500.      */
  501.     public static double gDataSetsComparison(final long[] observed1,
  502.                                                   final long[] observed2)
  503.         throws DimensionMismatchException, NotPositiveException, ZeroException {
  504.         return G_TEST.gDataSetsComparison(observed1, observed2);
  505.     }

  506.     /**
  507.      * @param k11 number of times the two events occurred together (AB)
  508.      * @param k12 number of times the second event occurred WITHOUT the
  509.      * first event (notA,B)
  510.      * @param k21 number of times the first event occurred WITHOUT the
  511.      * second event (A, notB)
  512.      * @param k22 number of times something else occurred (i.e. was neither
  513.      * of these events (notA, notB)
  514.      * @return root log-likelihood ratio
  515.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#rootLogLikelihoodRatio(long, long, long, long)
  516.      * @since 3.1
  517.      */
  518.     public static double rootLogLikelihoodRatio(final long k11, final long k12, final long k21, final long k22)
  519.         throws DimensionMismatchException, NotPositiveException, ZeroException {
  520.         return G_TEST.rootLogLikelihoodRatio(k11, k12, k21, k22);
  521.     }


  522.     /**
  523.      * @param observed1 array of observed frequency counts of the first data set
  524.      * @param observed2 array of observed frequency counts of the second data
  525.      * set
  526.      * @return p-value
  527.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestDataSetsComparison(long[], long[])
  528.      * @since 3.1
  529.      */
  530.     public static double gTestDataSetsComparison(final long[] observed1,
  531.                                                         final long[] observed2)
  532.         throws DimensionMismatchException, NotPositiveException, ZeroException,
  533.         MaxCountExceededException {
  534.         return G_TEST.gTestDataSetsComparison(observed1, observed2);
  535.     }

  536.     /**
  537.      * @param observed1 array of observed frequency counts of the first data set
  538.      * @param observed2 array of observed frequency counts of the second data
  539.      * set
  540.      * @param alpha significance level of the test
  541.      * @return true iff null hypothesis can be rejected with confidence 1 -
  542.      * alpha
  543.      * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestDataSetsComparison(long[],long[],double)
  544.      * @since 3.1
  545.      */
  546.     public static boolean gTestDataSetsComparison(final long[] observed1,
  547.                                                   final long[] observed2,
  548.                                                   final double alpha)
  549.         throws DimensionMismatchException, NotPositiveException,
  550.         ZeroException, OutOfRangeException, MaxCountExceededException {
  551.         return G_TEST.gTestDataSetsComparison(observed1, observed2, alpha);
  552.     }

  553.     /**
  554.      * @param dist reference distribution
  555.      * @param data sample being evaluated
  556.      * @return Kolmogorov-Smirnov statistic \(D_n\)
  557.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovStatistic(ContinuousDistribution, double[])
  558.      * @since 3.3
  559.      */
  560.     public static double kolmogorovSmirnovStatistic(ContinuousDistribution dist, double[] data)
  561.             throws InsufficientDataException, NullArgumentException {
  562.         return KS_TEST.kolmogorovSmirnovStatistic(dist, data);
  563.     }

  564.     /**
  565.      * @param dist reference distribution
  566.      * @param data sample being being evaluated
  567.      * @return the p-value associated with the null hypothesis that {@code data} is a sample from
  568.      *         {@code distribution}
  569.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[])
  570.      * @since 3.3
  571.      */
  572.     public static double kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data)
  573.             throws InsufficientDataException, NullArgumentException {
  574.         return KS_TEST.kolmogorovSmirnovTest(dist, data);
  575.     }

  576.     /**
  577.      * @param dist reference distribution
  578.      * @param data sample being being evaluated
  579.      * @param strict whether or not to force exact computation of the p-value
  580.      * @return the p-value associated with the null hypothesis that {@code data} is a sample from
  581.      *         {@code distribution}
  582.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[], boolean)
  583.      * @since 3.3
  584.      */
  585.     public static double kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data, boolean strict)
  586.             throws InsufficientDataException, NullArgumentException {
  587.         return KS_TEST.kolmogorovSmirnovTest(dist, data, strict);
  588.     }

  589.     /**
  590.      * @param dist reference distribution
  591.      * @param data sample being being evaluated
  592.      * @param alpha significance level of the test
  593.      * @return true iff the null hypothesis that {@code data} is a sample from {@code distribution}
  594.      *         can be rejected with confidence 1 - {@code alpha}
  595.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[], double)
  596.      * @since 3.3
  597.      */
  598.     public static boolean kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data, double alpha)
  599.             throws InsufficientDataException, NullArgumentException {
  600.         return KS_TEST.kolmogorovSmirnovTest(dist, data, alpha);
  601.     }

  602.     /**
  603.      * @param x first sample
  604.      * @param y second sample
  605.      * @return test statistic \(D_{n,m}\) used to evaluate the null hypothesis that {@code x} and
  606.      *         {@code y} represent samples from the same underlying distribution
  607.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovStatistic(double[], double[])
  608.      * @since 3.3
  609.      */
  610.     public static double kolmogorovSmirnovStatistic(double[] x, double[] y)
  611.             throws InsufficientDataException, NullArgumentException {
  612.         return KS_TEST.kolmogorovSmirnovStatistic(x, y);
  613.     }

  614.     /**
  615.      * @param x first sample dataset
  616.      * @param y second sample dataset
  617.      * @return p-value associated with the null hypothesis that {@code x} and {@code y} represent
  618.      *         samples from the same distribution
  619.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(double[], double[])
  620.      * @since 3.3
  621.      */
  622.     public static double kolmogorovSmirnovTest(double[] x, double[] y)
  623.             throws InsufficientDataException, NullArgumentException {
  624.         return KS_TEST.kolmogorovSmirnovTest(x, y);
  625.     }

  626.     /**
  627.      * @param x first sample dataset.
  628.      * @param y second sample dataset.
  629.      * @param strict whether or not the probability to compute is expressed as
  630.      * a strict inequality (ignored for large samples).
  631.      * @return p-value associated with the null hypothesis that {@code x} and
  632.      * {@code y} represent samples from the same distribution.
  633.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(double[], double[], boolean)
  634.      * @since 3.3
  635.      */
  636.     public static double kolmogorovSmirnovTest(double[] x, double[] y, boolean strict)
  637.             throws InsufficientDataException, NullArgumentException  {
  638.         return KS_TEST.kolmogorovSmirnovTest(x, y, strict);
  639.     }

  640.     /**
  641.      * @param d D-statistic value
  642.      * @param n first sample size
  643.      * @param m second sample size
  644.      * @param strict whether or not the probability to compute is expressed as a strict inequality
  645.      * @return probability that a randomly selected m-n partition of m + n generates \(D_{n,m}\)
  646.      *         greater than (resp. greater than or equal to) {@code d}
  647.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#exactP(double, int, int, boolean)
  648.      * @since 3.3
  649.      */
  650.     public static double exactP(double d, int m, int n, boolean strict) {
  651.         return KS_TEST.exactP(d, n, m, strict);
  652.     }

  653.     /**
  654.      * @param d D-statistic value
  655.      * @param n first sample size
  656.      * @param m second sample size
  657.      * @return approximate probability that a randomly selected m-n partition of m + n generates
  658.      *         \(D_{n,m}\) greater than {@code d}
  659.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#approximateP(double, int, int)
  660.      * @since 3.3
  661.      */
  662.     public static double approximateP(double d, int n, int m) {
  663.         return KS_TEST.approximateP(d, n, m);
  664.     }

  665.     /**
  666.      * @param d D-statistic value
  667.      * @param n first sample size
  668.      * @param m second sample size
  669.      * @param iterations number of random partitions to generate
  670.      * @param strict whether or not the probability to compute is expressed as a strict inequality
  671.      * @param rng RNG used for generating the partitions.
  672.      * @return proportion of randomly generated m-n partitions of m + n that result in \(D_{n,m}\)
  673.      * greater than (resp. greater than or equal to) {@code d}
  674.      * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#monteCarloP(double,int,int,boolean,int,UniformRandomProvider)
  675.      * @since 3.3
  676.      */
  677.     public static double monteCarloP(double d, int n, int m, boolean strict, int iterations, UniformRandomProvider rng) {
  678.         return KS_TEST.monteCarloP(d, n, m, strict, iterations, rng);
  679.     }


  680.     // CHECKSTYLE: resume JavadocMethodCheck
  681. }