org.fhcrc.cpl.toolbox.statistics
Class BasicStatistics

java.lang.Object
  extended by org.fhcrc.cpl.toolbox.statistics.BasicStatistics

public class BasicStatistics
extends java.lang.Object

A class with generic methods for basic stats. Add methods as needed. A lot of things are written twice, once for floats and once for doubles. That's annoying. But it would be wasteful of space and time to do conversions


Constructor Summary
BasicStatistics()
           
 
Method Summary
static double calcNormalCumDensity(double mu, double sigma, double x)
          Calculate the cumulative density of the normal distribution function with parameters mu and sigma, at point x
static double calcNormalDistDensity(double mu, double sigma, double x)
          Calculate the density of the normal distribution function with parameters mu and sigma, at point x
static double calcStandardNormalCumDensity(double z)
          Calculate the cumulative density of the standard normal distribution at point x
static double coefficientOfVariation(double[] input)
           
static double coefficientOfVariation(java.util.List<? extends java.lang.Number> input)
           
static double correlationCoefficient(double[] xvalues, double[] yvalues)
          covariance(xy) / (sx * sy)
static float correlationCoefficient(float[] xvalues, float[] yvalues)
          covariance(xy) / (sx * sy)
static double correlationCoefficient(java.util.List<? extends java.lang.Number> xvaluesList, java.util.List<? extends java.lang.Number> yvaluesList)
           
static double covariance(double[] xvalues, double[] yvalues)
          Covariance = (sum(x*y) - ((sumx)(sumy)/n)) / (n-1)
static float covariance(float[] xvalues, float[] yvalues)
          Covariance = (sum(x*y) - ((sumx)(sumy)/n)) / (n-1)
static double erf(double z)
          Error function for standard normal distribution
static double geometricMean(double[] values)
          Geometric mean is defined as ((x1)(x2)(x3)...(xk)) ^ 1/k
static double geometricMean(double value1, double value2)
           
static float geometricMean(float[] values)
           
static double geometricMean(java.util.List<? extends java.lang.Number> inputs)
           
static Pair<java.lang.Double,java.lang.Double> interQuartileRange(double[] inputs)
          Calculate the interquartile range.
static Pair<java.lang.Double,java.lang.Double> interQuartileRange(java.util.List<? extends java.lang.Number> inputs)
           
static double[] leverages(double[] inputs)
          Compute the leverage of each input: (x-xbar)^2/((n-1)sigmax^2))
static float[] leverages(float[] inputs)
          Compute the leverage of each input: (x-xbar)^2/((n-1)sigmax^2))
static double max(double[] values)
           
static float max(float[] values)
           
static double max(java.util.List<? extends java.lang.Number> values)
           
static double mean(double[] inputs)
          Calculate the mean of the inputs
static float mean(float[] inputs)
          Calculate the mean of the inputs
static double mean(int[] inputs)
          Calculate the mean of the inputs
static double mean(java.util.List<? extends java.lang.Number> inputs)
          Calculate the mean of the inputs
static double median(double[] inputs)
          Calculate the median of the inputs.
static float median(float[] inputs)
          Calculate the median of the inputs.
static double median(java.util.List<? extends java.lang.Number> inputs)
           
static double min(double[] values)
           
static double min(java.util.List<? extends java.lang.Number> values)
           
static double percentile(double[] values, double p)
          Returns an estimate of the pth percentile of the values in the values array, starting with the element in (0-based) position begin in the array and including length values.
static double percentile(java.util.List<? extends java.lang.Number> values, double p)
          calculate percentile p of values in list
static double standardDeviation(double[] inputs)
          Calculate the standard deviation of the inputs
static float standardDeviation(float[] inputs)
          Calculate the standard deviation of the inputs
static double standardDeviation(java.util.List<? extends java.lang.Number> inputs)
           
static float standardDeviationFloatList(java.util.List<? extends java.lang.Number> inputs)
           
static double standardGaussian(double x)
          Calculate a standard Gaussian with mean 0, variance 1
