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

Statistics.Distribution

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 continuous 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 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
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.CauchyLorentz Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

class Distribution d => DiscreteDistr d where #

Discrete probability distribution.

Minimal complete definition

Nothing

Methods

probability :: d -> Int -> Double #

Probability of n-th outcome.

logProbability :: d -> Int -> Double #

Logarithm of probability of n-th outcome

Instances
 # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods

class Distribution d => ContDistr d where #

Continuous probability distribution.

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

complQuantile :: d -> Double -> Double #

1-complement of quantile:

complQuantile x ≡ quantile (1 - x)

logDensity :: d -> Double -> Double #

Natural logarithm of density.

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.CauchyLorentz Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

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

Methods

maybeMean :: d -> Maybe Double #

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

class MaybeMean d => Mean d where #

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 #

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods Mean d => Mean (LinearTransform d) # Instance detailsDefined in Statistics.Distribution.Transform Methods

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

Minimal complete definition

Nothing

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

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

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 #

stdDev :: d -> Double #

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

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.

Methods

maybeEntropy :: d -> Maybe Double #

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

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Gamma Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.CauchyLorentz Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

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.

Methods

entropy :: d -> Double #

Returns the entropy of a distribution, in nats.

Instances
 # Instance detailsDefined in Statistics.Distribution.Uniform Methods # Instance detailsDefined in Statistics.Distribution.StudentT Methods # Instance detailsDefined in Statistics.Distribution.Poisson Methods # Instance detailsDefined in Statistics.Distribution.Hypergeometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.Geometric Methods # Instance detailsDefined in Statistics.Distribution.FDistribution Methods # Instance detailsDefined in Statistics.Distribution.DiscreteUniform Methods # Instance detailsDefined in Statistics.Distribution.ChiSquared Methods # Instance detailsDefined in Statistics.Distribution.CauchyLorentz Methods # Instance detailsDefined in Statistics.Distribution.Binomial Methods # Instance detailsDefined in Statistics.Distribution.Beta Methods # Instance detailsDefined in Statistics.Distribution.Normal Methods # Instance detailsDefined in Statistics.Distribution.Laplace Methods # Instance detailsDefined in Statistics.Distribution.Exponential Methods # Instance detailsDefined in Statistics.Distribution.Transform Methods

class FromSample d a where #

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 #

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
 # 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 detailsDefined in Statistics.Distribution.Normal Methods # 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 detailsDefined in Statistics.Distribution.Laplace Methods # 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 detailsDefined in Statistics.Distribution.Exponential Methods

## Random number generation

class Distribution d => ContGen d where #

Generate discrete random variates which have given distribution.

Methods

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

Instances

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

Methods

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

Instances
 # Instance detailsDefined in Statistics.Distribution.Geometric MethodsgenDiscreteVar :: PrimMonad m => GeometricDistribution0 -> Gen (PrimState m) -> m Int # # Instance detailsDefined in Statistics.Distribution.Geometric MethodsgenDiscreteVar :: PrimMonad m => GeometricDistribution -> Gen (PrimState m) -> m Int #

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

Generate variates from continuous distribution using inverse transform rule.

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

Deprecated: Use genContinuous

Backwards compatibility with genContinuous.

# Helper functions

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.