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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
package org.apache.commons.math.stat.inference;
19
import org.apache.commons.math.MathException;
22
* An interface for Chi-Square tests for unknown distributions.
23
* <p>Two samples tests are used when the distribution is unknown <i>a priori</i>
24
* but provided by one sample. We compare the second sample against the first.</p>
26
* @version $Revision: 670469 $ $Date: 2008-06-23 04:01:38 -0400 (Mon, 23 Jun 2008) $
29
public interface UnknownDistributionChiSquareTest extends ChiSquareTest {
33
* <a href="http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/chi2samp.htm">
34
* Chi-Square two sample test statistic</a> comparing bin frequency counts
35
* in <code>observed1</code> and <code>observed2</code>. The
36
* sums of frequency counts in the two samples are not required to be the
37
* same. The formula used to compute the test statistic is</p>
39
* ∑[(K * observed1[i] - observed2[i]/K)<sup>2</sup> / (observed1[i] + observed2[i])]
41
* <br/><code>K = &sqrt;[&sum(observed2 / ∑(observed1)]</code>
43
* <p>This statistic can be used to perform a Chi-Square test evaluating the null hypothesis that
44
* both observed counts follow the same distribution.</p>
46
* <strong>Preconditions</strong>: <ul>
47
* <li>Observed counts must be non-negative.
49
* <li>Observed counts for a specific bin must not both be zero.
51
* <li>Observed counts for a specific sample must not all be 0.
53
* <li>The arrays <code>observed1</code> and <code>observed2</code> must have the same length and
54
* their common length must be at least 2.
56
* If any of the preconditions are not met, an
57
* <code>IllegalArgumentException</code> is thrown.</p>
59
* @param observed1 array of observed frequency counts of the first data set
60
* @param observed2 array of observed frequency counts of the second data set
61
* @return chiSquare statistic
62
* @throws IllegalArgumentException if preconditions are not met
64
double chiSquareDataSetsComparison(long[] observed1, long[] observed2)
65
throws IllegalArgumentException;
68
* <p>Returns the <i>observed significance level</i>, or <a href=
69
* "http://www.cas.lancs.ac.uk/glossary_v1.1/hyptest.html#pvalue">
70
* p-value</a>, associated with a Chi-Square two sample test comparing
71
* bin frequency counts in <code>observed1</code> and
72
* <code>observed2</code>.
74
* <p>The number returned is the smallest significance level at which one
75
* can reject the null hypothesis that the observed counts conform to the
78
* <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for details
79
* on the formula used to compute the test statistic. The degrees of
80
* of freedom used to perform the test is one less than the common length
81
* of the input observed count arrays.
83
* <strong>Preconditions</strong>: <ul>
84
* <li>Observed counts must be non-negative.
86
* <li>Observed counts for a specific bin must not both be zero.
88
* <li>Observed counts for a specific sample must not all be 0.
90
* <li>The arrays <code>observed1</code> and <code>observed2</code> must
91
* have the same length and
92
* their common length must be at least 2.
94
* If any of the preconditions are not met, an
95
* <code>IllegalArgumentException</code> is thrown.</p>
97
* @param observed1 array of observed frequency counts of the first data set
98
* @param observed2 array of observed frequency counts of the second data set
100
* @throws IllegalArgumentException if preconditions are not met
101
* @throws MathException if an error occurs computing the p-value
103
double chiSquareTestDataSetsComparison(long[] observed1, long[] observed2)
104
throws IllegalArgumentException, MathException;
107
* <p>Performs a Chi-Square two sample test comparing two binned data
108
* sets. The test evaluates the null hypothesis that the two lists of
109
* observed counts conform to the same frequency distribution, with
110
* significance level <code>alpha</code>. Returns true iff the null
111
* hypothesis can be rejected with 100 * (1 - alpha) percent confidence.
113
* <p>See {@link #chiSquareDataSetsComparison(long[], long[])} for
114
* details on the formula used to compute the Chisquare statistic used
115
* in the test. The degrees of of freedom used to perform the test is
116
* one less than the common length of the input observed count arrays.
118
* <strong>Preconditions</strong>: <ul>
119
* <li>Observed counts must be non-negative.
121
* <li>Observed counts for a specific bin must not both be zero.
123
* <li>Observed counts for a specific sample must not all be 0.
125
* <li>The arrays <code>observed1</code> and <code>observed2</code> must
126
* have the same length and their common length must be at least 2.
128
* <li> <code> 0 < alpha < 0.5 </code>
130
* If any of the preconditions are not met, an
131
* <code>IllegalArgumentException</code> is thrown.</p>
133
* @param observed1 array of observed frequency counts of the first data set
134
* @param observed2 array of observed frequency counts of the second data set
135
* @param alpha significance level of the test
136
* @return true iff null hypothesis can be rejected with confidence
138
* @throws IllegalArgumentException if preconditions are not met
139
* @throws MathException if an error occurs performing the test
141
boolean chiSquareTestDataSetsComparison(long[] observed1, long[] observed2, double alpha)
142
throws IllegalArgumentException, MathException;