static double[] studentizedResiduals(double[] xValues, double[] residuals)
          Convenience method
static double[] studentizedResiduals(double[] xValues, double[] residuals, double[] leverages)
          Calculate the studentized residuals of arrays of somethingorother represented here by their X values, leverages (based on X values), and residuals.
static double sum(double[] values)
           
static float sum(float[] values)
           
static double sum(java.util.List<? extends java.lang.Number> values)
           
static double variance(double[] inputs)
          Calculate the variance of the inputs
static float variance(float[] inputs)
          Calculate the variance of the inputs
static double weightedGeometricMean(java.util.List<? extends java.lang.Number> inputs, java.util.List<? extends java.lang.Number> weights)
          Calculate the weighted geometric mean.
static double weightedMean(java.util.List<? extends java.lang.Number> inputs, java.util.List<? extends java.lang.Number> weights)
          Calculate the weighted mean
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicStatistics

public BasicStatistics()
Method Detail

standardDeviation

public static float standardDeviation(float[] inputs)
Calculate the standard deviation of the inputs

Parameters:
inputs -
Returns:

standardDeviation

public static double standardDeviation(double[] inputs)
Calculate the standard deviation of the inputs

Parameters:
inputs -
Returns:

standardDeviation

public static double standardDeviation(java.util.List<? extends java.lang.Number> inputs)

standardDeviationFloatList

public static float standardDeviationFloatList(java.util.List<? extends java.lang.Number> inputs)

variance

public static float variance(float[] inputs)
Calculate the variance of the inputs

Parameters:
inputs -
Returns:

variance

public static double variance(double[] inputs)
Calculate the variance of the inputs

Parameters:
inputs -
Returns:

mean

public static double mean(int[] inputs)
Calculate the mean of the inputs

Parameters:
inputs -
Returns:

mean

public static float mean(float[] inputs)
Calculate the mean of the inputs

Parameters:
inputs -
Returns:

mean

public static double mean(java.util.List<? extends java.lang.Number> inputs)
Calculate the mean of the inputs

Parameters:
inputs -
Returns:

mean

public static double mean(double[] inputs)
Calculate the mean of the inputs

Parameters:
inputs -
Returns:

median

public static double median(java.util.List<? extends java.lang.Number> inputs)

median

public static double median(double[] inputs)
Calculate the median of the inputs. This is median as defined in R -- average of the middle two points. NOT necessarily one of the inputs. Clones before sorting, so as not to disrupt input

Parameters:
inputs -
Returns:

interQuartileRange

public static Pair<java.lang.Double,java.lang.Double> interQuartileRange(double[] inputs)
Calculate the interquartile range. I think this is right. Calculate the median, then calculate the median of everything under the median and everything over the median.

Parameters:
inputs -
Returns:

interQuartileRange

public static Pair<java.lang.Double,java.lang.Double> interQuartileRange(java.util.List<? extends java.lang.Number> inputs)

min

public static double min(double[] values)

min

public static double min(java.util.List<? extends java.lang.Number> values)

max

public static double max(double[] values)

max

public static float max(float[] values)

max

public static double max(java.util.List<? extends java.lang.Number> values)

percentile

public static double percentile(java.util.List<? extends java.lang.Number> values,
                                double p)
calculate percentile p of values in list

Parameters:
values -
p -
Returns:

percentile

public static double percentile(double[] values,
                                double p)
Returns an estimate of the pth percentile of the values in the values array, starting with the element in (0-based) position begin in the array and including length values.

Calls to this method do not modify the array Copied from org.apache.commons.math.stat todo: figure out for sure whether having median() call this is OK

Parameters:
values - array of input values
p - the percentile to compute
Returns:
the percentile value
Throws:
java.lang.IllegalArgumentException - if the parameters are not valid or the input array is null

median

public static float median(float[] inputs)
Calculate the median of the inputs. This is median as defined in R -- average of the middle two points. NOT necessarily one of the inputs. Clones before sorting, so as not to disrupt input

Parameters:
inputs -
Returns:

