View Javadoc

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.math.stat.inference;
18  
19  import java.util.Collection;
20  import org.apache.commons.math.MathException;
21  import org.apache.commons.math.stat.descriptive.StatisticalSummary;
22  
23  /**
24   * A collection of static methods to create inference test instances or to
25   * perform inference tests.
26   *
27   * @since 1.1
28   * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $ 
29   */
30  public class TestUtils  {
31      /**
32       * Prevent instantiation.
33       */
34      protected TestUtils() {
35          super();
36      }
37      
38      /** Singleton TTest instance using default implementation. */
39      private static TTest tTest = new TTestImpl();
40     
41      /** Singleton ChiSquareTest instance using default implementation. */
42      private static ChiSquareTest chiSquareTest = 
43          new ChiSquareTestImpl();
44      
45      /** Singleton ChiSquareTest instance using default implementation. */
46      private static UnknownDistributionChiSquareTest unknownDistributionChiSquareTest = 
47          new ChiSquareTestImpl();
48      
49      /** Singleton OneWayAnova instance using default implementation. */
50      private static OneWayAnova oneWayAnova =
51          new OneWayAnovaImpl();
52      
53      /**
54       * Set the (singleton) TTest instance.
55       * 
56       * @param tTest the new instance to use
57       * @since 1.2
58       */
59      public static void setChiSquareTest(TTest tTest) {
60          TestUtils.tTest = tTest;
61      }
62      
63      /**
64       * Return a (singleton) TTest instance.  Does not create a new instance.
65       * 
66       * @return a TTest instance
67       */
68      public static TTest getTTest() {
69          return tTest;
70      }
71      
72      /**
73       * Set the (singleton) ChiSquareTest instance.
74       * 
75       * @param chiSquareTest the new instance to use
76       * @since 1.2
77       */
78      public static void setChiSquareTest(ChiSquareTest chiSquareTest) {
79          TestUtils.chiSquareTest = chiSquareTest;
80      }
81      
82      /**
83       * Return a (singleton) ChiSquareTest instance.  Does not create a new instance.
84       * 
85       * @return a ChiSquareTest instance
86       */
87      public static ChiSquareTest getChiSquareTest() {
88          return chiSquareTest;
89      }
90      
91      /**
92       * Set the (singleton) UnknownDistributionChiSquareTest instance.
93       * 
94       * @param unknownDistributionChiSquareTest the new instance to use
95       * @since 1.2
96       */
97      public static void setUnknownDistributionChiSquareTest(UnknownDistributionChiSquareTest unknownDistributionChiSquareTest) {
98          TestUtils.unknownDistributionChiSquareTest = unknownDistributionChiSquareTest;
99      }
100     
101     /**
102      * Return a (singleton) UnknownDistributionChiSquareTest instance.  Does not create a new instance.
103      * 
104      * @return a UnknownDistributionChiSquareTest instance
105      */
106     public static UnknownDistributionChiSquareTest getUnknownDistributionChiSquareTest() {
107         return unknownDistributionChiSquareTest;
108     }
109     
110     /**
111      * Set the (singleton) OneWayAnova instance
112      * 
113      * @param oneWayAnova the new instance to use
114      * @since 1.2
115      */
116     public static void setOneWayAnova(OneWayAnova oneWayAnova) {
117         TestUtils.oneWayAnova = oneWayAnova;
118     }
119     
120     /**
121      * Return a (singleton) OneWayAnova instance.  Does not create a new instance.
122      * 
123      * @return a OneWayAnova instance
124      * @since 1.2
125      */
126     public static OneWayAnova getOneWayAnova() {
127         return oneWayAnova;
128     }
129     
130     
131     // CHECKSTYLE: stop JavadocMethodCheck
132 
133     /**
134      * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(double[], double[])
135      */
136     public static double homoscedasticT(double[] sample1, double[] sample2)
137         throws IllegalArgumentException {
138         return tTest.homoscedasticT(sample1, sample2);
139     }
140 
141     /**
142      * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
143      */
144     public static double homoscedasticT(StatisticalSummary sampleStats1,
145         StatisticalSummary sampleStats2)
146         throws IllegalArgumentException {
147         return tTest.homoscedasticT(sampleStats1, sampleStats2);
148     }
149 
150     /**
151      * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[], double)
152      */
153     public static boolean homoscedasticTTest(double[] sample1, double[] sample2,
154             double alpha)
155         throws IllegalArgumentException, MathException {
156         return tTest. homoscedasticTTest(sample1, sample2, alpha);
157     }
158 
159     /**
160      * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[])
161      */
162     public static double homoscedasticTTest(double[] sample1, double[] sample2)
163         throws IllegalArgumentException, MathException {
164         return tTest.homoscedasticTTest(sample1, sample2);
165     }
166 
167     /**
168      * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
169      */
170     public static double homoscedasticTTest(StatisticalSummary sampleStats1,
171         StatisticalSummary sampleStats2)
172         throws IllegalArgumentException, MathException {
173         return tTest.homoscedasticTTest(sampleStats1, sampleStats2);
174     }
175 
176     /**
177      * @see org.apache.commons.math.stat.inference.TTest#pairedT(double[], double[])
178      */
179     public static double pairedT(double[] sample1, double[] sample2)
180         throws IllegalArgumentException, MathException {
181         return tTest.pairedT(sample1, sample2);
182     }
183 
184     /**
185      * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[], double)
186      */
187     public static boolean pairedTTest(double[] sample1, double[] sample2,
188         double alpha)
189         throws IllegalArgumentException, MathException {
190         return tTest.pairedTTest(sample1, sample2, alpha);
191     }
192 
193     /**
194      * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[])
195      */
196     public static double pairedTTest(double[] sample1, double[] sample2)
197         throws IllegalArgumentException, MathException {
198         return tTest.pairedTTest(sample1, sample2);
199     }
200 
201     /**
202      * @see org.apache.commons.math.stat.inference.TTest#t(double, double[])
203      */
204     public static double t(double mu, double[] observed)
205         throws IllegalArgumentException {
206         return tTest.t(mu, observed);
207     }
208 
209     /**
210      * @see org.apache.commons.math.stat.inference.TTest#t(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
211      */
212     public static double t(double mu, StatisticalSummary sampleStats)
213         throws IllegalArgumentException {
214         return tTest.t(mu, sampleStats);
215     }
216 
217     /**
218      * @see org.apache.commons.math.stat.inference.TTest#t(double[], double[])
219      */
220     public static double t(double[] sample1, double[] sample2)
221         throws IllegalArgumentException {
222         return tTest.t(sample1, sample2);
223     }
224 
225     /**
226      * @see org.apache.commons.math.stat.inference.TTest#t(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
227      */
228     public static double t(StatisticalSummary sampleStats1,
229             StatisticalSummary sampleStats2)
230         throws IllegalArgumentException {
231         return tTest.t(sampleStats1, sampleStats2);
232     }
233 
234     /**
235      * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[], double)
236      */
237     public static boolean tTest(double mu, double[] sample, double alpha)
238         throws IllegalArgumentException, MathException {
239         return tTest.tTest(mu, sample, alpha);
240     }
241 
242     /**
243      * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[])
244      */
245     public static double tTest(double mu, double[] sample)
246         throws IllegalArgumentException, MathException {
247         return tTest.tTest(mu, sample);
248     }
249 
250     /**
251      * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
252      */
253     public static boolean tTest(double mu, StatisticalSummary sampleStats,
254         double alpha)
255         throws IllegalArgumentException, MathException {
256         return tTest. tTest(mu, sampleStats, alpha);
257     }
258 
259     /**
260      * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
261      */
262     public static double tTest(double mu, StatisticalSummary sampleStats)
263         throws IllegalArgumentException, MathException {
264         return tTest.tTest(mu, sampleStats);
265     }
266 
267     /**
268      * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[], double)
269      */
270     public static boolean tTest(double[] sample1, double[] sample2, double alpha)
271         throws IllegalArgumentException, MathException {
272         return tTest.tTest(sample1, sample2, alpha);
273     }
274 
275     /**
276      * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[])
277      */
278     public static double tTest(double[] sample1, double[] sample2)
279         throws IllegalArgumentException, MathException {
280         return tTest.tTest(sample1, sample2);
281     }
282 
283     /**
284      * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
285      */
286     public static boolean tTest(StatisticalSummary sampleStats1,
287         StatisticalSummary sampleStats2, double alpha)
288         throws IllegalArgumentException, MathException {
289         return tTest. tTest(sampleStats1, sampleStats2, alpha);
290     }
291 
292     /**
293      * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
294      */
295     public static double tTest(StatisticalSummary sampleStats1,
296         StatisticalSummary sampleStats2)
297         throws IllegalArgumentException, MathException {
298         return tTest.tTest(sampleStats1, sampleStats2);
299     }
300 
301     /**
302      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(double[], long[])
303      */
304     public static double chiSquare(double[] expected, long[] observed)
305         throws IllegalArgumentException {
306         return chiSquareTest.chiSquare(expected, observed);
307     }
308 
309     /**
310      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(long[][])
311      */
312     public static double chiSquare(long[][] counts) 
313         throws IllegalArgumentException {
314         return chiSquareTest.chiSquare(counts);
315     }
316 
317     /**
318      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[], double)
319      */
320     public static boolean chiSquareTest(double[] expected, long[] observed,
321         double alpha)
322         throws IllegalArgumentException, MathException {
323         return chiSquareTest.chiSquareTest(expected, observed, alpha);
324     }
325 
326     /**
327      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[])
328      */
329     public static double chiSquareTest(double[] expected, long[] observed)
330         throws IllegalArgumentException, MathException {
331         return chiSquareTest.chiSquareTest(expected, observed);
332     }
333 
334     /**
335      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][], double)
336      */
337     public static boolean chiSquareTest(long[][] counts, double alpha)
338         throws IllegalArgumentException, MathException {
339         return chiSquareTest. chiSquareTest(counts, alpha);
340     }
341 
342     /**
343      * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][])
344      */
345     public static double chiSquareTest(long[][] counts)
346         throws IllegalArgumentException, MathException {
347         return chiSquareTest. chiSquareTest(counts);
348     }
349 
350     /**
351      * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareDataSetsComparison(long[], long[])
352      *
353      * @since 1.2
354      */
355     public static double chiSquareDataSetsComparison(long[] observed1, long[] observed2)
356         throws IllegalArgumentException {
357         return unknownDistributionChiSquareTest.chiSquareDataSetsComparison(observed1, observed2);
358     }
359 
360     /**
361      * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[])
362      *
363      * @since 1.2
364      */
365     public static double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
366         throws IllegalArgumentException, MathException {
367         return unknownDistributionChiSquareTest.chiSquareTestDataSetsComparison(observed1, observed2);
368     }
369 
370 
371     /**
372      * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[], double)
373      *
374      * @since 1.2
375      */
376     public static boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
377         double alpha)
378         throws IllegalArgumentException, MathException {
379         return unknownDistributionChiSquareTest.chiSquareTestDataSetsComparison(observed1, observed2, alpha);
380     }
381     
382     /**
383      * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaFValue(Collection)
384      *
385      * @since 1.2
386      */
387     public static double oneWayAnovaFValue(Collection<double[]> categoryData)
388     throws IllegalArgumentException, MathException {
389         return oneWayAnova.anovaFValue(categoryData);
390     }
391     
392     /**
393      * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaPValue(Collection)
394      * 
395      * @since 1.2
396      */
397     public static double oneWayAnovaPValue(Collection<double[]> categoryData)
398     throws IllegalArgumentException, MathException {
399         return oneWayAnova.anovaPValue(categoryData);
400     }
401     
402     /**
403      * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaTest(Collection,double)
404      *
405      * @since 1.2
406      */
407     public static boolean oneWayAnovaTest(Collection<double[]> categoryData, double alpha)
408     throws IllegalArgumentException, MathException {
409         return oneWayAnova.anovaTest(categoryData, alpha);
410     }
411 
412     // CHECKSTYLE: resume JavadocMethodCheck
413 
414 }