Class OneWayAnova
- java.lang.Object
-
- org.apache.commons.statistics.inference.OneWayAnova
-
public final class OneWayAnova extends java.lang.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
.This implementation computes the F statistic using the definitional formula:
\[ F = \frac{\text{between-group variability}}{\text{within-group variability}} \]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
OneWayAnova.Result
Result for the one-way ANOVA.
-
Field Summary
Fields Modifier and Type Field Description private static OneWayAnova
DEFAULT
Default instance.
-
Constructor Summary
Constructors Modifier Constructor Description private
OneWayAnova()
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static boolean
allMatch(double v, double[] a)
Return true if all values in the array match the specified value.private static boolean
allMatch(java.util.Collection<double[]> data)
Return true if all values in the arrays match.private static OneWayAnova.Result
aov(java.util.Collection<double[]> data, double[] statistic)
Performs an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.private static double
pow2(double x)
Computex^2
.double
statistic(java.util.Collection<double[]> data)
Computes the F statistic for an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.OneWayAnova.Result
test(java.util.Collection<double[]> data)
Performs an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.static OneWayAnova
withDefaults()
Return an instance using the default options.
-
-
-
Field Detail
-
DEFAULT
private static final OneWayAnova DEFAULT
Default instance.
-
-
Method Detail
-
withDefaults
public static OneWayAnova withDefaults()
Return an instance using the default options.- Returns:
- default instance
-
statistic
public double statistic(java.util.Collection<double[]> data)
Computes the F statistic for an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.Special cases:
- If the value in each category is the same (no variance within groups) but different between groups, the f-value is infinity.
- If the value in every group is the same (no variance within or between groups),
the f-value is
NaN
.
- Parameters:
data
- Category summary data.- Returns:
- F statistic
- Throws:
java.lang.IllegalArgumentException
- if the number of categories is less than two; a contained category does not have at least one value; or all categories have only one value (zero degrees of freedom within groups)
-
test
public OneWayAnova.Result test(java.util.Collection<double[]> data)
Performs an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.Special cases:
- If the value in each category is the same (no variance within groups) but different between groups, the f-value is infinity and the p-value is zero.
- If the value in every group is the same (no variance within or between groups),
the f-value and p-value are
NaN
.
- Parameters:
data
- Category summary data.- Returns:
- test result
- Throws:
java.lang.IllegalArgumentException
- if the number of categories is less than two; a contained category does not have at least one value; or all categories have only one value (zero degrees of freedom within groups)
-
aov
private static OneWayAnova.Result aov(java.util.Collection<double[]> data, double[] statistic)
Performs an ANOVA test for a collection of category data, evaluating the null hypothesis that there is no difference among the means of the data categories.This is a utility method to allow computation of the F statistic without the p-value or partitioning of the variance. If the
statistic
is not null the method will record the F statistic in the array and return null.- Parameters:
data
- Category summary data.statistic
- Result for the F statistic (or null).- Returns:
- test result (or null)
- Throws:
java.lang.IllegalArgumentException
- if the number of categories is less than two; a contained category does not have at least one value; or all categories have only one value (zero degrees of freedom within groups)
-
allMatch
private static boolean allMatch(double v, double[] a)
Return true if all values in the array match the specified value.- Parameters:
v
- Value.a
- Array.- Returns:
- true if all match
-
allMatch
private static boolean allMatch(java.util.Collection<double[]> data)
Return true if all values in the arrays match.Assumes that there are at least two arrays and that each array has the same value throughout. Thus only the first element in each array is checked.
- Parameters:
data
- Arrays.- Returns:
- true if all match
-
pow2
private static double pow2(double x)
Computex^2
.- Parameters:
x
- Value.- Returns:
x^2
-
-