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 $Id: TestUtils.java 1131229 2011-06-03 20:49:25Z luc $
029 */
030 public class TestUtils {
031
032 /** Singleton TTest instance using default implementation. */
033 private static final TTest T_TEST = new TTestImpl();
034
035 /** Singleton ChiSquareTest instance using default implementation. */
036 private static final ChiSquareTest CHI_SQUARE_TEST = new ChiSquareTestImpl();
037
038 /** Singleton ChiSquareTest instance using default implementation. */
039 private static final UnknownDistributionChiSquareTest UNKNOWN_DISTRIBUTION_CHI_SQUARE_TEST =
040 new ChiSquareTestImpl();
041
042 /** Singleton OneWayAnova instance using default implementation. */
043 private static final OneWayAnova ONE_WAY_ANANOVA = new OneWayAnovaImpl();
044
045 /**
046 * Prevent instantiation.
047 */
048 private TestUtils() {
049 super();
050 }
051
052 // CHECKSTYLE: stop JavadocMethodCheck
053
054 /**
055 * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(double[], double[])
056 */
057 public static double homoscedasticT(double[] sample1, double[] sample2)
058 throws IllegalArgumentException {
059 return T_TEST.homoscedasticT(sample1, sample2);
060 }
061
062 /**
063 * @see org.apache.commons.math.stat.inference.TTest#homoscedasticT(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
064 */
065 public static double homoscedasticT(StatisticalSummary sampleStats1,
066 StatisticalSummary sampleStats2)
067 throws IllegalArgumentException {
068 return T_TEST.homoscedasticT(sampleStats1, sampleStats2);
069 }
070
071 /**
072 * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[], double)
073 */
074 public static boolean homoscedasticTTest(double[] sample1, double[] sample2,
075 double alpha)
076 throws IllegalArgumentException, MathException {
077 return T_TEST. homoscedasticTTest(sample1, sample2, alpha);
078 }
079
080 /**
081 * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(double[], double[])
082 */
083 public static double homoscedasticTTest(double[] sample1, double[] sample2)
084 throws IllegalArgumentException, MathException {
085 return T_TEST.homoscedasticTTest(sample1, sample2);
086 }
087
088 /**
089 * @see org.apache.commons.math.stat.inference.TTest#homoscedasticTTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
090 */
091 public static double homoscedasticTTest(StatisticalSummary sampleStats1,
092 StatisticalSummary sampleStats2)
093 throws IllegalArgumentException, MathException {
094 return T_TEST.homoscedasticTTest(sampleStats1, sampleStats2);
095 }
096
097 /**
098 * @see org.apache.commons.math.stat.inference.TTest#pairedT(double[], double[])
099 */
100 public static double pairedT(double[] sample1, double[] sample2)
101 throws IllegalArgumentException, MathException {
102 return T_TEST.pairedT(sample1, sample2);
103 }
104
105 /**
106 * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[], double)
107 */
108 public static boolean pairedTTest(double[] sample1, double[] sample2,
109 double alpha)
110 throws IllegalArgumentException, MathException {
111 return T_TEST.pairedTTest(sample1, sample2, alpha);
112 }
113
114 /**
115 * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[])
116 */
117 public static double pairedTTest(double[] sample1, double[] sample2)
118 throws IllegalArgumentException, MathException {
119 return T_TEST.pairedTTest(sample1, sample2);
120 }
121
122 /**
123 * @see org.apache.commons.math.stat.inference.TTest#t(double, double[])
124 */
125 public static double t(double mu, double[] observed)
126 throws IllegalArgumentException {
127 return T_TEST.t(mu, observed);
128 }
129
130 /**
131 * @see org.apache.commons.math.stat.inference.TTest#t(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
132 */
133 public static double t(double mu, StatisticalSummary sampleStats)
134 throws IllegalArgumentException {
135 return T_TEST.t(mu, sampleStats);
136 }
137
138 /**
139 * @see org.apache.commons.math.stat.inference.TTest#t(double[], double[])
140 */
141 public static double t(double[] sample1, double[] sample2)
142 throws IllegalArgumentException {
143 return T_TEST.t(sample1, sample2);
144 }
145
146 /**
147 * @see org.apache.commons.math.stat.inference.TTest#t(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
148 */
149 public static double t(StatisticalSummary sampleStats1,
150 StatisticalSummary sampleStats2)
151 throws IllegalArgumentException {
152 return T_TEST.t(sampleStats1, sampleStats2);
153 }
154
155 /**
156 * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[], double)
157 */
158 public static boolean tTest(double mu, double[] sample, double alpha)
159 throws IllegalArgumentException, MathException {
160 return T_TEST.tTest(mu, sample, alpha);
161 }
162
163 /**
164 * @see org.apache.commons.math.stat.inference.TTest#tTest(double, double[])
165 */
166 public static double tTest(double mu, double[] sample)
167 throws IllegalArgumentException, MathException {
168 return T_TEST.tTest(mu, sample);
169 }
170
171 /**
172 * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
173 */
174 public static boolean tTest(double mu, StatisticalSummary sampleStats,
175 double alpha)
176 throws IllegalArgumentException, MathException {
177 return T_TEST. tTest(mu, sampleStats, alpha);
178 }
179
180 /**
181 * @see org.apache.commons.math.stat.inference.TTest#tTest(double, org.apache.commons.math.stat.descriptive.StatisticalSummary)
182 */
183 public static double tTest(double mu, StatisticalSummary sampleStats)
184 throws IllegalArgumentException, MathException {
185 return T_TEST.tTest(mu, sampleStats);
186 }
187
188 /**
189 * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[], double)
190 */
191 public static boolean tTest(double[] sample1, double[] sample2, double alpha)
192 throws IllegalArgumentException, MathException {
193 return T_TEST.tTest(sample1, sample2, alpha);
194 }
195
196 /**
197 * @see org.apache.commons.math.stat.inference.TTest#tTest(double[], double[])
198 */
199 public static double tTest(double[] sample1, double[] sample2)
200 throws IllegalArgumentException, MathException {
201 return T_TEST.tTest(sample1, sample2);
202 }
203
204 /**
205 * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary, double)
206 */
207 public static boolean tTest(StatisticalSummary sampleStats1,
208 StatisticalSummary sampleStats2, double alpha)
209 throws IllegalArgumentException, MathException {
210 return T_TEST. tTest(sampleStats1, sampleStats2, alpha);
211 }
212
213 /**
214 * @see org.apache.commons.math.stat.inference.TTest#tTest(org.apache.commons.math.stat.descriptive.StatisticalSummary, org.apache.commons.math.stat.descriptive.StatisticalSummary)
215 */
216 public static double tTest(StatisticalSummary sampleStats1,
217 StatisticalSummary sampleStats2)
218 throws IllegalArgumentException, MathException {
219 return T_TEST.tTest(sampleStats1, sampleStats2);
220 }
221
222 /**
223 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(double[], long[])
224 */
225 public static double chiSquare(double[] expected, long[] observed)
226 throws IllegalArgumentException {
227 return CHI_SQUARE_TEST.chiSquare(expected, observed);
228 }
229
230 /**
231 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquare(long[][])
232 */
233 public static double chiSquare(long[][] counts)
234 throws IllegalArgumentException {
235 return CHI_SQUARE_TEST.chiSquare(counts);
236 }
237
238 /**
239 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[], double)
240 */
241 public static boolean chiSquareTest(double[] expected, long[] observed,
242 double alpha)
243 throws IllegalArgumentException, MathException {
244 return CHI_SQUARE_TEST.chiSquareTest(expected, observed, alpha);
245 }
246
247 /**
248 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(double[], long[])
249 */
250 public static double chiSquareTest(double[] expected, long[] observed)
251 throws IllegalArgumentException, MathException {
252 return CHI_SQUARE_TEST.chiSquareTest(expected, observed);
253 }
254
255 /**
256 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][], double)
257 */
258 public static boolean chiSquareTest(long[][] counts, double alpha)
259 throws IllegalArgumentException, MathException {
260 return CHI_SQUARE_TEST. chiSquareTest(counts, alpha);
261 }
262
263 /**
264 * @see org.apache.commons.math.stat.inference.ChiSquareTest#chiSquareTest(long[][])
265 */
266 public static double chiSquareTest(long[][] counts)
267 throws IllegalArgumentException, MathException {
268 return CHI_SQUARE_TEST.chiSquareTest(counts);
269 }
270
271 /**
272 * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareDataSetsComparison(long[], long[])
273 *
274 * @since 1.2
275 */
276 public static double chiSquareDataSetsComparison(long[] observed1, long[] observed2)
277 throws IllegalArgumentException {
278 return UNKNOWN_DISTRIBUTION_CHI_SQUARE_TEST.chiSquareDataSetsComparison(observed1, observed2);
279 }
280
281 /**
282 * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[])
283 *
284 * @since 1.2
285 */
286 public static double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
287 throws IllegalArgumentException, MathException {
288 return UNKNOWN_DISTRIBUTION_CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2);
289 }
290
291
292 /**
293 * @see org.apache.commons.math.stat.inference.UnknownDistributionChiSquareTest#chiSquareTestDataSetsComparison(long[], long[], double)
294 *
295 * @since 1.2
296 */
297 public static boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2,
298 double alpha)
299 throws IllegalArgumentException, MathException {
300 return UNKNOWN_DISTRIBUTION_CHI_SQUARE_TEST.chiSquareTestDataSetsComparison(observed1, observed2, alpha);
301 }
302
303 /**
304 * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaFValue(Collection)
305 *
306 * @since 1.2
307 */
308 public static double oneWayAnovaFValue(Collection<double[]> categoryData)
309 throws IllegalArgumentException, MathException {
310 return ONE_WAY_ANANOVA.anovaFValue(categoryData);
311 }
312
313 /**
314 * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaPValue(Collection)
315 *
316 * @since 1.2
317 */
318 public static double oneWayAnovaPValue(Collection<double[]> categoryData)
319 throws IllegalArgumentException, MathException {
320 return ONE_WAY_ANANOVA.anovaPValue(categoryData);
321 }
322
323 /**
324 * @see org.apache.commons.math.stat.inference.OneWayAnova#anovaTest(Collection,double)
325 *
326 * @since 1.2
327 */
328 public static boolean oneWayAnovaTest(Collection<double[]> categoryData, double alpha)
329 throws IllegalArgumentException, MathException {
330 return ONE_WAY_ANANOVA.anovaTest(categoryData, alpha);
331 }
332
333 // CHECKSTYLE: resume JavadocMethodCheck
334
335 }