blob: 5023d558db4a197f8c8cfff7229ce111966585e7 [file] [log] [blame]
Raymonddee08492015-04-02 10:43:13 -07001/*
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 */
17package org.apache.commons.math.stat.inference;
18
19import java.util.Collection;
20import org.apache.commons.math.MathException;
21import 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 * <p>
28 * The set methods are not compatible with using the class in multiple threads,
29 * and have therefore been deprecated (along with the getters).
30 * The setters and getters will be removed in version 3.0.
31 *
32 * @since 1.1
33 * @version $Revision: 1067582 $ $Date: 2011-02-06 04:55:32 +0100 (dim. 06 févr. 2011) $
34 */
35public class TestUtils {
36
37 /** Singleton TTest instance using default implementation. */
38 private static TTest tTest = new TTestImpl();
39
40 /** Singleton ChiSquareTest instance using default implementation. */
41 private static ChiSquareTest chiSquareTest =
42 new ChiSquareTestImpl();
43
44 /** Singleton ChiSquareTest instance using default implementation. */
45 private static UnknownDistributionChiSquareTest unknownDistributionChiSquareTest =
46 new ChiSquareTestImpl();
47
48 /** Singleton OneWayAnova instance using default implementation. */
49 private static OneWayAnova oneWayAnova =
50 new OneWayAnovaImpl();
51
52 /**
53 * Prevent instantiation.
54 */
55 protected TestUtils() {
56 super();
57 }
58
59 /**
60 * Set the (singleton) TTest instance.
61 *
62 * @param chiSquareTest the new instance to use
63 * @since 1.2
64 * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
65 */
66 @Deprecated
67 public static void setChiSquareTest(TTest chiSquareTest) {
68 TestUtils.tTest = chiSquareTest;
69 }
70
71 /**
72 * Return a (singleton) TTest instance. Does not create a new instance.
73 *
74 * @return a TTest instance
75 * @deprecated 2.2 will be removed in 3.0
76 */
77 @Deprecated
78 public static TTest getTTest() {
79 return tTest;
80 }
81
82 /**
83 * Set the (singleton) ChiSquareTest instance.
84 *
85 * @param chiSquareTest the new instance to use
86 * @since 1.2
87 * @deprecated 2.2 will be removed in 3.0 - not compatible with use from multiple threads
88 */
89 @Deprecated
90 public static void setChiSquareTest(ChiSquareTest chiSquareTest) {
91 TestUtils.chiSquareTest = chiSquareTest;
92 }
93
94 /**
95 * Return a (singleton) ChiSquareTest instance. Does not create a new instance.
96 *
97 * @return a ChiSquareTest instance
98 * @deprecated 2.2 will be removed in 3.0
99 */
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}