public class OneWayAnova
extends java.lang.Object
Tests for differences between two or more categories of univariate data
(for example, the body mass index of accountants, lawyers, doctors and
computer programmers). When two categories are given, this is equivalent to
the TTest.
Uses the commons-math F Distribution implementation to estimate exact p-values.
This implementation is based on a description at http://faculty.vassar.edu/lowry/ch13pt1.html
Abbreviations: bg = between groups,
wg = within groups,
ss = sum squared deviations
| Modifier and Type | Class and Description |
|---|---|
private static class |
OneWayAnova.AnovaStats
Convenience class to pass dfbg,dfwg,F values around within OneWayAnova.
|
| Constructor and Description |
|---|
OneWayAnova()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
double |
anovaFValue(java.util.Collection<double[]> categoryData)
Computes the ANOVA F-value for a collection of
double[]
arrays. |
double |
anovaPValue(java.util.Collection<double[]> categoryData)
Computes the ANOVA P-value for a collection of
double[]
arrays. |
double |
anovaPValue(java.util.Collection<SummaryStatistics> categoryData,
boolean allowOneElementData)
Computes the ANOVA P-value for a collection of
SummaryStatistics. |
private OneWayAnova.AnovaStats |
anovaStats(java.util.Collection<double[]> categoryData)
This method calls the method that actually does the calculations (except
P-value).
|
private OneWayAnova.AnovaStats |
anovaStats(java.util.Collection<SummaryStatistics> categoryData,
boolean allowOneElementData)
This method actually does the calculations (except P-value).
|
boolean |
anovaTest(java.util.Collection<double[]> categoryData,
double alpha)
Performs an ANOVA test, evaluating the null hypothesis that there
is no difference among the means of the data categories.
|
public double anovaFValue(java.util.Collection<double[]> categoryData)
throws NullArgumentException,
DimensionMismatchException
double[]
arrays.
Preconditions:
Collection must contain
double[] arrays.double[] arrays in the
categoryData collection and each of these arrays must
contain at least two values.This implementation computes the F statistic using the definitional formula
F = msbg/mswgwhere
msbg = between group mean square mswg = within group mean squareare as defined here
categoryData - Collection of double[]
arrays each containing data for one categoryNullArgumentException - if categoryData is nullDimensionMismatchException - if the length of the categoryData
array is less than 2 or a contained double[] array does not have
at least two valuespublic double anovaPValue(java.util.Collection<double[]> categoryData)
throws NullArgumentException,
DimensionMismatchException,
ConvergenceException,
MaxCountExceededException
double[]
arrays.
Preconditions:
Collection must contain
double[] arrays.double[] arrays in the
categoryData collection and each of these arrays must
contain at least two values.
This implementation uses the
commons-math F Distribution implementation to estimate the exact
p-value, using the formula
p = 1 - cumulativeProbability(F)where
F is the F value and cumulativeProbability
is the commons-math implementation of the F distribution.categoryData - Collection of double[]
arrays each containing data for one categoryNullArgumentException - if categoryData is nullDimensionMismatchException - if the length of the categoryData
array is less than 2 or a contained double[] array does not have
at least two valuesConvergenceException - if the p-value can not be computed due to a convergence errorMaxCountExceededException - if the maximum number of iterations is exceededpublic double anovaPValue(java.util.Collection<SummaryStatistics> categoryData, boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException
SummaryStatistics.
Preconditions:
Collection must contain
SummaryStatistics.SummaryStatistics in the
categoryData collection and each of these statistics must
contain at least two values.
This implementation uses the
commons-math F Distribution implementation to estimate the exact
p-value, using the formula
p = 1 - cumulativeProbability(F)where
F is the F value and cumulativeProbability
is the commons-math implementation of the F distribution.categoryData - Collection of SummaryStatistics
each containing data for one categoryallowOneElementData - if true, allow computation for one catagory
only or for one data element per categoryNullArgumentException - if categoryData is nullDimensionMismatchException - if the length of the categoryData
array is less than 2 or a contained SummaryStatistics does not have
at least two valuesConvergenceException - if the p-value can not be computed due to a convergence errorMaxCountExceededException - if the maximum number of iterations is exceededprivate OneWayAnova.AnovaStats anovaStats(java.util.Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException
categoryData - Collection of double[] arrays each
containing data for one categoryNullArgumentException - if categoryData is nullDimensionMismatchException - if the length of the categoryData array is less
than 2 or a contained double[] array does not
contain at least two valuespublic boolean anovaTest(java.util.Collection<double[]> categoryData,
double alpha)
throws NullArgumentException,
DimensionMismatchException,
OutOfRangeException,
ConvergenceException,
MaxCountExceededException
Preconditions:
Collection must contain
double[] arrays.double[] arrays in the
categoryData collection and each of these arrays must
contain at least two values.
This implementation uses the
commons-math F Distribution implementation to estimate the exact
p-value, using the formula
p = 1 - cumulativeProbability(F)where
F is the F value and cumulativeProbability
is the commons-math implementation of the F distribution.
True is returned iff the estimated p-value is less than alpha.
categoryData - Collection of double[]
arrays each containing data for one categoryalpha - significance level of the testNullArgumentException - if categoryData is nullDimensionMismatchException - if the length of the categoryData
array is less than 2 or a contained double[] array does not have
at least two valuesOutOfRangeException - if alpha is not in the range (0, 0.5]ConvergenceException - if the p-value can not be computed due to a convergence errorMaxCountExceededException - if the maximum number of iterations is exceededprivate OneWayAnova.AnovaStats anovaStats(java.util.Collection<SummaryStatistics> categoryData, boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException
categoryData - Collection of double[]
arrays each containing data for one categoryallowOneElementData - if true, allow computation for one catagory
only or for one data element per categoryNullArgumentException - if categoryData is nullDimensionMismatchException - if allowOneElementData is false and the number of
categories is less than 2 or a contained SummaryStatistics does not contain
at least two valuesCopyright (c) 2003-2015 Apache Software Foundation