Class Stats


  • public class Stats
    extends Object
    Miscellaneous functions used for statistical analysis. Some are optimized or specialized versions of methods that can be found elsewhere.
    Author:
    Paul Pavlidis
    See Also:
    cern.jet.math , cern.jet.stat
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static cern.colt.list.DoubleArrayList cdf​(cern.colt.list.DoubleArrayList x)
      Convert an array into a cumulative density function (CDF).
      static cern.colt.list.DoubleArrayList cumulate​(cern.colt.list.DoubleArrayList x)
      Convert an array into a cumulative array.
      static cern.colt.list.DoubleArrayList cumulateRight​(cern.colt.list.DoubleArrayList x)
      Convert an array into a cumulative array.
      static double cv​(cern.colt.list.DoubleArrayList data)
      Compute the coefficient of variation of an array (standard deviation / mean).
      static Double fractionDistinctValuesNonNA​(cern.colt.list.DoubleArrayList array, double tolerance)
      Compute the fraction of values which are distinct.
      static boolean isValidFraction​(double value)
      Test whether a value is a valid fractional or probability value.
      static double meanAboveQuantile​(int index, double[] array, int effectiveSize)
      calculate the mean of the values above (NOT greater or equal to) a particular index rank of an array.
      static cern.colt.list.DoubleArrayList normalize​(cern.colt.list.DoubleArrayList x)
      Adjust the elements of an array so they total to 1.0.
      static cern.colt.list.DoubleArrayList normalize​(cern.colt.list.DoubleArrayList x, double normfactor)
      Divide the elements of an array by a given factor.
      static Integer numberofDistinctValues​(cern.colt.list.DoubleArrayList array, double tolerance)  
      static Integer numberofDistinctValuesNonNA​(cern.colt.list.DoubleArrayList array, double tolerance)  
      static double quantile​(int index, double[] values, int effectiveSize)
      Given a double array, calculate the quantile requested.
      static double range​(cern.colt.list.DoubleArrayList data)
      Compute the range of an array.
    • Method Detail

      • cdf

        public static cern.colt.list.DoubleArrayList cdf​(cern.colt.list.DoubleArrayList x)
        Convert an array into a cumulative density function (CDF). This assumes that the input contains counts representing the distribution in question.
        Parameters:
        x - The input of counts (i.e. a histogram).
        Returns:
        DoubleArrayList the CDF.
      • cumulate

        public static cern.colt.list.DoubleArrayList cumulate​(cern.colt.list.DoubleArrayList x)
        Convert an array into a cumulative array. Summing is from the left hand side. Use this to make CDFs where the concern is the left tail.
        Parameters:
        x - DoubleArrayList
        Returns:
        cern.colt.list.DoubleArrayList
      • cumulateRight

        public static cern.colt.list.DoubleArrayList cumulateRight​(cern.colt.list.DoubleArrayList x)
        Convert an array into a cumulative array. Summing is from the right hand side. This is useful for creating upper-tail cumulative density histograms from count histograms, where the upper tail is expected to have very small numbers that could be lost to rounding.
        Parameters:
        x - the array of data to be cumulated.
        Returns:
        cern.colt.list.DoubleArrayList
      • cv

        public static double cv​(cern.colt.list.DoubleArrayList data)
        Compute the coefficient of variation of an array (standard deviation / mean). If the variance is zero, this returns zero. If the mean is zero, NaN is returned. If the mean is negative, the CV is computed relative to the absolute value of the mean; that is, negative values are treated as magnitudes.
        Parameters:
        data - DoubleArrayList
        Returns:
        the cv
      • isValidFraction

        public static boolean isValidFraction​(double value)
        Test whether a value is a valid fractional or probability value.
        Parameters:
        value -
        Returns:
        true if the value is in the interval 0 to 1.
      • meanAboveQuantile

        public static double meanAboveQuantile​(int index,
                                               double[] array,
                                               int effectiveSize)
        calculate the mean of the values above (NOT greater or equal to) a particular index rank of an array. Quantile must be a value from 0 to 100.
        Parameters:
        index - the rank of the value we wish to average above.
        array - Array for which we want to get the quantile.
        effectiveSize - The size of the array, not including NaNs.
        Returns:
        double
        See Also:
        DescriptiveWithMissing.meanAboveQuantile(double, cern.colt.list.DoubleArrayList)
      • normalize

        public static cern.colt.list.DoubleArrayList normalize​(cern.colt.list.DoubleArrayList x)
        Adjust the elements of an array so they total to 1.0.
        Parameters:
        x - Input array.
        Returns:
        Normalized array.
      • normalize

        public static cern.colt.list.DoubleArrayList normalize​(cern.colt.list.DoubleArrayList x,
                                                               double normfactor)
        Divide the elements of an array by a given factor.
        Parameters:
        x - Input array.
        normfactor - double
        Returns:
        Normalized array.
      • numberofDistinctValues

        public static Integer numberofDistinctValues​(cern.colt.list.DoubleArrayList array,
                                                     double tolerance)
        Parameters:
        array - input data
        tolerance - a small constant
        Returns:
        number of distinct values in the array, within tolerance. Double.NaN is counted as a distinct value.
      • numberofDistinctValuesNonNA

        public static Integer numberofDistinctValuesNonNA​(cern.colt.list.DoubleArrayList array,
                                                          double tolerance)
        Parameters:
        tolerance - a small constant
        Returns:
        number of distinct values in the array, within tolerance. Double.NaN is ignored entirely
      • fractionDistinctValuesNonNA

        public static Double fractionDistinctValuesNonNA​(cern.colt.list.DoubleArrayList array,
                                                         double tolerance)
        Compute the fraction of values which are distinct. NaNs are ignored entirely. If the data are all NaN, 0.0 is returned.
        Parameters:
        array - input data
        tolerance - a small constant to define the difference that is "distinct"
        Returns:
      • quantile

        public static double quantile​(int index,
                                      double[] values,
                                      int effectiveSize)
        Given a double array, calculate the quantile requested. Note that no interpolation is done and missing values are ignored.
        Parameters:
        index - - the rank of the value we wish to get. Thus if we have 200 items in the array, and want the median, we should enter 100.
        values - double[] - array of data we want quantile of
        effectiveSize - int the effective size of the array
        Returns:
        double the value at the requested quantile
        See Also:
        DescriptiveWithMissing.quantile(cern.colt.list.DoubleArrayList, double)
      • range

        public static double range​(cern.colt.list.DoubleArrayList data)
        Compute the range of an array. Missing values are ignored.
        Parameters:
        data - DoubleArrayList
        Returns:
        double