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

Portability | portable
Stability | experimental
Maintainer | bos@serpentine.com

Statistics.Distribution

Contents

- Type classes
- Helper functions

Description

Types classes for probability distrubutions

Synopsis

- class Distribution d where
  - cumulative :: d -> Double -> Double
- class Distribution d => DiscreteDistr d where
  - probability :: d -> Int -> Double
- class Distribution d => ContDistr d where
  - density :: d -> Double -> Double
  - quantile :: d -> Double -> Double
- class Distribution d => Mean d where
  - mean :: d -> Double
- class Mean d => Variance d where
  - variance :: d -> Double
- findRoot :: ContDistr d => d -> Double -> Double -> Double -> Double -> Double
- sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> Double

# Type classes

class Distribution d where

Type class common to all distributions. Only c.d.f. could be defined for both discrete and continous distributions.

Methods

cumulative :: d -> Double -> Double

Cumulative distribution function. The probability that a random variable X is less or equal than x, i.e. P(X≤x).

Instances

Distribution GeometricDistribution |
Distribution ExponentialDistribution |
Distribution NormalDistribution |
Distribution BinomialDistribution |
Distribution ChiSquared |
Distribution GammaDistribution |
Distribution HypergeometricDistribution |
Distribution PoissonDistribution |

class Distribution d => DiscreteDistr d where

Discrete probability distribution.

Methods

probability :: d -> Int -> Double

Probability of n-th outcome.

Instances

DiscreteDistr GeometricDistribution |
DiscreteDistr BinomialDistribution |
DiscreteDistr HypergeometricDistribution |
DiscreteDistr PoissonDistribution |

class Distribution d => ContDistr d where

Continuous probability distributuion

Methods

density :: d -> Double -> Double

Probability density function. Probability that random variable X lies in the infinitesimal interval [x,x+δx) equal to density(x)⋅δx

quantile :: d -> Double -> Double

Inverse of the cumulative distribution function. The value x for which P(X≤x) = p.

Instances

ContDistr ExponentialDistribution |
ContDistr NormalDistribution |
ContDistr ChiSquared |
ContDistr GammaDistribution |

class Distribution d => Mean d where

Type class for distributions with mean.

Methods

mean :: d -> Double

Instances

Mean GeometricDistribution |
Mean ExponentialDistribution |
Mean NormalDistribution |
Mean BinomialDistribution |
Mean ChiSquared |
Mean GammaDistribution |
Mean HypergeometricDistribution |
Mean PoissonDistribution |

class Mean d => Variance d where

Type class for distributions with variance.

Methods

variance :: d -> Double

Instances

Variance GeometricDistribution |
Variance ExponentialDistribution |
Variance NormalDistribution |
Variance BinomialDistribution |
Variance ChiSquared |
Variance GammaDistribution |
Variance HypergeometricDistribution |
Variance PoissonDistribution |

# Helper functions

findRoot

Arguments

:: ContDistr d |
=> d | Distribution
-> Double | Probability p
-> Double | Initial guess
-> Double | Lower bound on interval
-> Double | Upper bound on interval
-> Double |

Approximate the value of X for which P(x>X)=p.

This method uses a combination of Newton-Raphson iteration and bisection with the given guess as a starting point. The upper and lower bounds specify the interval in which the probability distribution reaches the value p.

sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> Double

Sum probabilities in inclusive interval.