Class OneWayAnova

    • 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)
      Compute x^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.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT

        private static final OneWayAnova DEFAULT
        Default instance.
    • Constructor Detail

      • OneWayAnova

        private OneWayAnova()
        Private constructor.
    • 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)
        Compute x^2.
        Parameters:
        x - Value.
        Returns:
        x^2