org.apache.commons.math.stat
Class StatUtils

java.lang.Object
  extended byorg.apache.commons.math.stat.StatUtils

public final class StatUtils
extends Object

StatUtils provides easy static implementations of common double[] based statistical methods. These return a single result value or in some cases, as identified in the javadoc for each method, Double.NaN.

Version:
$Revision: 1.22 $ $Date: 2003/11/15 18:52:31 $

Method Summary
static double max(double[] values)
          Returns the maximum of the available values
static double max(double[] values, int begin, int length)
          Returns the maximum of the available values
static double mean(double[] values)
          Returns the arithmetic mean of the available values
static double mean(double[] values, int begin, int length)
          Returns the arithmetic mean of the available values
static double min(double[] values)
          Returns the minimum of the available values
static double min(double[] values, int begin, int length)
          Returns the minimum of the available values
static double percentile(double[] values, double p)
          Returns an estimate for the pth percentile of the stored values.
static double percentile(double[] values, int begin, int length, double p)
          Returns an estimate for the pth percentile of the stored values.
static double product(double[] values)
          Returns the product for this collection of values
static double product(double[] values, int begin, int length)
          Returns the product for this collection of values
static double sum(double[] values)
          The sum of the values that have been added to Univariate.
static double sum(double[] values, int begin, int length)
          The sum of the values that have been added to Univariate.
static double sumLog(double[] values)
          Returns the sum of the natural logs for this collection of values
static double sumLog(double[] values, int begin, int length)
          Returns the sum of the natural logs for this collection of values
static double sumSq(double[] values)
          Returns the sum of the squares of the available values.
static double sumSq(double[] values, int begin, int length)
          Returns the sum of the squares of the available values.
static double variance(double[] values)
          Returns the variance of the available values.
static double variance(double[] values, int begin, int length)
          Returns the variance of the available values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sum

public static double sum(double[] values)
The sum of the values that have been added to Univariate.

Parameters:
values - Is a double[] containing the values
Returns:
the sum of the values or Double.NaN if the array is empty

sum

public static double sum(double[] values,
                         int begin,
                         int length)
The sum of the values that have been added to Univariate.

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the sum of the values or Double.NaN if the array is empty

sumSq

public static double sumSq(double[] values)
Returns the sum of the squares of the available values.

Parameters:
values - Is a double[] containing the values
Returns:
the sum of the squared values or Double.NaN if the array is empty

sumSq

public static double sumSq(double[] values,
                           int begin,
                           int length)
Returns the sum of the squares of the available values.

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the sum of the squared values or Double.NaN if the array is empty

product

public static double product(double[] values)
Returns the product for this collection of values

Parameters:
values - Is a double[] containing the values
Returns:
the product values or Double.NaN if the array is empty

product

public static double product(double[] values,
                             int begin,
                             int length)
Returns the product for this collection of values

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the product values or Double.NaN if the array is empty

sumLog

public static double sumLog(double[] values)
Returns the sum of the natural logs for this collection of values

Parameters:
values - Is a double[] containing the values
Returns:
the sumLog value or Double.NaN if the array is empty

sumLog

public static double sumLog(double[] values,
                            int begin,
                            int length)
Returns the sum of the natural logs for this collection of values

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the sumLog value or Double.NaN if the array is empty

mean

public static double mean(double[] values)
Returns the arithmetic mean of the available values

Parameters:
values - Is a double[] containing the values
Returns:
the mean of the values or Double.NaN if the array is empty

mean

public static double mean(double[] values,
                          int begin,
                          int length)
Returns the arithmetic mean of the available values

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the mean of the values or Double.NaN if the array is empty

variance

public static double variance(double[] values)
Returns the variance of the available values. This uses a corrected two pass algorithm of the following corrected two pass formula (14.1.8), and also referenced in:

"Algorithms for Computing the Sample Variance: Analysis and Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J. 1983, American Statistician, vol. 37, pp. 242?247.

Parameters:
values - Is a double[] containing the values
Returns:
the result, Double.NaN if no values for an empty array or 0.0 for a single value set.

variance

public static double variance(double[] values,
                              int begin,
                              int length)
Returns the variance of the available values. This uses a corrected two pass algorithm of the following corrected two pass formula (14.1.8), and also referenced in:

"Algorithms for Computing the Sample Variance: Analysis and Recommendations", Chan, T.F., Golub, G.H., and LeVeque, R.J. 1983, American Statistician, vol. 37, pp. 242?247.

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the result, Double.NaN if no values for an empty array or 0.0 for a single value set.

max

public static double max(double[] values)
Returns the maximum of the available values

Parameters:
values - Is a double[] containing the values
Returns:
the maximum of the values or Double.NaN if the array is empty

max

public static double max(double[] values,
                         int begin,
                         int length)
Returns the maximum of the available values

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the maximum of the values or Double.NaN if the array is empty

min

public static double min(double[] values)
Returns the minimum of the available values

Parameters:
values - Is a double[] containing the values
Returns:
the minimum of the values or Double.NaN if the array is empty

min

public static double min(double[] values,
                         int begin,
                         int length)
Returns the minimum of the available values

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
Returns:
the minimum of the values or Double.NaN if the array is empty

percentile

public static double percentile(double[] values,
                                double p)
Returns an estimate for the pth percentile of the stored values. This estimate follows the interpolation-adjusted defintion presented here

Preconditions:

Parameters:
values - Is a double[] containing the values
p - the requested percentile (scaled from 0 - 100)
Returns:
An estimate for the pth percentile of the data values

percentile

public static double percentile(double[] values,
                                int begin,
                                int length,
                                double p)
Returns an estimate for the pth percentile of the stored values. This estimate follows the interpolation-adjusted defintion presented here

Preconditions:

Parameters:
values - Is a double[] containing the values
begin - processing at this point in the array
length - processing at this point in the array
p - the requested percentile (scaled from 0 - 100)
Returns:
An estimate for the pth percentile of the data values


Copyright © 2003-2004 Apache Software Foundation. All Rights Reserved.