jstats
Class Statistic

java.lang.Object
  extended byjstats.Statistic

public class Statistic
extends java.lang.Object

Statistic is the base class of the jstats package, providing a number of static methods useful for collections of data.

Version:
0.2.3
Author:
Justin Scheiber, David Edelstein

Field Summary
static java.util.Locale locale
           
static int STIRLING_THRESHOLD
          Numbers greater than this will have factorials computed using Stirling's Approximation
 
Constructor Summary
Statistic()
           
 
Method Summary
static double combination(double n, double r)
          Combination function: nCr = n!
static double factorial(double n)
          Performs factorial (n!)
static double permutation(double n, double r)
          Permutation function: nPr = n!
static double StirlingApproximation(double n)
          Stirling's Approximation for a factorial: For large values of n, n!
static double summation(double[] values)
          Sum of all the values in an array.
static double summation(long[] values)
          Sum of all the values in an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STIRLING_THRESHOLD

public static final int STIRLING_THRESHOLD
Numbers greater than this will have factorials computed using Stirling's Approximation

See Also:
Constant Field Values

locale

public static java.util.Locale locale
Constructor Detail

Statistic

public Statistic()
Method Detail

factorial

public static double factorial(double n)
                        throws StatisticException

Performs factorial (n!) function. Uses Stirling's Approximation for n > 50.

Note that n, while a double, must be an integer value; any fractional component of n is discarded before the factorial is computed; i.e., the factorial of 6.8 will be computed as a factorial of 6 (factorial(6.8) == 6!).

Parameters:
n - number to factor
Returns:
the factorial of n
Throws:
StatisticException - for n < 0

StirlingApproximation

public static double StirlingApproximation(double n)
Stirling's Approximation for a factorial: For large values of n, n! =~ n^n * e^-n * 2*PI*n.

Parameters:
n - number to factor
Returns:
Stirling's Approximation for n!

permutation

public static double permutation(double n,
                                 double r)
                          throws StatisticException

Permutation function:

nPr = n!/(n-r)!

Note that n and r, while doubles, must actually be integer values and are calculated as such; any fractional component is discarded

Parameters:
n - number of items from which to select
r - number of items in selection
Returns:
number of permutations P(n,r)
Throws:
StatisticException - if n < r or r < 0 or n < 0

combination

public static double combination(double n,
                                 double r)
                          throws StatisticException

Combination function:

nCr = n!/(n-r)!r!

Note that n and r, while doubles, must actually be integer values and are calculated as such; any fractional component is discarded

Parameters:
n - number of items from which to select
r - length of combination sequence
Returns:
number of combinations C(n,r)
Throws:
StatisticException - if n < r or n < 0 or r < 0

summation

public static double summation(double[] values)
                        throws StatisticException
Sum of all the values in an array.

Parameters:
values - an array of doubles.
Returns:
sum of all elements in the array
Throws:
StatisticException - for an empty array

summation

public static double summation(long[] values)
                        throws StatisticException
Sum of all the values in an array.

Parameters:
values - an array of longs.
Returns:
sum of all elements in the array
Throws:
StatisticException - for an empty array