leverages

public static double[] leverages(double[] inputs)
Compute the leverage of each input: (x-xbar)^2/((n-1)sigmax^2))

Parameters:
inputs -
Returns:

leverages

public static float[] leverages(float[] inputs)
Compute the leverage of each input: (x-xbar)^2/((n-1)sigmax^2))

Parameters:
inputs -
Returns:

studentizedResiduals

public static double[] studentizedResiduals(double[] xValues,
                                            double[] residuals)
Convenience method

Parameters:
xValues -
residuals -
Returns:

studentizedResiduals

public static double[] studentizedResiduals(double[] xValues,
                                            double[] residuals,
                                            double[] leverages)
Calculate the studentized residuals of arrays of somethingorother represented here by their X values, leverages (based on X values), and residuals.

Parameters:
xValues -
residuals -
leverages -
Returns:

sum

public static double sum(double[] values)

sum

public static double sum(java.util.List<? extends java.lang.Number> values)

sum

public static float sum(float[] values)

coefficientOfVariation

public static double coefficientOfVariation(double[] input)

coefficientOfVariation

public static double coefficientOfVariation(java.util.List<? extends java.lang.Number> input)

covariance

public static double covariance(double[] xvalues,
                                double[] yvalues)
Covariance = (sum(x*y) - ((sumx)(sumy)/n)) / (n-1)

Parameters:
xvalues -
yvalues -
Returns:

covariance

public static float covariance(float[] xvalues,
                               float[] yvalues)
Covariance = (sum(x*y) - ((sumx)(sumy)/n)) / (n-1)

Parameters:
xvalues -
yvalues -
Returns:

correlationCoefficient

public static double correlationCoefficient(java.util.List<? extends java.lang.Number> xvaluesList,
                                            java.util.List<? extends java.lang.Number> yvaluesList)

correlationCoefficient

public static double correlationCoefficient(double[] xvalues,
                                            double[] yvalues)
covariance(xy) / (sx * sy)


correlationCoefficient

public static float correlationCoefficient(float[] xvalues,
                                           float[] yvalues)
covariance(xy) / (sx * sy)


geometricMean

public static double geometricMean(double[] values)
Geometric mean is defined as ((x1)(x2)(x3)...(xk)) ^ 1/k

Parameters:
values -
Returns:

geometricMean

public static double geometricMean(java.util.List<? extends java.lang.Number> inputs)

geometricMean

public static float geometricMean(float[] values)

geometricMean

public static double geometricMean(double value1,
                                   double value2)

weightedGeometricMean

public static double weightedGeometricMean(java.util.List<? extends java.lang.Number> inputs,
                                           java.util.List<? extends java.lang.Number> weights)
Calculate the weighted geometric mean. Exponentiated weighted mean of logs.

Parameters:
inputs -
weights -
Returns:

weightedMean

public static double weightedMean(java.util.List<? extends java.lang.Number> inputs,
                                  java.util.List<? extends java.lang.Number> weights)
Calculate the weighted mean

Parameters:
inputs -
weights -
Returns:

standardGaussian

public static double standardGaussian(double x)
Calculate a standard Gaussian with mean 0, variance 1

Parameters:
x -
Returns:

calcNormalDistDensity

public static double calcNormalDistDensity(double mu,
                                           double sigma,
                                           double x)
Calculate the density of the normal distribution function with parameters mu and sigma, at point x

Parameters:
mu -
sigma -
x -
Returns:

erf

public static double erf(double z)
Error function for standard normal distribution

Parameters:
z -
Returns:

calcStandardNormalCumDensity

public static double calcStandardNormalCumDensity(double z)
Calculate the cumulative density of the standard normal distribution at point x

Parameters:
z -
Returns:

calcNormalCumDensity

public static double calcNormalCumDensity(double mu,
                                          double sigma,
                                          double x)
Calculate the cumulative density of the normal distribution function with parameters mu and sigma, at point x

Parameters:
mu -
sigma -
x -
Returns:


Fred Hutchinson Cancer Research Center