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

Portabilityportable
Stabilityexperimental
Maintainerbos@serpentine.com
Safe HaskellNone

Statistics.Distribution

Contents

Description

Types classes for probability distrubutions

Synopsis

Type classes

class Distribution d whereSource

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

Methods

cumulative :: d -> Double -> DoubleSource

Cumulative distribution function. The probability that a random variable X is less or equal than x, i.e. P(Xx). Cumulative should be defined for infinities as well:

 cumulative d +∞ = 1
 cumulative d -∞ = 0

complCumulative :: d -> Double -> DoubleSource

One's complement of cumulative distibution:

 complCumulative d x = 1 - cumulative d x

It's useful when one is interested in P(X<x) and expression on the right side begin to lose precision. This function have default implementation but implementors are encouraged to provide more precise implementation.

class Distribution d => DiscreteDistr d whereSource

Discrete probability distribution.

Methods

probability :: d -> Int -> DoubleSource

Probability of n-th outcome.

logProbability :: d -> Int -> DoubleSource

Logarithm of probability of n-th outcome

class Distribution d => ContDistr d whereSource

Continuous probability distributuion.

Minimal complete definition is quantile and either density or logDensity.

Methods

density :: d -> Double -> DoubleSource

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

quantile :: d -> Double -> DoubleSource

Inverse of the cumulative distribution function. The value x for which P(Xx) = p. If probability is outside of [0,1] range function should call error

logDensity :: d -> Double -> DoubleSource

Natural logarithm of density.

Distribution statistics

class MaybeMean d => Mean d whereSource

Type class for distributions with mean. If distribution have finite mean for all valid values of parameters it should be instance of this type class.

Methods

mean :: d -> DoubleSource

class (Mean d, MaybeVariance d) => Variance d whereSource

Type class for distributions with variance. If distibution have finite variance for all valid parameter values it should be instance of this type class.

Minimal complete definition is variance or stdDev

class Distribution d => MaybeEntropy d whereSource

Type class for distributions with entropy, meaning Shannon entropy in the case of a discrete distribution, or differential entropy in the case of a continuous one. maybeEntropy should return Nothing if entropy is undefined for the chosen parameter values.

Methods

maybeEntropy :: d -> Maybe DoubleSource

Returns the entropy of a distribution, in nats, if such is defined.

class MaybeEntropy d => Entropy d whereSource

Type class for distributions with entropy, meaning Shannon entropy in the case of a discrete distribution, or differential entropy in the case of a continuous one. If the distribution has well-defined entropy for all valid parameter values then it should be an instance of this type class.

Methods

entropy :: d -> DoubleSource

Returns the entropy of a distribution, in nats.

Random number generation

class (DiscreteDistr d, ContGen d) => DiscreteGen d whereSource

Generate discrete random variates which have given distribution. ContGen is superclass because it's always possible to generate real-valued variates from integer values

Methods

genDiscreteVar :: PrimMonad m => d -> Gen (PrimState m) -> m IntSource

genContinous :: (ContDistr d, PrimMonad m) => d -> Gen (PrimState m) -> m DoubleSource

Generate variates from continous distribution using inverse transform rule.

Helper functions

findRootSource

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 -> DoubleSource

Sum probabilities in inclusive interval.