001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.math4.legacy.stat.inference;
018
019import java.util.Collection;
020
021import org.apache.commons.rng.UniformRandomProvider;
022import org.apache.commons.statistics.distribution.ContinuousDistribution;
023import org.apache.commons.math4.legacy.exception.ConvergenceException;
024import org.apache.commons.math4.legacy.exception.DimensionMismatchException;
025import org.apache.commons.math4.legacy.exception.InsufficientDataException;
026import org.apache.commons.math4.legacy.exception.MaxCountExceededException;
027import org.apache.commons.math4.legacy.exception.NoDataException;
028import org.apache.commons.math4.legacy.exception.NotPositiveException;
029import org.apache.commons.math4.legacy.exception.NotStrictlyPositiveException;
030import org.apache.commons.math4.legacy.exception.NullArgumentException;
031import org.apache.commons.math4.legacy.exception.NumberIsTooSmallException;
032import org.apache.commons.math4.legacy.exception.OutOfRangeException;
033import org.apache.commons.math4.legacy.exception.ZeroException;
034import org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary;
035
036/**
037 * A collection of static methods to create inference test instances or to
038 * perform inference tests.
039 *
040 * @since 1.1
041 */
042public final class InferenceTestUtils {
043
044    /** Singleton TTest instance. */
045    private static final TTest T_TEST = new TTest();
046
047    /** Singleton ChiSquareTest instance. */
048    private static final ChiSquareTest CHI_SQUARE_TEST = new ChiSquareTest();
049
050    /** Singleton OneWayAnova instance. */
051    private static final OneWayAnova ONE_WAY_ANANOVA = new OneWayAnova();
052
053    /** Singleton G-Test instance. */
054    private static final GTest G_TEST = new GTest();
055
056    /** Singleton K-S test instance. */
057    private static final KolmogorovSmirnovTest KS_TEST = new KolmogorovSmirnovTest();
058
059    /**
060     * Prevent instantiation.
061     */
062    private InferenceTestUtils() {
063        super();
064    }
065
066    // CHECKSTYLE: stop JavadocMethodCheck
067
068    /**
069     * @param sample1 array of sample data values
070     * @param sample2 array of sample data values
071     * @return t statistic
072     * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticT(double[], double[])
073     */
074    public static double homoscedasticT(final double[] sample1, final double[] sample2)
075        throws NullArgumentException, NumberIsTooSmallException {
076        return T_TEST.homoscedasticT(sample1, sample2);
077    }
078
079    /**
080     * @param sampleStats1 StatisticalSummary describing data from the first sample
081     * @param sampleStats2 StatisticalSummary describing data from the second sample
082     * @return t statistic
083     * @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)
084     */
085    public static double homoscedasticT(final StatisticalSummary sampleStats1,
086                                        final StatisticalSummary sampleStats2)
087        throws NullArgumentException, NumberIsTooSmallException {
088        return T_TEST.homoscedasticT(sampleStats1, sampleStats2);
089    }
090
091    /**
092     * @param sample1 array of sample data values
093     * @param sample2 array of sample data values
094     * @param alpha significance level of the test
095     * @return true if the null hypothesis can be rejected with
096     * confidence 1 - alpha
097     * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticTTest(double[], double[], double)
098     */
099    public static boolean homoscedasticTTest(final double[] sample1, final double[] sample2,
100                                             final double alpha)
101        throws NullArgumentException, NumberIsTooSmallException,
102        OutOfRangeException, MaxCountExceededException {
103        return T_TEST.homoscedasticTTest(sample1, sample2, alpha);
104    }
105
106    /**
107     * @param sample1 array of sample data values
108     * @param sample2 array of sample data values
109     * @return p-value for t-test
110     * @see org.apache.commons.math4.legacy.stat.inference.TTest#homoscedasticTTest(double[], double[])
111     */
112    public static double homoscedasticTTest(final double[] sample1, final double[] sample2)
113        throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException {
114        return T_TEST.homoscedasticTTest(sample1, sample2);
115    }
116
117    /**
118     * @param sampleStats1  StatisticalSummary describing data from the first sample
119     * @param sampleStats2  StatisticalSummary describing data from the second sample
120     * @return p-value for t-test
121     * @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)
122     */
123    public static double homoscedasticTTest(final StatisticalSummary sampleStats1,
124                                            final StatisticalSummary sampleStats2)
125        throws NullArgumentException, NumberIsTooSmallException, MaxCountExceededException {
126        return T_TEST.homoscedasticTTest(sampleStats1, sampleStats2);
127    }
128
129    /**
130     * @param sample1 array of sample data values
131     * @param sample2 array of sample data values
132     * @return t statistic
133     * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedT(double[], double[])
134     */
135    public static double pairedT(final double[] sample1, final double[] sample2)
136        throws NullArgumentException, NoDataException,
137        DimensionMismatchException, NumberIsTooSmallException {
138        return T_TEST.pairedT(sample1, sample2);
139    }
140
141    /**
142     * @param sample1 array of sample data values
143     * @param sample2 array of sample data values
144     * @param alpha significance level of the test
145     * @return true if the null hypothesis can be rejected with
146     * confidence 1 - alpha
147     * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedTTest(double[], double[], double)
148     */
149    public static boolean pairedTTest(final double[] sample1, final double[] sample2,
150                                      final double alpha)
151        throws NullArgumentException, NoDataException, DimensionMismatchException,
152        NumberIsTooSmallException, OutOfRangeException, MaxCountExceededException {
153        return T_TEST.pairedTTest(sample1, sample2, alpha);
154    }
155
156    /**
157     * @param sample1 array of sample data values
158     * @param sample2 array of sample data values
159     * @return p-value for t-test
160     * @see org.apache.commons.math4.legacy.stat.inference.TTest#pairedTTest(double[], double[])
161     */
162    public static double pairedTTest(final double[] sample1, final double[] sample2)
163        throws NullArgumentException, NoDataException, DimensionMismatchException,
164        NumberIsTooSmallException, MaxCountExceededException {
165        return T_TEST.pairedTTest(sample1, sample2);
166    }
167
168    /**
169     * @param mu comparison constant
170     * @param observed array of values
171     * @return t statistic
172     * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double, double[])
173     */
174    public static double t(final double mu, final double[] observed)
175        throws NullArgumentException, NumberIsTooSmallException {
176        return T_TEST.t(mu, observed);
177    }
178
179    /**
180     * @param mu comparison constant
181     * @param sampleStats DescriptiveStatistics holding sample summary statitstics
182     * @return t statistic
183     * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
184     */
185    public static double t(final double mu, final StatisticalSummary sampleStats)
186        throws NullArgumentException, NumberIsTooSmallException {
187        return T_TEST.t(mu, sampleStats);
188    }
189
190    /**
191     * @param sample1 array of sample data values
192     * @param sample2 array of sample data values
193     * @return t statistic
194     * @see org.apache.commons.math4.legacy.stat.inference.TTest#t(double[], double[])
195     */
196    public static double t(final double[] sample1, final double[] sample2)
197        throws NullArgumentException, NumberIsTooSmallException {
198        return T_TEST.t(sample1, sample2);
199    }
200
201    /**
202     * @param sampleStats1 StatisticalSummary describing data from the first sample
203     * @param sampleStats2 StatisticalSummary describing data from the second sample
204     * @return t statistic
205     * @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)
206     */
207    public static double t(final StatisticalSummary sampleStats1,
208                           final StatisticalSummary sampleStats2)
209        throws NullArgumentException, NumberIsTooSmallException {
210        return T_TEST.t(sampleStats1, sampleStats2);
211    }
212
213    /**
214     * @param mu constant value to compare sample mean against
215     * @param sample array of 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, double[], double)
219     */
220    public static boolean tTest(final double mu, final double[] sample, final double alpha)
221        throws NullArgumentException, NumberIsTooSmallException,
222        OutOfRangeException, MaxCountExceededException {
223        return T_TEST.tTest(mu, sample, alpha);
224    }
225
226    /**
227     * @param mu constant value to compare sample mean against
228     * @param sample array of sample data values
229     * @return p-value
230     * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, double[])
231     */
232    public static double tTest(final double mu, final double[] sample)
233        throws NullArgumentException, NumberIsTooSmallException,
234        MaxCountExceededException {
235        return T_TEST.tTest(mu, sample);
236    }
237
238    /**
239     * @param mu constant value to compare sample mean against
240     * @param sampleStats StatisticalSummary describing sample data values
241     * @param alpha significance level of the test
242     * @return p-value
243     * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary, double)
244     */
245    public static boolean tTest(final double mu, final StatisticalSummary sampleStats,
246                                final double alpha)
247        throws NullArgumentException, NumberIsTooSmallException,
248        OutOfRangeException, MaxCountExceededException {
249        return T_TEST.tTest(mu, sampleStats, alpha);
250    }
251
252    /**
253     * @param mu constant value to compare sample mean against
254     * @param sampleStats StatisticalSummary describing sample data
255     * @return p-value
256     * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double, org.apache.commons.math4.legacy.stat.descriptive.StatisticalSummary)
257     */
258    public static double tTest(final double mu, final StatisticalSummary sampleStats)
259        throws NullArgumentException, NumberIsTooSmallException,
260        MaxCountExceededException {
261        return T_TEST.tTest(mu, sampleStats);
262    }
263
264    /**
265     * @param sample1 array of sample data values
266     * @param sample2 array of sample data values
267     * @param alpha significance level of the test
268     * @return true if the null hypothesis can be rejected with
269     * confidence 1 - alpha
270     * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double[], double[], double)
271     */
272    public static boolean tTest(final double[] sample1, final double[] sample2,
273                                final double alpha)
274        throws NullArgumentException, NumberIsTooSmallException,
275        OutOfRangeException, MaxCountExceededException {
276        return T_TEST.tTest(sample1, sample2, alpha);
277    }
278
279    /**
280     * @param sample1 array of sample data values
281     * @param sample2 array of sample data values
282     * @return p-value for t-test
283     * @see org.apache.commons.math4.legacy.stat.inference.TTest#tTest(double[], double[])
284     */
285    public static double tTest(final double[] sample1, final double[] sample2)
286        throws NullArgumentException, NumberIsTooSmallException,
287        MaxCountExceededException {
288        return T_TEST.tTest(sample1, sample2);
289    }
290
291    /**
292     * @param sampleStats1 StatisticalSummary describing sample data values
293     * @param sampleStats2 StatisticalSummary describing sample data values
294     * @param alpha significance level of the test
295     * @return true if the null hypothesis can be rejected with
296     * confidence 1 - alpha
297     * @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)
298     */
299    public static boolean tTest(final StatisticalSummary sampleStats1,
300                                final StatisticalSummary sampleStats2,
301                                final double alpha)
302        throws NullArgumentException, NumberIsTooSmallException,
303        OutOfRangeException, MaxCountExceededException {
304        return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
305    }
306
307    /**
308     * @param sampleStats1  StatisticalSummary describing data from the first sample
309     * @param sampleStats2  StatisticalSummary describing data from the second sample
310     * @return p-value for t-test
311     * @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)
312     */
313    public static double tTest(final StatisticalSummary sampleStats1,
314                               final StatisticalSummary sampleStats2)
315        throws NullArgumentException, NumberIsTooSmallException,
316        MaxCountExceededException {
317        return T_TEST.tTest(sampleStats1, sampleStats2);
318    }
319
320    /**
321     * @param observed array of observed frequency counts
322     * @param expected array of expected frequency counts
323     * @return chiSquare test statistic
324* @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquare(double[], long[])
325     */
326    public static double chiSquare(final double[] expected, final long[] observed)
327        throws NotPositiveException, NotStrictlyPositiveException,
328        DimensionMismatchException {
329        return CHI_SQUARE_TEST.chiSquare(expected, observed);
330    }
331
332    /**
333     * @param counts array representation of 2-way table
334     * @return chiSquare test statistic
335     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquare(long[][])
336     */
337    public static double chiSquare(final long[][] counts)
338        throws NullArgumentException, NotPositiveException,
339        DimensionMismatchException {
340        return CHI_SQUARE_TEST.chiSquare(counts);
341    }
342
343    /**
344     * @param observed array of observed frequency counts
345     * @param expected array of expected frequency counts
346     * @param alpha significance level of the test
347     * @return true iff null hypothesis can be rejected with confidence
348     * 1 - alpha
349     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(double[], long[], double)
350     */
351    public static boolean chiSquareTest(final double[] expected, final long[] observed,
352                                        final double alpha)
353        throws NotPositiveException, NotStrictlyPositiveException,
354        DimensionMismatchException, OutOfRangeException, MaxCountExceededException {
355        return CHI_SQUARE_TEST.chiSquareTest(expected, observed, alpha);
356    }
357
358    /**
359     * @param observed array of observed frequency counts
360     * @param expected array of expected frequency counts
361     * @return p-value
362     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(double[], long[])
363     */
364    public static double chiSquareTest(final double[] expected, final long[] observed)
365        throws NotPositiveException, NotStrictlyPositiveException,
366        DimensionMismatchException, MaxCountExceededException {
367        return CHI_SQUARE_TEST.chiSquareTest(expected, observed);
368    }
369
370    /**
371     * @param counts array representation of 2-way table
372     * @param alpha significance level of the test
373     * @return true iff null hypothesis can be rejected with confidence
374     * 1 - alpha
375     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(long[][], double)
376     */
377    public static boolean chiSquareTest(final long[][] counts, final double alpha)
378        throws NullArgumentException, DimensionMismatchException,
379        NotPositiveException, OutOfRangeException, MaxCountExceededException {
380        return CHI_SQUARE_TEST.chiSquareTest(counts, alpha);
381    }
382
383    /**
384     * @param counts array representation of 2-way table
385     * @return p-value
386     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTest(long[][])
387     */
388    public static double chiSquareTest(final long[][] counts)
389        throws NullArgumentException, DimensionMismatchException,
390        NotPositiveException, MaxCountExceededException {
391        return CHI_SQUARE_TEST.chiSquareTest(counts);
392    }
393
394    /**
395     * @param observed1 array of observed frequency counts of the first data set
396     * @param observed2 array of observed frequency counts of the second data set
397     * @return chiSquare test statistic
398     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareDataSetsComparison(long[], long[])
399     *
400     * @since 1.2
401     */
402    public static double chiSquareDataSetsComparison(final long[] observed1,
403                                                     final long[] observed2)
404        throws DimensionMismatchException, NotPositiveException, ZeroException {
405        return CHI_SQUARE_TEST.chiSquareDataSetsComparison(observed1, observed2);
406    }
407
408    /**
409     * @param observed1 array of observed frequency counts of the first data set
410     * @param observed2 array of observed frequency counts of the second data set
411     * @return p-value
412     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTestDataSetsComparison(long[], long[])
413     *
414     * @since 1.2
415     */
416    public static double chiSquareTestDataSetsComparison(final long[] observed1,
417                                                         final long[] observed2)
418        throws DimensionMismatchException, NotPositiveException, ZeroException,
419        MaxCountExceededException {
420        return CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2);
421    }
422
423    /**
424     * @param observed1 array of observed frequency counts of the first data set
425     * @param observed2 array of observed frequency counts of the second data set
426     * @param alpha significance level of the test
427     * @return true iff null hypothesis can be rejected with confidence
428     * 1 - alpha
429     * @see org.apache.commons.math4.legacy.stat.inference.ChiSquareTest#chiSquareTestDataSetsComparison(long[], long[], double)
430     *
431     * @since 1.2
432     */
433    public static boolean chiSquareTestDataSetsComparison(final long[] observed1,
434                                                          final long[] observed2,
435                                                          final double alpha)
436        throws DimensionMismatchException, NotPositiveException,
437        ZeroException, OutOfRangeException, MaxCountExceededException {
438        return CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2, alpha);
439    }
440
441    /**
442     * @param categoryData <code>Collection</code> of <code>double[]</code>
443     * arrays each containing data for one category
444     * @return Fvalue
445     * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaFValue(Collection)
446     *
447     * @since 1.2
448     */
449    public static double oneWayAnovaFValue(final Collection<double[]> categoryData)
450        throws NullArgumentException, DimensionMismatchException {
451        return ONE_WAY_ANANOVA.anovaFValue(categoryData);
452    }
453
454    /**
455     * @param categoryData <code>Collection</code> of <code>double[]</code>
456     * arrays each containing data for one category
457     * @return Pvalue
458     * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaPValue(Collection)
459     *
460     * @since 1.2
461     */
462    public static double oneWayAnovaPValue(final Collection<double[]> categoryData)
463        throws NullArgumentException, DimensionMismatchException,
464        ConvergenceException, MaxCountExceededException {
465        return ONE_WAY_ANANOVA.anovaPValue(categoryData);
466    }
467
468    /**
469     * @param categoryData <code>Collection</code> of <code>double[]</code>
470     * arrays each containing data for one category
471     * @param alpha significance level of the test
472     * @return true if the null hypothesis can be rejected with
473     * confidence 1 - alpha
474     * @see org.apache.commons.math4.legacy.stat.inference.OneWayAnova#anovaTest(Collection,double)
475     *
476     * @since 1.2
477     */
478    public static boolean oneWayAnovaTest(final Collection<double[]> categoryData,
479                                          final double alpha)
480        throws NullArgumentException, DimensionMismatchException,
481        OutOfRangeException, ConvergenceException, MaxCountExceededException {
482        return ONE_WAY_ANANOVA.anovaTest(categoryData, alpha);
483    }
484
485     /**
486     * @param observed array of observed frequency counts
487     * @param expected array of expected frequency counts
488     * @return G-Test statistic
489     * @see org.apache.commons.math4.legacy.stat.inference.GTest#g(double[], long[])
490     * @since 3.1
491     */
492    public static double g(final double[] expected, final long[] observed)
493        throws NotPositiveException, NotStrictlyPositiveException,
494        DimensionMismatchException {
495        return G_TEST.g(expected, observed);
496    }
497
498    /**
499     * @param observed array of observed frequency counts
500     * @param expected array of expected frequency counts
501     * @return p-value
502     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTest( double[],  long[] )
503     * @since 3.1
504     */
505    public static double gTest(final double[] expected, final long[] observed)
506        throws NotPositiveException, NotStrictlyPositiveException,
507        DimensionMismatchException, MaxCountExceededException {
508        return G_TEST.gTest(expected, observed);
509    }
510
511    /**
512     * @param observed array of observed frequency counts
513     * @param expected array of expected frequency counts
514     * @return p-value
515     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestIntrinsic(double[], long[] )
516     * @since 3.1
517     */
518    public static double gTestIntrinsic(final double[] expected, final long[] observed)
519        throws NotPositiveException, NotStrictlyPositiveException,
520        DimensionMismatchException, MaxCountExceededException {
521        return G_TEST.gTestIntrinsic(expected, observed);
522    }
523
524     /**
525     * @param observed array of observed frequency counts
526     * @param expected array of expected frequency counts
527     * @param alpha significance level of the test
528     * @return true iff null hypothesis can be rejected with confidence 1 -
529     * alpha
530     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTest( double[],long[],double)
531     * @since 3.1
532     */
533    public static boolean gTest(final double[] expected, final long[] observed,
534                                final double alpha)
535        throws NotPositiveException, NotStrictlyPositiveException,
536        DimensionMismatchException, OutOfRangeException, MaxCountExceededException {
537        return G_TEST.gTest(expected, observed, alpha);
538    }
539
540    /**
541     * @param observed1 array of observed frequency counts of the first data set
542     * @param observed2 array of observed frequency counts of the second data
543     * set
544     * @return G-Test statistic
545     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gDataSetsComparison(long[], long[])
546     * @since 3.1
547     */
548    public static double gDataSetsComparison(final long[] observed1,
549                                                  final long[] observed2)
550        throws DimensionMismatchException, NotPositiveException, ZeroException {
551        return G_TEST.gDataSetsComparison(observed1, observed2);
552    }
553
554    /**
555     * @param k11 number of times the two events occurred together (AB)
556     * @param k12 number of times the second event occurred WITHOUT the
557     * first event (notA,B)
558     * @param k21 number of times the first event occurred WITHOUT the
559     * second event (A, notB)
560     * @param k22 number of times something else occurred (i.e. was neither
561     * of these events (notA, notB)
562     * @return root log-likelihood ratio
563     * @see org.apache.commons.math4.legacy.stat.inference.GTest#rootLogLikelihoodRatio(long, long, long, long)
564     * @since 3.1
565     */
566    public static double rootLogLikelihoodRatio(final long k11, final long k12, final long k21, final long k22)
567        throws DimensionMismatchException, NotPositiveException, ZeroException {
568        return G_TEST.rootLogLikelihoodRatio(k11, k12, k21, k22);
569    }
570
571
572    /**
573     * @param observed1 array of observed frequency counts of the first data set
574     * @param observed2 array of observed frequency counts of the second data
575     * set
576     * @return p-value
577     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestDataSetsComparison(long[], long[])
578     * @since 3.1
579     */
580    public static double gTestDataSetsComparison(final long[] observed1,
581                                                        final long[] observed2)
582        throws DimensionMismatchException, NotPositiveException, ZeroException,
583        MaxCountExceededException {
584        return G_TEST.gTestDataSetsComparison(observed1, observed2);
585    }
586
587    /**
588     * @param observed1 array of observed frequency counts of the first data set
589     * @param observed2 array of observed frequency counts of the second data
590     * set
591     * @param alpha significance level of the test
592     * @return true iff null hypothesis can be rejected with confidence 1 -
593     * alpha
594     * @see org.apache.commons.math4.legacy.stat.inference.GTest#gTestDataSetsComparison(long[],long[],double)
595     * @since 3.1
596     */
597    public static boolean gTestDataSetsComparison(final long[] observed1,
598                                                  final long[] observed2,
599                                                  final double alpha)
600        throws DimensionMismatchException, NotPositiveException,
601        ZeroException, OutOfRangeException, MaxCountExceededException {
602        return G_TEST.gTestDataSetsComparison(observed1, observed2, alpha);
603    }
604
605    /**
606     * @param dist reference distribution
607     * @param data sample being evaluated
608     * @return Kolmogorov-Smirnov statistic \(D_n\)
609     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovStatistic(ContinuousDistribution, double[])
610     * @since 3.3
611     */
612    public static double kolmogorovSmirnovStatistic(ContinuousDistribution dist, double[] data)
613            throws InsufficientDataException, NullArgumentException {
614        return KS_TEST.kolmogorovSmirnovStatistic(dist, data);
615    }
616
617    /**
618     * @param dist reference distribution
619     * @param data sample being being evaluated
620     * @return the p-value associated with the null hypothesis that {@code data} is a sample from
621     *         {@code distribution}
622     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[])
623     * @since 3.3
624     */
625    public static double kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data)
626            throws InsufficientDataException, NullArgumentException {
627        return KS_TEST.kolmogorovSmirnovTest(dist, data);
628    }
629
630    /**
631     * @param dist reference distribution
632     * @param data sample being being evaluated
633     * @param strict whether or not to force exact computation of the p-value
634     * @return the p-value associated with the null hypothesis that {@code data} is a sample from
635     *         {@code distribution}
636     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[], boolean)
637     * @since 3.3
638     */
639    public static double kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data, boolean strict)
640            throws InsufficientDataException, NullArgumentException {
641        return KS_TEST.kolmogorovSmirnovTest(dist, data, strict);
642    }
643
644    /**
645     * @param dist reference distribution
646     * @param data sample being being evaluated
647     * @param alpha significance level of the test
648     * @return true iff the null hypothesis that {@code data} is a sample from {@code distribution}
649     *         can be rejected with confidence 1 - {@code alpha}
650     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(ContinuousDistribution, double[], double)
651     * @since 3.3
652     */
653    public static boolean kolmogorovSmirnovTest(ContinuousDistribution dist, double[] data, double alpha)
654            throws InsufficientDataException, NullArgumentException {
655        return KS_TEST.kolmogorovSmirnovTest(dist, data, alpha);
656    }
657
658    /**
659     * @param x first sample
660     * @param y second sample
661     * @return test statistic \(D_{n,m}\) used to evaluate the null hypothesis that {@code x} and
662     *         {@code y} represent samples from the same underlying distribution
663     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovStatistic(double[], double[])
664     * @since 3.3
665     */
666    public static double kolmogorovSmirnovStatistic(double[] x, double[] y)
667            throws InsufficientDataException, NullArgumentException {
668        return KS_TEST.kolmogorovSmirnovStatistic(x, y);
669    }
670
671    /**
672     * @param x first sample dataset
673     * @param y second sample dataset
674     * @return p-value associated with the null hypothesis that {@code x} and {@code y} represent
675     *         samples from the same distribution
676     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(double[], double[])
677     * @since 3.3
678     */
679    public static double kolmogorovSmirnovTest(double[] x, double[] y)
680            throws InsufficientDataException, NullArgumentException {
681        return KS_TEST.kolmogorovSmirnovTest(x, y);
682    }
683
684    /**
685     * @param x first sample dataset.
686     * @param y second sample dataset.
687     * @param strict whether or not the probability to compute is expressed as
688     * a strict inequality (ignored for large samples).
689     * @return p-value associated with the null hypothesis that {@code x} and
690     * {@code y} represent samples from the same distribution.
691     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#kolmogorovSmirnovTest(double[], double[], boolean)
692     * @since 3.3
693     */
694    public static double kolmogorovSmirnovTest(double[] x, double[] y, boolean strict)
695            throws InsufficientDataException, NullArgumentException  {
696        return KS_TEST.kolmogorovSmirnovTest(x, y, strict);
697    }
698
699    /**
700     * @param d D-statistic value
701     * @param n first sample size
702     * @param m second sample size
703     * @param strict whether or not the probability to compute is expressed as a strict inequality
704     * @return probability that a randomly selected m-n partition of m + n generates \(D_{n,m}\)
705     *         greater than (resp. greater than or equal to) {@code d}
706     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#exactP(double, int, int, boolean)
707     * @since 3.3
708     */
709    public static double exactP(double d, int m, int n, boolean strict) {
710        return KS_TEST.exactP(d, n, m, strict);
711    }
712
713    /**
714     * @param d D-statistic value
715     * @param n first sample size
716     * @param m second sample size
717     * @return approximate probability that a randomly selected m-n partition of m + n generates
718     *         \(D_{n,m}\) greater than {@code d}
719     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#approximateP(double, int, int)
720     * @since 3.3
721     */
722    public static double approximateP(double d, int n, int m) {
723        return KS_TEST.approximateP(d, n, m);
724    }
725
726    /**
727     * @param d D-statistic value
728     * @param n first sample size
729     * @param m second sample size
730     * @param iterations number of random partitions to generate
731     * @param strict whether or not the probability to compute is expressed as a strict inequality
732     * @param rng RNG used for generating the partitions.
733     * @return proportion of randomly generated m-n partitions of m + n that result in \(D_{n,m}\)
734     * greater than (resp. greater than or equal to) {@code d}
735     * @see org.apache.commons.math4.legacy.stat.inference.KolmogorovSmirnovTest#monteCarloP(double,int,int,boolean,int,UniformRandomProvider)
736     * @since 3.3
737     */
738    public static double monteCarloP(double d, int n, int m, boolean strict, int iterations, UniformRandomProvider rng) {
739        return KS_TEST.monteCarloP(d, n, m, strict, iterations, rng);
740    }
741
742
743    // CHECKSTYLE: resume JavadocMethodCheck
744}