Class OneWayAnova

java.lang.Object
org.apache.commons.statistics.inference.OneWayAnova

public final 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.

This implementation computes the F statistic using the definitional formula:

\[ F = \frac{\text{between-group variability}}{\text{within-group variability}} \]

Since:
1.1
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Result for the one-way ANOVA.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final OneWayAnova
    Default instance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor.
  • Method Summary

    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(Collection<double[]> data)
    Return true if all values in the arrays match.
    private static OneWayAnova.Result
    aov(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)
    Compute x^2.
    double
    statistic(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.
    test(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.
    Return an instance using the default options.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT

      private static final OneWayAnova DEFAULT
      Default instance.
  • Constructor Details

    • OneWayAnova

      private OneWayAnova()
      Private constructor.
  • Method Details

    • withDefaults

      public static OneWayAnova withDefaults()
      Return an instance using the default options.
      Returns:
      default instance
    • statistic

      public double statistic(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:
      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(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:
      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(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:
      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(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)
      Compute x^2.
      Parameters:
      x - Value.
      Returns:
      x^2