statistics-0.15.2.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 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 distribution:

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 UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

Distribution StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

Distribution PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

Distribution HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

Distribution GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Distribution GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Distribution GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

Distribution FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

Distribution DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

Distribution ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

Distribution CauchyDistribution Source # 
Instance details

Defined in Statistics.Distribution.CauchyLorentz

Distribution BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

Distribution BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

Distribution NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

Distribution LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

Distribution ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

Distribution d => Distribution (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

class Distribution d => DiscreteDistr d where Source #

Discrete probability distribution.

Minimal complete definition

Nothing

Methods

probability :: d -> Int -> Double Source #

Probability of n-th outcome.

logProbability :: d -> Int -> Double Source #

Logarithm of probability of n-th outcome

class Distribution d => ContDistr d where Source #

Continuous probability distribution.

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 UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

ContDistr StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

ContDistr GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

ContDistr FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

ContDistr ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

ContDistr CauchyDistribution Source # 
Instance details

Defined in Statistics.Distribution.CauchyLorentz

ContDistr BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

ContDistr NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

ContDistr LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

ContDistr ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

ContDistr d => ContDistr (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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

Methods

maybeMean :: d -> Maybe Double Source #

Instances
MaybeMean UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

MaybeMean StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

MaybeMean PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

MaybeMean HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

MaybeMean GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeMean GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeMean GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

MaybeMean FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

MaybeMean DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

MaybeMean ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

MaybeMean BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

MaybeMean BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

MaybeMean NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

MaybeMean LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

MaybeMean ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

MaybeMean d => MaybeMean (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

class MaybeMean d => Mean d where Source #

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

Methods

mean :: d -> Double Source #

Instances
Mean UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

Mean PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

Mean HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

Mean GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Mean GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Mean GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

Mean DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

Mean ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

Mean BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

Mean BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

Mean NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

Mean LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

Mean ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

Mean d => Mean (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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

Minimal complete definition

Nothing

Instances
MaybeVariance UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

MaybeVariance StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

MaybeVariance PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

MaybeVariance HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

MaybeVariance GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeVariance GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeVariance GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

MaybeVariance FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

MaybeVariance DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

MaybeVariance ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

MaybeVariance BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

MaybeVariance BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

MaybeVariance NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

MaybeVariance LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

MaybeVariance ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

MaybeVariance d => MaybeVariance (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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

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

Minimal complete definition is variance or stdDev

Minimal complete definition

Nothing

Methods

variance :: d -> Double Source #

stdDev :: d -> Double Source #

Instances
Variance UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

Variance PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

Variance HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

Variance GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Variance GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Variance GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

Variance DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

Variance ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

Variance BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

Variance BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

Variance NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

Variance LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

Variance ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

Variance d => Variance (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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.

Methods

maybeEntropy :: d -> Maybe Double Source #

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

Instances
MaybeEntropy UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

MaybeEntropy StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

MaybeEntropy PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

MaybeEntropy HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

MaybeEntropy GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeEntropy GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

MaybeEntropy GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

MaybeEntropy FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

MaybeEntropy DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

MaybeEntropy ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

MaybeEntropy CauchyDistribution Source # 
Instance details

Defined in Statistics.Distribution.CauchyLorentz

MaybeEntropy BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

MaybeEntropy BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

MaybeEntropy NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

MaybeEntropy LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

MaybeEntropy ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

MaybeEntropy d => MaybeEntropy (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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.

Methods

entropy :: d -> Double Source #

Returns the entropy of a distribution, in nats.

Instances
Entropy UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

Entropy StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

Entropy PoissonDistribution Source # 
Instance details

Defined in Statistics.Distribution.Poisson

Entropy HypergeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Hypergeometric

Entropy GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Entropy GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

Entropy FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

Entropy DiscreteUniform Source # 
Instance details

Defined in Statistics.Distribution.DiscreteUniform

Entropy ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

Entropy CauchyDistribution Source # 
Instance details

Defined in Statistics.Distribution.CauchyLorentz

Entropy BinomialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Binomial

Entropy BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

Entropy NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

Entropy LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

Entropy ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

Entropy d => Entropy (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

class FromSample d a where Source #

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

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

Instance details

Defined in Statistics.Distribution.Normal

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.

Instance details

Defined in Statistics.Distribution.Laplace

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.

Instance details

Defined in Statistics.Distribution.Exponential

Random number generation

class Distribution d => ContGen d where Source #

Generate discrete random variates which have given distribution.

Methods

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

Instances
ContGen UniformDistribution Source # 
Instance details

Defined in Statistics.Distribution.Uniform

ContGen StudentT Source # 
Instance details

Defined in Statistics.Distribution.StudentT

ContGen GeometricDistribution0 Source # 
Instance details

Defined in Statistics.Distribution.Geometric

ContGen GeometricDistribution Source # 
Instance details

Defined in Statistics.Distribution.Geometric

ContGen GammaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Gamma

ContGen FDistribution Source # 
Instance details

Defined in Statistics.Distribution.FDistribution

ContGen ChiSquared Source # 
Instance details

Defined in Statistics.Distribution.ChiSquared

ContGen CauchyDistribution Source # 
Instance details

Defined in Statistics.Distribution.CauchyLorentz

ContGen BetaDistribution Source # 
Instance details

Defined in Statistics.Distribution.Beta

ContGen NormalDistribution Source # 
Instance details

Defined in Statistics.Distribution.Normal

ContGen LaplaceDistribution Source # 
Instance details

Defined in Statistics.Distribution.Laplace

ContGen ExponentialDistribution Source # 
Instance details

Defined in Statistics.Distribution.Exponential

ContGen d => ContGen (LinearTransform d) Source # 
Instance details

Defined in Statistics.Distribution.Transform

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

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.