OneWayAnova { public double anovaPValue(final Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException { final AnovaStats a = anovaStats(categoryData); final FDistribution fdist = new FDistribution(null, a.dfbg, a.dfwg); return 1.0 - fdist.cumulativeProbability(a.F); } OneWayAnova(); double anovaFValue(final Collection<double[]> categoryData); double anovaPValue(final Collection<double[]> categoryData); double anovaPValue(final Collection<SummaryStatistics> categoryData,
                              final boolean allowOneElementData); boolean anovaTest(final Collection<double[]> categoryData,
                             final double alpha);  }
@Test public void testAnovaPValue() { List<double[]> threeClasses = new ArrayList<double[]>(); threeClasses.add(classA); threeClasses.add(classB); threeClasses.add(classC); Assert.assertEquals("ANOVA P-value", 6.959446E-06, testStatistic.anovaPValue(threeClasses), 1E-12); List<double[]> twoClasses = new ArrayList<double[]>(); twoClasses.add(classA); twoClasses.add(classB); Assert.assertEquals("ANOVA P-value", 0.904212960464, testStatistic.anovaPValue(twoClasses), 1E-12); }
@Test public void testAnovaPValueSummaryStatistics() { List<SummaryStatistics> threeClasses = new ArrayList<SummaryStatistics>(); SummaryStatistics statsA = new SummaryStatistics(); for (double a : classA) { statsA.addValue(a); } threeClasses.add(statsA); SummaryStatistics statsB = new SummaryStatistics(); for (double b : classB) { statsB.addValue(b); } threeClasses.add(statsB); SummaryStatistics statsC = new SummaryStatistics(); for (double c : classC) { statsC.addValue(c); } threeClasses.add(statsC); Assert.assertEquals("ANOVA P-value", 6.959446E-06, testStatistic.anovaPValue(threeClasses, true), 1E-12); List<SummaryStatistics> twoClasses = new ArrayList<SummaryStatistics>(); twoClasses.add(statsA); twoClasses.add(statsB); Assert.assertEquals("ANOVA P-value", 0.904212960464, testStatistic.anovaPValue(twoClasses, false), 1E-12); }