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     */
017    package org.apache.commons.math.stat.inference;
018    
019    import java.util.Collection;
020    import org.apache.commons.math.MathException;
021    import org.apache.commons.math.stat.descriptive.StatisticalSummary;
022    
023    /**
024     * A collection of static methods to create inference test instances or to
025     * perform inference tests.
026     *
027     * <p>
028     * The set methods are not compatible with using the class in multiple threads,
029     * and have therefore been deprecated (along with the getters).
030     * The setters and getters will be removed in version 3.0.
031     *
032     * @since 1.1
033     * @version $Revision: 1067582 $ $Date: 2011-02-06 04:55:32 +0100 (dim. 06 f??vr. 2011) $
034     */
035    public class TestUtils  {
036    
037        /** Singleton TTest instance using default implementation. */
038        private static TTest tTest = new TTestImpl();
039    
040        /** Singleton ChiSquareTest instance using default implementation. */
041        private static ChiSquareTest chiSquareTest =
042            new ChiSquareTestImpl();
043    
044        /** Singleton ChiSquareTest instance using default implementation. */
045        private static UnknownDistributionChiSquareTest unknownDistributionChiSquareTest =
046            new ChiSquareTestImpl();
047    
048        /** Singleton OneWayAnova instance using default implementation. */
049        private static OneWayAnova oneWayAnova =
050            new OneWayAnovaImpl();
051    
052        /**
053         * Prevent instantiation.
054         */
055        protected TestUtils() {
056            super();
057        }
058    
059        /**
060         * Set the (singleton) TTest instance.
061         *
062         * @param chiSquareTest the new instance to use
063         * @since 1.2
064         * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
065         */
066        @Deprecated
067        public static void setChiSquareTest(TTest chiSquareTest) {
068            TestUtils.tTest = chiSquareTest;
069        }
070    
071        /**
072         * Return a (singleton) TTest instance.  Does not create a new instance.
073         *
074         * @return a TTest instance
075         * @deprecated 2.2 will be removed in 3.0
076         */
077        @Deprecated
078        public static TTest getTTest() {
079            return tTest;
080        }
081    
082        /**
083         * Set the (singleton) ChiSquareTest instance.
084         *
085         * @param chiSquareTest the new instance to use
086         * @since 1.2
087         * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
088         */
089        @Deprecated
090        public static void setChiSquareTest(ChiSquareTest chiSquareTest) {
091            TestUtils.chiSquareTest = chiSquareTest;
092        }
093    
094        /**
095         * Return a (singleton) ChiSquareTest instance.  Does not create a new instance.
096         *
097         * @return a ChiSquareTest instance
098         * @deprecated 2.2 will be removed in 3.0
099         */
100        @Deprecated
101        public static ChiSquareTest getChiSquareTest() {
102            return chiSquareTest;
103        }
104    
105        /**
106         * Set the (singleton) UnknownDistributionChiSquareTest instance.
107         *
108         * @param unknownDistributionChiSquareTest the new instance to use
109         * @since 1.2
110         * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
111         */
112        @Deprecated
113        public static void setUnknownDistributionChiSquareTest(UnknownDistributionChiSquareTest unknownDistributionChiSquareTest) {
114            TestUtils.unknownDistributionChiSquareTest = unknownDistributionChiSquareTest;
115        }
116    
117        /**
118         * Return a (singleton) UnknownDistributionChiSquareTest instance.  Does not create a new instance.
119         *
120         * @return a UnknownDistributionChiSquareTest instance
121         * @deprecated 2.2 will be removed in 3.0
122         */
123        @Deprecated
124        public static UnknownDistributionChiSquareTest getUnknownDistributionChiSquareTest() {
125            return unknownDistributionChiSquareTest;
126        }
127    
128        /**
129         * Set the (singleton) OneWayAnova instance
130         *
131         * @param oneWayAnova the new instance to use
132         * @since 1.2
133         * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
134         */
135        @Deprecated
136        public static void setOneWayAnova(OneWayAnova oneWayAnova) {
137            TestUtils.oneWayAnova = oneWayAnova;
138        }
139    
140        /**
141         * Return a (singleton) OneWayAnova instance.  Does not create a new instance.
142         *
143         * @return a OneWayAnova instance
144         * @since 1.2
145         * @deprecated 2.2 will be removed in 3.0
146         */
147        @Deprecated
148        public static OneWayAnova getOneWayAnova() {
149            return oneWayAnova;
150        }
151    
152    
153        // CHECKSTYLE: stop JavadocMethodCheck
154    
155        /**
156         * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(double[], double[])
157         */
158        public static double homoscedasticT(double[] sample1, double[] sample2)
159            throws IllegalArgumentException {
160            return tTest.homoscedasticT(sample1, sample2);
161        }
162    
163        /**
164         * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
165         */
166        public static double homoscedasticT(StatisticalSummary sampleStats1,
167            StatisticalSummary sampleStats2)
168            throws IllegalArgumentException {
169            return tTest.homoscedasticT(sampleStats1, sampleStats2);
170        }
171    
172        /**
173         * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[], double)
174         */
175        public static boolean homoscedasticTTest(double[] sample1, double[] sample2,
176                double alpha)
177            throws IllegalArgumentException, MathException {
178            return tTest. homoscedasticTTest(sample1, sample2, alpha);
179        }
180    
181        /**
182         * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[])
183         */
184        public static double homoscedasticTTest(double[] sample1, double[] sample2)
185            throws IllegalArgumentException, MathException {
186            return tTest.homoscedasticTTest(sample1, sample2);
187        }
188    
189        /**
190         * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
191         */
192        public static double homoscedasticTTest(StatisticalSummary sampleStats1,
193            StatisticalSummary sampleStats2)
194            throws IllegalArgumentException, MathException {
195            return tTest.homoscedasticTTest(sampleStats1, sampleStats2);
196        }
197    
198        /**
199         * @see org.apache.commons.math.stat.inference.TTest#pairedT(double[], double[])
200         */
201        public static double pairedT(double[] sample1, double[] sample2)
202            throws IllegalArgumentException, MathException {
203            return tTest.pairedT(sample1, sample2);
204        }
205    
206        /**
207         * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[], double)
208         */
209        public static boolean pairedTTest(double[] sample1, double[] sample2,
210            double alpha)
211            throws IllegalArgumentException, MathException {
212            return tTest.pairedTTest(sample1, sample2, alpha);
213        }
214    
215        /**
216         * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[])
217         */
218        public static double pairedTTest(double[] sample1, double[] sample2)
219            throws IllegalArgumentException, MathException {
220            return tTest.pairedTTest(sample1, sample2);
221        }
222    
223        /**
224         * @see org.apache.commons.math.stat.inference.TTest#t(double, double[])
225         */
226        public static double t(double mu, double[] observed)
227            throws IllegalArgumentException {
228            return tTest.t(mu, observed);
229        }
230    
231        /**
232         * @see org.apache.commons.math.stat.inference.TTest#t(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
233         */
234        public static double t(double mu, StatisticalSummary sampleStats)
235            throws IllegalArgumentException {
236            return tTest.t(mu, sampleStats);
237        }
238    
239        /**
240         * @see org.apache.commons.math.stat.inference.TTest#t(double[], double[])
241         */
242        public static double t(double[] sample1, double[] sample2)
243            throws IllegalArgumentException {
244            return tTest.t(sample1, sample2);
245        }
246    
247        /**
248         * @see org.apache.commons.math.stat.inference.TTest#t(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
249         */
250        public static double t(StatisticalSummary sampleStats1,
251                StatisticalSummary sampleStats2)
252            throws IllegalArgumentException {
253            return tTest.t(sampleStats1, sampleStats2);
254        }
255    
256        /**
257         * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[], double)
258         */
259        public static boolean tTest(double mu, double[] sample, double alpha)
260            throws IllegalArgumentException, MathException {
261            return tTest.tTest(mu, sample, alpha);
262        }
263    
264        /**
265         * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[])
266         */
267        public static double tTest(double mu, double[] sample)
268            throws IllegalArgumentException, MathException {
269            return tTest.tTest(mu, sample);
270        }
271    
272        /**
273         * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
274         */
275        public static boolean tTest(double mu, StatisticalSummary sampleStats,
276            double alpha)
277            throws IllegalArgumentException, MathException {
278            return tTest. tTest(mu, sampleStats, alpha);
279        }
280    
281        /**
282         * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
283         */
284        public static double tTest(double mu, StatisticalSummary sampleStats)
285            throws IllegalArgumentException, MathException {
286            return tTest.tTest(mu, sampleStats);
287        }
288    
289        /**
290         * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[], double)
291         */
292        public static boolean tTest(double[] sample1, double[] sample2, double alpha)
293            throws IllegalArgumentException, MathException {
294            return tTest.tTest(sample1, sample2, alpha);
295        }
296    
297        /**
298         * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[])
299         */
300        public static double tTest(double[] sample1, double[] sample2)
301            throws IllegalArgumentException, MathException {
302            return tTest.tTest(sample1, sample2);
303        }
304    
305        /**
306         * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
307         */
308        public static boolean tTest(StatisticalSummary sampleStats1,
309            StatisticalSummary sampleStats2, double alpha)
310            throws IllegalArgumentException, MathException {
311            return tTest. tTest(sampleStats1, sampleStats2, alpha);
312        }
313    
314        /**
315         * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
316         */
317        public static double tTest(StatisticalSummary sampleStats1,
318            StatisticalSummary sampleStats2)
319            throws IllegalArgumentException, MathException {
320            return tTest.tTest(sampleStats1, sampleStats2);
321        }
322    
323        /**
324         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(double[], long[])
325         */
326        public static double chiSquare(double[] expected, long[] observed)
327            throws IllegalArgumentException {
328            return chiSquareTest.chiSquare(expected, observed);
329        }
330    
331        /**
332         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(long[][])
333         */
334        public static double chiSquare(long[][] counts)
335            throws IllegalArgumentException {
336            return chiSquareTest.chiSquare(counts);
337        }
338    
339        /**
340         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[], double)
341         */
342        public static boolean chiSquareTest(double[] expected, long[] observed,
343            double alpha)
344            throws IllegalArgumentException, MathException {
345            return chiSquareTest.chiSquareTest(expected, observed, alpha);
346        }
347    
348        /**
349         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[])
350         */
351        public static double chiSquareTest(double[] expected, long[] observed)
352            throws IllegalArgumentException, MathException {
353            return chiSquareTest.chiSquareTest(expected, observed);
354        }
355    
356        /**
357         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][], double)
358         */
359        public static boolean chiSquareTest(long[][] counts, double alpha)
360            throws IllegalArgumentException, MathException {
361            return chiSquareTest. chiSquareTest(counts, alpha);
362        }
363    
364        /**
365         * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][])
366         */
367        public static double chiSquareTest(long[][] counts)
368            throws IllegalArgumentException, MathException {
369            return chiSquareTest. chiSquareTest(counts);
370        }
371    
372        /**
373         * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareDataSetsComparison(long[], long[])
374         *
375         * @since 1.2
376         */
377        public static double chiSquareDataSetsComparison(long[] observed1, long[] observed2)
378            throws IllegalArgumentException {
379            return unknownDistributionChiSquareTest.chiSquareDataSetsComparison(observed1, observed2);
380        }
381    
382        /**
383         * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[])
384         *
385         * @since 1.2
386         */
387        public static double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
388            throws IllegalArgumentException, MathException {
389            return unknownDistributionChiSquareTest.chiSquareTestDataSetsComparison(observed1, observed2);
390        }
391    
392    
393        /**
394         * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[], double)
395         *
396         * @since 1.2
397         */
398        public static boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
399            double alpha)
400            throws IllegalArgumentException, MathException {
401            return unknownDistributionChiSquareTest.chiSquareTestDataSetsComparison(observed1, observed2, alpha);
402        }
403    
404        /**
405         * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaFValue(Collection)
406         *
407         * @since 1.2
408         */
409        public static double oneWayAnovaFValue(Collection<double[]> categoryData)
410        throws IllegalArgumentException, MathException {
411            return oneWayAnova.anovaFValue(categoryData);
412        }
413    
414        /**
415         * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaPValue(Collection)
416         *
417         * @since 1.2
418         */
419        public static double oneWayAnovaPValue(Collection<double[]> categoryData)
420        throws IllegalArgumentException, MathException {
421            return oneWayAnova.anovaPValue(categoryData);
422        }
423    
424        /**
425         * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaTest(Collection,double)
426         *
427         * @since 1.2
428         */
429        public static boolean oneWayAnovaTest(Collection<double[]> categoryData, double alpha)
430        throws IllegalArgumentException, MathException {
431            return oneWayAnova.anovaTest(categoryData, alpha);
432        }
433    
434        // CHECKSTYLE: resume JavadocMethodCheck
435    
436    }