Package mgui.stats

Class StatFunctions

java.lang.Object
mgui.interfaces.Utility
mgui.stats.StatFunctions

public class StatFunctions
extends Utility
Utility class providing general statistical functions.
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected static double fwhm_factor  
  • Constructor Summary

    Constructors
    Constructor Description
    StatFunctions()  
  • Method Summary

    Modifier and Type Method Description
    static double[] getBasicNormalStats​(java.util.ArrayList<MguiNumber> data)
    Return statistics describing a set of normally distributed values ordered as follows: mean sum standard deviation sum of squares minimum maximum
    static double[] getBasicNormalStatsDouble​(java.util.ArrayList<java.lang.Double> data)
    Return statistics describing a set of normally distributed values ordered as follows: mean sum standard deviation sum of squares
    static Jama.Matrix getBootstrapSample​(Jama.Matrix matrix, int N)
    Generates a bootstrap sample of matrix by randomly sampling from it N times, with the possibility of sampling the same observation multiple times.
    static double getFWHMtoSigma​(double fwhm)
    Converts full-width at half max to sigma (standard deviations)
    static double getGaussian​(double x, double mu, double sigma)
    Returns the normalized probability of x given the normal probability distribution defined by mu (mean) and sigma (st dev).
    static double getGaussian2​(double x, double mu, double sigma)
    Returns the normalized probability of x given the normal probability distribution defined by mu (mean) and sigma (st dev).
    static Histogram getHistogram​(java.util.ArrayList<MguiNumber> d, int bins)
    Constructs a histogram from the list d, comprised of bins bins.
    static Histogram getHistogram​(java.util.ArrayList<MguiNumber> d, int bins, double min, double max)
    Constructs a histogram from the list d, comprised of bins bins.
    static Histogram getHistogram​(java.util.ArrayList<MguiNumber> values, int bins, double min, double max, boolean sorted)
    Constructs a histogram from the list d, comprised of bins bins.
    static double[] getHolmBonferroniCorrected​(java.util.ArrayList<MguiNumber> p_values)
    Returns p-values corrected for family-wise error, using the Holm-Bonferroni method.
    static java.util.HashMap<java.lang.Integer,​java.lang.Integer> getIntegerFrequencies​(java.util.ArrayList<MguiNumber> values)
    Computes the frequency of each unique integer in the list.
    static double getMedian​(double[] values)
    Returns the median of a list of values.
    static double getMedian​(java.util.ArrayList<MguiNumber> values)
    Returns the median of a list of values.
    static double getMode​(double[] values)
    Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < default_precision.
    static double getMode​(double[] values, double precision)
    Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < precision.
    static double getMode​(java.util.ArrayList<MguiNumber> values)
    Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < default_precision.
    static double getPearsonCoefficient​(java.util.ArrayList<java.lang.Double> list1, java.util.ArrayList<java.lang.Double> list2)  
    static org.apache.commons.math3.stat.regression.SimpleRegression getRegression​(java.util.ArrayList<java.lang.Double> list1, java.util.ArrayList<java.lang.Double> list2)
    Returns a SimpleRegression object for the two lists of values.
    static double getRootMeanSquaredError​(java.util.ArrayList<MguiNumber> list1, java.util.ArrayList<MguiNumber> list2)
    Returns the root mean squared error (RMSE) for two lists of values.
    static double getSigmaToFWHM​(double sigma)
    Converts sigma (standard deviations) to full-width at half max (FWHM)
    static double[] getWeightedBasicNormalStats​(java.util.ArrayList<MguiNumber> data, java.util.ArrayList<MguiNumber> weights)
    Return statistics describing a set of weighted normally distributed values ordered as follows (see http://en.wikipedia.org/wiki/Weighted_mean): mean sum standard deviation sum of squares

    Methods inherited from class java.lang.Object

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

    • fwhm_factor

      protected static final double fwhm_factor
  • Constructor Details

    • StatFunctions

      public StatFunctions()
  • Method Details

    • getBasicNormalStats

      public static double[] getBasicNormalStats​(java.util.ArrayList<MguiNumber> data)
      Return statistics describing a set of normally distributed values ordered as follows:
      1. mean
      2. sum
      3. standard deviation
      4. sum of squares
      5. minimum
      6. maximum
      Parameters:
      data -
      Returns:
    • getMode

      public static double getMode​(java.util.ArrayList<MguiNumber> values)
      Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < default_precision.
      Parameters:
      values -
      Returns:
    • getMode

      public static double getMode​(double[] values)
      Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < default_precision.
      Parameters:
      values -
      Returns:
    • getMode

      public static double getMode​(double[] values, double precision)
      Returns the mode of a list of values, where equality is determined as abs(values[i] - values[j]) < precision.
      Parameters:
      values -
      Returns:
    • getMedian

      public static double getMedian​(java.util.ArrayList<MguiNumber> values)
      Returns the median of a list of values. If the list has an odd number of elements, returns the lowest-index median value.
      Parameters:
      values -
      Returns:
    • getMedian

      public static double getMedian​(double[] values)
      Returns the median of a list of values. If the list has an odd number of elements, returns the lowest-index median value.
      Parameters:
      values -
      Returns:
    • getWeightedBasicNormalStats

      public static double[] getWeightedBasicNormalStats​(java.util.ArrayList<MguiNumber> data, java.util.ArrayList<MguiNumber> weights)
      Return statistics describing a set of weighted normally distributed values ordered as follows (see http://en.wikipedia.org/wiki/Weighted_mean):
      1. mean
      2. sum
      3. standard deviation
      4. sum of squares
      Parameters:
      data -
      weights -
      Returns:
    • getBasicNormalStatsDouble

      public static double[] getBasicNormalStatsDouble​(java.util.ArrayList<java.lang.Double> data)
      Return statistics describing a set of normally distributed values ordered as follows:
      1. mean
      2. sum
      3. standard deviation
      4. sum of squares
      Parameters:
      data -
      Returns:
    • getPearsonCoefficient

      public static double getPearsonCoefficient​(java.util.ArrayList<java.lang.Double> list1, java.util.ArrayList<java.lang.Double> list2) throws java.lang.Exception
      Throws:
      java.lang.Exception
    • getRegression

      public static org.apache.commons.math3.stat.regression.SimpleRegression getRegression​(java.util.ArrayList<java.lang.Double> list1, java.util.ArrayList<java.lang.Double> list2)
      Returns a SimpleRegression object for the two lists of values.
      Parameters:
      list1 -
      list2 -
      Returns:
    • getGaussian

      public static double getGaussian​(double x, double mu, double sigma)
      Returns the normalized probability of x given the normal probability distribution defined by mu (mean) and sigma (st dev). Formula for Gaussian: 1/ (sigma *sqrt(2*Pi)) * exp -((x - mu)^2 / (2 * sigma)^2)
      Parameters:
      x - value to evaluate
      mu - mean of distribution
      sigma - standard deviation of distribution
      Returns:
    • getGaussian2

      public static double getGaussian2​(double x, double mu, double sigma)
      Returns the normalized probability of x given the normal probability distribution defined by mu (mean) and sigma (st dev). Modified to ensure that the return value for x = mu is always 1.0. Formula for normalized Gaussian: exp -((x - mu)^2 / (2 * sigma)^2)
      Parameters:
      x - value to evaluate
      mu - mean of distribution
      sigma - standard deviation of distribution
      Returns:
    • getHistogram

      public static Histogram getHistogram​(java.util.ArrayList<MguiNumber> d, int bins)
      Constructs a histogram from the list d, comprised of bins bins.
      Parameters:
      d - list of values
      bins - number of bins in histogram
      Returns:
      list of size bins, representing the frequency of each interval occurring between the minimum and maximum values of d
    • getHistogram

      public static Histogram getHistogram​(java.util.ArrayList<MguiNumber> d, int bins, double min, double max)
      Constructs a histogram from the list d, comprised of bins bins. The data array d will be sorted.
      Parameters:
      d - list of values
      bins - number of bins in histogram
      min -
      max -
      Returns:
      list of size bins, representing the frequency of each interval occurring between the minimum and maximum values of d
    • getHistogram

      public static Histogram getHistogram​(java.util.ArrayList<MguiNumber> values, int bins, double min, double max, boolean sorted)
      Constructs a histogram from the list d, comprised of bins bins.
      Parameters:
      d - list of values
      bins - number of bins in histogram
      min -
      max -
      sorted - Indicates whether the array d is presorted. If not, it will be sorted.
      Returns:
      list of size bins, representing the frequency of each interval occurring between the minimum and maximum values of d
    • getBootstrapSample

      public static Jama.Matrix getBootstrapSample​(Jama.Matrix matrix, int N)
      Generates a bootstrap sample of matrix by randomly sampling from it N times, with the possibility of sampling the same observation multiple times.
      Parameters:
      matrix - Matrix of observations X measurements
      N - Number of samples in result
      Returns:
      Sampled matrix
    • getHolmBonferroniCorrected

      public static double[] getHolmBonferroniCorrected​(java.util.ArrayList<MguiNumber> p_values)
      Returns p-values corrected for family-wise error, using the Holm-Bonferroni method. This method sorts the values from lowest to highest, applies correction factor n to the first, and decrements n for each subsequent factor.
      Parameters:
      p_values -
      Returns:
    • getRootMeanSquaredError

      public static double getRootMeanSquaredError​(java.util.ArrayList<MguiNumber> list1, java.util.ArrayList<MguiNumber> list2)
      Returns the root mean squared error (RMSE) for two lists of values. Calculated as:

      SQRT (sum( (v1_i - v2_i)^2 ) / n) across all values i in list1 and list2

      The lists must be of the same length.
      Parameters:
      list1 -
      list1 -
      Returns:
    • getFWHMtoSigma

      public static double getFWHMtoSigma​(double fwhm)
      Converts full-width at half max to sigma (standard deviations)
      Parameters:
      fwhm -
      Returns:
    • getSigmaToFWHM

      public static double getSigmaToFWHM​(double sigma)
      Converts sigma (standard deviations) to full-width at half max (FWHM)
      Parameters:
      fwhm -
      Returns:
    • getIntegerFrequencies

      public static java.util.HashMap<java.lang.Integer,​java.lang.Integer> getIntegerFrequencies​(java.util.ArrayList<MguiNumber> values)
      Computes the frequency of each unique integer in the list. If the list is not comprised of integer values, values will be rounded. Returns a hash map of the integers to frequencies
      Parameters:
      values -
      Returns: