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 * @since 1.1
028 * @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
029 */
030 public class TestUtils {
031 /**
032 * Prevent instantiation.
033 */
034 protected TestUtils() {
035 super();
036 }
037
038 /** Singleton TTest instance using default implementation. */
039 private static TTest tTest = new TTestImpl();
040
041 /** Singleton ChiSquareTest instance using default implementation. */
042 private static ChiSquareTest chiSquareTest =
043 new ChiSquareTestImpl();
044
045 /** Singleton ChiSquareTest instance using default implementation. */
046 private static UnknownDistributionChiSquareTest unknownDistributionChiSquareTest =
047 new ChiSquareTestImpl();
048
049 /** Singleton OneWayAnova instance using default implementation. */
050 private static OneWayAnova oneWayAnova =
051 new OneWayAnovaImpl();
052
053 /**
054 * Set the (singleton) TTest instance.
055 *
056 * @param tTest the new instance to use
057 * @since 1.2
058 */
059 public static void setChiSquareTest(TTest tTest) {
060 TestUtils.tTest = tTest;
061 }
062
063 /**
064 * Return a (singleton) TTest instance. Does not create a new instance.
065 *
066 * @return a TTest instance
067 */
068 public static TTest getTTest() {
069 return tTest;
070 }
071
072 /**
073 * Set the (singleton) ChiSquareTest instance.
074 *
075 * @param chiSquareTest the new instance to use
076 * @since 1.2
077 */
078 public static void setChiSquareTest(ChiSquareTest chiSquareTest) {
079 TestUtils.chiSquareTest = chiSquareTest;
080 }
081
082 /**
083 * Return a (singleton) ChiSquareTest instance. Does not create a new instance.
084 *
085 * @return a ChiSquareTest instance
086 */
087 public static ChiSquareTest getChiSquareTest() {
088 return chiSquareTest;
089 }
090
091 /**
092 * Set the (singleton) UnknownDistributionChiSquareTest instance.
093 *
094 * @param unknownDistributionChiSquareTest the new instance to use
095 * @since 1.2
096 */
097 public static void setUnknownDistributionChiSquareTest(UnknownDistributionChiSquareTest unknownDistributionChiSquareTest) {
098 TestUtils.unknownDistributionChiSquareTest = unknownDistributionChiSquareTest;
099 }
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 }