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 junit.framework.Test;
20
import junit.framework.TestCase;
21
import junit.framework.TestSuite;
23
import java.util.ArrayList;
24
import java.util.List;
27
* Test cases for the OneWayAnovaImpl class.
29
* @version $Revision$ $Date$
32
public class OneWayAnovaTest extends TestCase {
34
protected OneWayAnova testStatistic = new OneWayAnovaImpl();
36
private char[] wrongArray = { 'a', 'b', 'c' };
37
private double[] emptyArray = {};
39
private double[] classA =
40
{93.0, 103.0, 95.0, 101.0, 91.0, 105.0, 96.0, 94.0, 101.0 };
41
private double[] classB =
42
{99.0, 92.0, 102.0, 100.0, 102.0, 89.0 };
43
private double[] classC =
44
{110.0, 115.0, 111.0, 117.0, 128.0, 117.0 };
46
public OneWayAnovaTest(String name) {
53
public static Test suite() {
54
TestSuite suite = new TestSuite(OneWayAnovaTest.class);
55
suite.setName("TestStatistic Tests");
59
public void testAnovaFValue() throws Exception {
60
// Target comparison values computed using R version 2.6.0 (Linux version)
61
List threeClasses = new ArrayList();
62
threeClasses.add(classA);
63
threeClasses.add(classB);
64
threeClasses.add(classC);
66
assertEquals("ANOVA F-value", 24.67361709460624,
67
testStatistic.anovaFValue(threeClasses), 1E-12);
69
List twoClasses = new ArrayList();
70
twoClasses.add(classA);
71
twoClasses.add(classB);
73
assertEquals("ANOVA F-value", 0.0150579150579,
74
testStatistic.anovaFValue(twoClasses), 1E-12);
76
// now try some input hashes which should fail
77
List wrongContents = new ArrayList();
78
wrongContents.add(classC);
79
wrongContents.add(wrongArray);
81
testStatistic.anovaFValue(wrongContents);
82
fail("non double[] hash value for key classX, IllegalArgumentException expected");
83
} catch (IllegalArgumentException ex) {
87
List emptyContents = new ArrayList();
88
emptyContents.add(emptyArray);
89
emptyContents.add(classC);
91
testStatistic.anovaFValue(emptyContents);
92
fail("empty array for key classX, IllegalArgumentException expected");
93
} catch (IllegalArgumentException ex) {
97
List tooFew = new ArrayList();
100
testStatistic.anovaFValue(tooFew);
101
fail("less than two classes, IllegalArgumentException expected");
102
} catch (IllegalArgumentException ex) {
108
public void testAnovaPValue() throws Exception {
109
// Target comparison values computed using R version 2.6.0 (Linux version)
110
List threeClasses = new ArrayList();
111
threeClasses.add(classA);
112
threeClasses.add(classB);
113
threeClasses.add(classC);
115
assertEquals("ANOVA P-value", 6.959446E-06,
116
testStatistic.anovaPValue(threeClasses), 1E-12);
118
List twoClasses = new ArrayList();
119
twoClasses.add(classA);
120
twoClasses.add(classB);
122
assertEquals("ANOVA P-value", 0.904212960464,
123
testStatistic.anovaPValue(twoClasses), 1E-12);
127
public void testAnovaTest() throws Exception {
128
// Target comparison values computed using R version 2.3.1 (Linux version)
129
List threeClasses = new ArrayList();
130
threeClasses.add(classA);
131
threeClasses.add(classB);
132
threeClasses.add(classC);
134
assertTrue("ANOVA Test P<0.01", testStatistic.anovaTest(threeClasses, 0.01));
136
List twoClasses = new ArrayList();
137
twoClasses.add(classA);
138
twoClasses.add(classB);
140
assertFalse("ANOVA Test P>0.01", testStatistic.anovaTest(twoClasses, 0.01));
b'\\ No newline at end of file'