statistics-0.8.0.5: A library of statistical types, data, and functions

Portabilityportable
Stabilityexperimental
Maintainerbos@serpentine.com

Statistics.Math

Contents

Description

Mathematical functions for statistics.

Synopsis

Functions

choose :: Int -> Int -> DoubleSource

Compute the binomial coefficient n `choose` k. For values of k > 30, this uses an approximation for performance reasons. The approximation is accurate to 12 decimal places in the worst case

Example:

 7 `choose` 3 == 35

Beta function

logBeta :: Double -> Double -> DoubleSource

Compute the natural logarithm of the beta function.

Chebyshev polynomials

A Chebyshev polynomial of the first kind is defined by the following recurrence:

 t 0 _ = 1
 t 1 x = x
 t n x = 2 * x * t (n-1) x - t (n-2) x

chebyshevSource

Arguments

:: Vector v Double 
=> Double

Parameter of each function.

-> v Double

Coefficients of each polynomial term, in increasing order.

-> Double 

Evaluate a Chebyshev polynomial of the first kind. Uses Clenshaw's algorithm.

chebyshevBrouckeSource

Arguments

:: Vector v Double 
=> Double

Parameter of each function.

-> v Double

Coefficients of each polynomial term, in increasing order.

-> Double 

Evaluate a Chebyshev polynomial of the first kind. Uses Broucke's ECHEB algorithm, and his convention for coefficient handling, and so gives different results than chebyshev for the same inputs.

Factorial

factorial :: Int -> DoubleSource

Compute the factorial function n!. Returns ∞ if the input is above 170 (above which the result cannot be represented by a 64-bit Double).

logFactorial :: Int -> DoubleSource

Compute the natural logarithm of the factorial function. Gives 16 decimal digits of precision.

Gamma function

incompleteGammaSource

Arguments

:: Double

s

-> Double

x

-> Double 

Compute the normalized lower incomplete gamma function γ(s,x). Normalization means that γ(s,∞)=1. Uses Algorithm AS 239 by Shea.

logGamma :: Double -> DoubleSource

Compute the logarithm of the gamma function Γ(x). Uses Algorithm AS 245 by Macleod.

Gives an accuracy of 10–12 significant decimal digits, except for small regions around x = 1 and x = 2, where the function goes to zero. For greater accuracy, use logGammaL.

Returns ∞ if the input is outside of the range (0 < x ≤ 1e305).

logGammaL :: Double -> DoubleSource

Compute the logarithm of the gamma function, Γ(x). Uses a Lanczos approximation.

This function is slower than logGamma, but gives 14 or more significant decimal digits of accuracy, except around x = 1 and x = 2, where the function goes to zero.

Returns ∞ if the input is outside of the range (0 < x ≤ 1e305).

Logarithm

log1p :: Double -> DoubleSource

Compute the natural logarithm of 1 + x. This is accurate even for values of x near zero, where use of log(1+x) would lose precision.

References

  • Broucke, R. (1973) Algorithm 446: Ten subroutines for the manipulation of Chebyshev series. Communications of the ACM 16(4):254–256. http://doi.acm.org/10.1145/362003.362037
  • Clenshaw, C.W. (1962) Chebyshev series for mathematical functions. National Physical Laboratory Mathematical Tables 5, Her Majesty's Stationery Office, London.
  • Lanczos, C. (1964) A precision approximation of the gamma function. SIAM Journal on Numerical Analysis B 1:86–96. http://www.jstor.org/stable/2949767
  • Macleod, A.J. (1989) Algorithm AS 245: A robust and reliable algorithm for the logarithm of the gamma function. Journal of the Royal Statistical Society, Series C (Applied Statistics) 38(2):397–402. http://www.jstor.org/stable/2348078
  • Shea, B. (1988) Algorithm AS 239: Chi-squared and incomplete gamma integral. Applied Statistics 37(3):466–473. http://www.jstor.org/stable/2347328