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

Copyright(c) 2009 Bryan O'Sullivan
LicenseBSD3
Maintainerbos@serpentine.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Statistics.Distribution

Contents

Description

Type classes for probability distributions

Synopsis

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.

Minimal complete definition

cumulative

Methods

cumulative :: d -> Double -> Double #

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 -> Double #

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.

Instances

Distribution BetaDistribution # 
Distribution BinomialDistribution # 
Distribution CauchyDistribution # 
Distribution ChiSquared # 
Distribution ExponentialDistribution # 
Distribution FDistribution # 
Distribution GammaDistribution # 
Distribution GeometricDistribution0 # 
Distribution GeometricDistribution # 
Distribution HypergeometricDistribution # 
Distribution LaplaceDistribution # 
Distribution NormalDistribution # 
Distribution PoissonDistribution # 
Distribution StudentT # 
Distribution UniformDistribution # 
Distribution d => Distribution (LinearTransform d) # 

class Distribution d => ContDistr d where #

Continuous probability distributuion.

Minimal complete definition is quantile and either density or logDensity.

Minimal complete definition

quantile

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(Xx) = p. If probability is outside of [0,1] range function should call error

logDensity :: d -> Double -> Double #

Natural logarithm of density.

Instances

ContDistr BetaDistribution # 
ContDistr CauchyDistribution # 
ContDistr ChiSquared # 
ContDistr ExponentialDistribution # 
ContDistr FDistribution # 
ContDistr GammaDistribution # 
ContDistr LaplaceDistribution # 
ContDistr NormalDistribution # 
ContDistr StudentT # 
ContDistr UniformDistribution # 
ContDistr d => ContDistr (LinearTransform d) # 

Distribution statistics

class Distribution d => MaybeMean d where #

Type class for distributions with mean. maybeMean should return Nothing if it's undefined for current value of data

Minimal complete definition

maybeMean

Methods

maybeMean :: d -> Maybe Double #

class MaybeMean d => Mean d where #

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.

Minimal complete definition

mean

Methods

mean :: d -> Double #

class MaybeMean d => MaybeVariance d where #

Type class for distributions with variance. If variance is undefined for some parameter values both maybeVariance and maybeStdDev should return Nothing.

Minimal complete definition is maybeVariance or maybeStdDev

Instances

MaybeVariance BetaDistribution # 
MaybeVariance BinomialDistribution # 
MaybeVariance ChiSquared # 
MaybeVariance ExponentialDistribution # 
MaybeVariance FDistribution # 
MaybeVariance GammaDistribution # 
MaybeVariance GeometricDistribution0 # 
MaybeVariance GeometricDistribution # 
MaybeVariance HypergeometricDistribution # 
MaybeVariance LaplaceDistribution # 
MaybeVariance NormalDistribution # 
MaybeVariance PoissonDistribution # 
MaybeVariance StudentT # 
MaybeVariance UniformDistribution # 
MaybeVariance d => MaybeVariance (LinearTransform d) # 

class (Mean d, MaybeVariance d) => Variance d where #

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

Methods

variance :: d -> Double #

stdDev :: d -> Double #

Instances

Variance BetaDistribution # 
Variance BinomialDistribution # 
Variance ChiSquared # 
Variance ExponentialDistribution # 
Variance GammaDistribution # 
Variance GeometricDistribution0 # 
Variance GeometricDistribution # 
Variance HypergeometricDistribution # 
Variance LaplaceDistribution # 
Variance NormalDistribution # 
Variance PoissonDistribution # 
Variance UniformDistribution # 
Variance d => Variance (LinearTransform d) # 

class Distribution d => MaybeEntropy d where #

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.

Minimal complete definition

maybeEntropy

Methods

maybeEntropy :: d -> Maybe Double #

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

Instances

MaybeEntropy BetaDistribution # 
MaybeEntropy BinomialDistribution # 
MaybeEntropy CauchyDistribution # 
MaybeEntropy ChiSquared # 
MaybeEntropy ExponentialDistribution # 
MaybeEntropy FDistribution # 
MaybeEntropy GammaDistribution # 
MaybeEntropy GeometricDistribution0 # 
MaybeEntropy GeometricDistribution # 
MaybeEntropy HypergeometricDistribution # 
MaybeEntropy LaplaceDistribution # 
MaybeEntropy NormalDistribution # 
MaybeEntropy PoissonDistribution # 
MaybeEntropy StudentT # 
MaybeEntropy UniformDistribution # 
(MaybeEntropy d, DiscreteDistr d) => MaybeEntropy (LinearTransform d) # 

class MaybeEntropy d => Entropy d where #

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.

Minimal complete definition

entropy

Methods

entropy :: d -> Double #

Returns the entropy of a distribution, in nats.

Random number generation

class Distribution d => ContGen d where #

Generate discrete random variates which have given distribution.

Minimal complete definition

genContVar

Methods

genContVar :: PrimMonad m => d -> Gen (PrimState m) -> m Double #

Instances

ContGen BetaDistribution # 
ContGen CauchyDistribution # 
ContGen ChiSquared # 

Methods

genContVar :: PrimMonad m => ChiSquared -> Gen (PrimState m) -> m Double #

ContGen ExponentialDistribution # 
ContGen FDistribution # 
ContGen GammaDistribution # 
ContGen GeometricDistribution0 # 
ContGen GeometricDistribution # 
ContGen LaplaceDistribution # 
ContGen NormalDistribution # 
ContGen StudentT # 

Methods

genContVar :: PrimMonad m => StudentT -> Gen (PrimState m) -> m Double #

ContGen UniformDistribution # 
ContGen d => ContGen (LinearTransform d) # 

class (DiscreteDistr d, ContGen d) => DiscreteGen d where #

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

Minimal complete definition

genDiscreteVar

Methods

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

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

Generate variates from continous distribution using inverse transform rule.

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.