Class OneWayAnova
- java.lang.Object
-
- org.apache.commons.math4.legacy.stat.inference.OneWayAnova
-
public class OneWayAnova extends Object
Implements one-way ANOVA (analysis of variance) statistics.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
- Since:
- 1.2
-
-
Constructor Summary
Constructors Constructor Description OneWayAnova()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
anovaFValue(Collection<double[]> categoryData)
Computes the ANOVA F-value for a collection ofdouble[]
arrays.double
anovaPValue(Collection<double[]> categoryData)
Computes the ANOVA P-value for a collection ofdouble[]
arrays.double
anovaPValue(Collection<SummaryStatistics> categoryData, boolean allowOneElementData)
Computes the ANOVA P-value for a collection ofSummaryStatistics
.boolean
anovaTest(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.
-
-
-
Constructor Detail
-
OneWayAnova
public OneWayAnova()
Default constructor.
-
-
Method Detail
-
anovaFValue
public double anovaFValue(Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException
Computes the ANOVA F-value for a collection ofdouble[]
arrays.Preconditions:
- The categoryData
Collection
must containdouble[]
arrays. - There must be at least two
double[]
arrays in thecategoryData
collection and each of these arrays must contain at least two values.
This implementation computes the F statistic using the definitional formula
F = msbg/mswg
wheremsbg = between group mean square mswg = within group mean square
are as defined here- Parameters:
categoryData
-Collection
ofdouble[]
arrays each containing data for one category- Returns:
- Fvalue
- Throws:
NullArgumentException
- ifcategoryData
isnull
DimensionMismatchException
- if the length of thecategoryData
array is less than 2 or a containeddouble[]
array does not have at least two values
- The categoryData
-
anovaPValue
public double anovaPValue(Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException
Computes the ANOVA P-value for a collection ofdouble[]
arrays.Preconditions:
- The categoryData
Collection
must containdouble[]
arrays. - There must be at least two
double[]
arrays in thecategoryData
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 formulap = survivalProbability(F)
whereF
is the F value andsurvivalProbability = 1 - cumulativeProbability
is the commons-statistics implementation of the F distribution.- Parameters:
categoryData
-Collection
ofdouble[]
arrays each containing data for one category- Returns:
- Pvalue
- Throws:
NullArgumentException
- ifcategoryData
isnull
DimensionMismatchException
- if the length of thecategoryData
array is less than 2 or a containeddouble[]
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 exceeded
- The categoryData
-
anovaPValue
public double anovaPValue(Collection<SummaryStatistics> categoryData, boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException
Computes the ANOVA P-value for a collection ofSummaryStatistics
.Preconditions:
- The categoryData
Collection
must containSummaryStatistics
. - There must be at least two
SummaryStatistics
in thecategoryData
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 formulap = survivalProbability(F)
whereF
is the F value andsurvivalProbability = 1 - cumulativeProbability
is the commons-statistics implementation of the F distribution.- Parameters:
categoryData
-Collection
ofSummaryStatistics
each containing data for one categoryallowOneElementData
- if true, allow computation for one catagory only or for one data element per category- Returns:
- Pvalue
- Throws:
NullArgumentException
- ifcategoryData
isnull
DimensionMismatchException
- if the length of thecategoryData
array is less than 2 or a containedSummaryStatistics
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 exceeded- Since:
- 3.2
- The categoryData
-
anovaTest
public boolean anovaTest(Collection<double[]> categoryData, double alpha) throws NullArgumentException, DimensionMismatchException, OutOfRangeException, ConvergenceException, MaxCountExceededException
Performs an ANOVA test, evaluating the null hypothesis that there is no difference among the means of the data categories.Preconditions:
- The categoryData
Collection
must containdouble[]
arrays. - There must be at least two
double[]
arrays in thecategoryData
collection and each of these arrays must contain at least two values. - alpha must be strictly greater than 0 and less than or equal to 0.5.
This implementation uses the
commons-math F Distribution implementation
to estimate the exact p-value, using the formulap = survivalProbability(F)
whereF
is the F value andsurvivalProbability = 1 - cumulativeProbability
is the commons-statistics implementation of the F distribution.True is returned iff the estimated p-value is less than alpha.
- Parameters:
categoryData
-Collection
ofdouble[]
arrays each containing data for one categoryalpha
- significance level of the test- Returns:
- true if the null hypothesis can be rejected with confidence 1 - alpha
- Throws:
NullArgumentException
- ifcategoryData
isnull
DimensionMismatchException
- if the length of thecategoryData
array is less than 2 or a containeddouble[]
array does not have at least two valuesOutOfRangeException
- ifalpha
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 exceeded
- The categoryData
-
-