Top Description Inners Constructors Methods
org.apache.commons.math3.stat.inference

public Class OneWayAnova

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collection, org.apache.commons.math3.distribution.FDistribution, org.apache.commons.math3.exception.ConvergenceException, .DimensionMismatchException, .MaxCountExceededException, .NullArgumentException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.stat.descriptive.SummaryStatistics, org.apache.commons.math3.util.MathUtils

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 org.apache.commons.math3.stat.inference.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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
OneWayAnova.AnovaStats

Convenience class to pass dfbg,dfwg,F values around within OneWayAnova.

Constructor Summary

AccessConstructor and Description
public
OneWayAnova()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
public double

Returns:

Fvalue
anovaFValue
(final Collection<double[]>
Collection of double[] arrays each containing data for one category
categoryData
)

Computes the ANOVA F-value for a collection of double[] arrays.

public double

Returns:

Pvalue
anovaPValue
(final Collection<double[]>
Collection of double[] arrays each containing data for one category
categoryData
)

Computes the ANOVA P-value for a collection of double[] arrays.

public double

Returns:

Pvalue
anovaPValue
(final Collection<SummaryStatistics>
Collection of SummaryStatistics each containing data for one category
categoryData
,
final boolean
if true, allow computation for one catagory only or for one data element per category
allowOneElementData
)

Computes the ANOVA P-value for a collection of SummaryStatistics.

private OneWayAnova.AnovaStats

Returns:

computed AnovaStats
anovaStats
(final Collection<double[]>
Collection of double[] arrays each containing data for one category
categoryData
)

This method calls the method that actually does the calculations (except P-value).

private OneWayAnova.AnovaStats

Returns:

computed AnovaStats
anovaStats
(final Collection<SummaryStatistics>
Collection of double[] arrays each containing data for one category
categoryData
,
final boolean
if true, allow computation for one catagory only or for one data element per category
allowOneElementData
)

This method actually does the calculations (except P-value).

public boolean

Returns:

true if the null hypothesis can be rejected with confidence 1 - alpha
anovaTest
(final Collection<double[]>
Collection of double[] arrays each containing data for one category
categoryData
,
final double
significance level of the test
alpha
)

Performs an ANOVA test, evaluating the null hypothesis that there is no difference among the means of the data categories.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

OneWayAnovaback to summary
public OneWayAnova()

Default constructor.

Method Detail

anovaFValueback to summary
public double anovaFValue(final Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException

Computes the ANOVA F-value for a collection of double[] arrays.

Preconditions:

  • The categoryData Collection must contain double[] arrays.
  • There must be at least two 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/mswg
where
 msbg = between group mean square
 mswg = within group mean square
are as defined here

Parameters
categoryData:Collection<double[]>

Collection of double[] arrays each containing data for one category

Returns:double

Fvalue

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if the length of the categoryData array is less than 2 or a contained double[] array does not have at least two values
anovaPValueback to summary
public double anovaPValue(final Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException

Computes the ANOVA P-value for a collection of double[] arrays.

Preconditions:

  • The categoryData Collection must contain double[] arrays.
  • There must be at least two 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.

Parameters
categoryData:Collection<double[]>

Collection of double[] arrays each containing data for one category

Returns:double

Pvalue

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if the length of the categoryData array is less than 2 or a contained double[] array does not have at least two values
ConvergenceException:
if the p-value can not be computed due to a convergence error
MaxCountExceededException:
if the maximum number of iterations is exceeded
anovaPValueback to summary
public double anovaPValue(final Collection<SummaryStatistics> categoryData, final boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException, ConvergenceException, MaxCountExceededException

Computes the ANOVA P-value for a collection of SummaryStatistics.

Preconditions:

  • The categoryData Collection must contain SummaryStatistics.
  • There must be at least two 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.

Parameters
categoryData:Collection<SummaryStatistics>

Collection of SummaryStatistics each containing data for one category

allowOneElementData:boolean

if true, allow computation for one catagory only or for one data element per category

Returns:double

Pvalue

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if the length of the categoryData array is less than 2 or a contained SummaryStatistics does not have at least two values
ConvergenceException:
if the p-value can not be computed due to a convergence error
MaxCountExceededException:
if the maximum number of iterations is exceeded
Since
3.2
anovaStatsback to summary
private OneWayAnova.AnovaStats anovaStats(final Collection<double[]> categoryData) throws NullArgumentException, DimensionMismatchException

This method calls the method that actually does the calculations (except P-value).

Parameters
categoryData:Collection<double[]>

Collection of double[] arrays each containing data for one category

Returns:OneWayAnova.AnovaStats

computed AnovaStats

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if the length of the categoryData array is less than 2 or a contained double[] array does not contain at least two values
anovaStatsback to summary
private OneWayAnova.AnovaStats anovaStats(final Collection<SummaryStatistics> categoryData, final boolean allowOneElementData) throws NullArgumentException, DimensionMismatchException

This method actually does the calculations (except P-value).

Parameters
categoryData:Collection<SummaryStatistics>

Collection of double[] arrays each containing data for one category

allowOneElementData:boolean

if true, allow computation for one catagory only or for one data element per category

Returns:OneWayAnova.AnovaStats

computed AnovaStats

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if allowOneElementData is false and the number of categories is less than 2 or a contained SummaryStatistics does not contain at least two values
anovaTestback to summary
public boolean anovaTest(final Collection<double[]> categoryData, final 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 contain double[] arrays.
  • There must be at least two double[] arrays in the categoryData 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 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.

Parameters
categoryData:Collection<double[]>

Collection of double[] arrays each containing data for one category

alpha:double

significance level of the test

Returns:boolean

true if the null hypothesis can be rejected with confidence 1 - alpha

Exceptions
NullArgumentException:
if categoryData is null
DimensionMismatchException:
if the length of the categoryData array is less than 2 or a contained double[] array does not have at least two values
OutOfRangeException:
if alpha is not in the range (0, 0.5]
ConvergenceException:
if the p-value can not be computed due to a convergence error
MaxCountExceededException:
if the maximum number of iterations is exceeded
org.apache.commons.math3.stat.inference back to summary

private Class OneWayAnova.AnovaStats

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.stat.inference.OneWayAnova.AnovaStats

Convenience class to pass dfbg,dfwg,F values around within OneWayAnova. No get/set methods provided.

Field Summary

Modifier and TypeField and Description
private final int
dfbg

Degrees of freedom in numerator (between groups).

private final int
dfwg

Degrees of freedom in denominator (within groups).

private final double
F

Statistic.

Constructor Summary

AccessConstructor and Description
private
AnovaStats(int
degrees of freedom in numerator (between groups)
dfbg
,
int
degrees of freedom in denominator (within groups)
dfwg
,
double
statistic
F
)

Constructor

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dfbgback to summary
private final int dfbg

Degrees of freedom in numerator (between groups).

dfwgback to summary
private final int dfwg

Degrees of freedom in denominator (within groups).

Fback to summary
private final double F

Statistic.

Constructor Detail

AnovaStatsback to summary
private AnovaStats(int dfbg, int dfwg, double F)

Constructor

Parameters
dfbg:int

degrees of freedom in numerator (between groups)

dfwg:int

degrees of freedom in denominator (within groups)

F:double

statistic