Class Stats

java.lang.Object
ubic.basecode.math.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:
  • Method Details

    • cdf

      public static DoubleArrayList cdf(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 DoubleArrayList cumulate(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 DoubleArrayList cumulateRight(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(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:
    • normalize

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

      public static DoubleArrayList normalize(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(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(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(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:
    • range

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