statistics-0.14.0.2: 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 Source #

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

Minimal complete definition

cumulative

Methods

cumulative :: d -> Double -> Double Source #

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

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 Source # 
Distribution BinomialDistribution Source # 
Distribution CauchyDistribution Source # 
Distribution ChiSquared Source # 
Distribution DiscreteUniform Source # 
Distribution ExponentialDistribution Source # 
Distribution FDistribution Source # 
Distribution GammaDistribution Source # 
Distribution GeometricDistribution0 Source # 
Distribution GeometricDistribution Source # 
Distribution HypergeometricDistribution Source # 
Distribution LaplaceDistribution Source # 
Distribution NormalDistribution Source # 
Distribution PoissonDistribution Source # 
Distribution StudentT Source # 
Distribution UniformDistribution Source # 
Distribution d => Distribution (LinearTransform d) Source # 

class Distribution d => ContDistr d where Source #

Continuous probability distributuion.

Minimal complete definition is quantile and either density or logDensity.

Minimal complete definition

quantile

Methods

density :: d -> Double -> Double Source #

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

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

complQuantile :: d -> Double -> Double Source #

1-complement of quantile:

complQuantile x ≡ quantile (1 - x)

logDensity :: d -> Double -> Double Source #

Natural logarithm of density.

Instances

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

Distribution statistics

class Distribution d => MaybeMean d where Source #

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

Instances

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

class MaybeMean d => Mean d where Source #

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

class MaybeMean d => MaybeVariance d where Source #

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 Source # 
MaybeVariance BinomialDistribution Source # 
MaybeVariance ChiSquared Source # 
MaybeVariance DiscreteUniform Source # 
MaybeVariance ExponentialDistribution Source # 
MaybeVariance FDistribution Source # 
MaybeVariance GammaDistribution Source # 
MaybeVariance GeometricDistribution0 Source # 
MaybeVariance GeometricDistribution Source # 
MaybeVariance HypergeometricDistribution Source # 
MaybeVariance LaplaceDistribution Source # 
MaybeVariance NormalDistribution Source # 
MaybeVariance PoissonDistribution Source # 
MaybeVariance StudentT Source # 
MaybeVariance UniformDistribution Source # 
MaybeVariance d => MaybeVariance (LinearTransform d) Source # 

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

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

stdDev :: d -> Double Source #

Instances

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

class Distribution d => MaybeEntropy d where Source #

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

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

Instances

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

class MaybeEntropy d => Entropy d where Source #

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

Returns the entropy of a distribution, in nats.

Instances

class FromSample d a where Source #

Estimate distribution from sample. First parameter in sample is distribution type and second is element type.

Minimal complete definition

fromSample

Methods

fromSample :: Vector v a => v a -> Maybe d Source #

Estimate distribution from sample. Returns nothing is there's not enough data to estimate or sample clearly doesn't come from distribution in question. For example if there's negative samples in exponential distribution.

Instances

FromSample ExponentialDistribution Double Source #

Create exponential distribution from sample. Returns Nothing if sample is empty or contains negative elements. No other tests are made to check whether it truly is exponential.

FromSample LaplaceDistribution Double Source #

Create Laplace distribution from sample. No tests are made to check whether it truly is Laplace. Location of distribution estimated as median of sample.

FromSample NormalDistribution Double Source #

Variance is estimated using maximum likelihood method (biased estimation).

Returns Nothing if sample contains less than one element or variance is zero (all elements are equal)

Random number generation

class Distribution d => ContGen d where Source #

Generate discrete random variates which have given distribution.

Minimal complete definition

genContVar

Methods

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

Instances

ContGen BetaDistribution Source # 
ContGen CauchyDistribution Source # 
ContGen ChiSquared Source # 
ContGen ExponentialDistribution Source # 
ContGen FDistribution Source # 
ContGen GammaDistribution Source # 
ContGen GeometricDistribution0 Source # 
ContGen GeometricDistribution Source # 
ContGen LaplaceDistribution Source # 
ContGen NormalDistribution Source # 
ContGen StudentT Source # 
ContGen UniformDistribution Source # 
ContGen d => ContGen (LinearTransform d) Source # 

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

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

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

Generate variates from continuous distribution using inverse transform rule.

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

Deprecated: Use genContinuous

Backwards compatibility with genContinuous.

Helper functions

findRoot Source #

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

Sum probabilities in inclusive interval.