HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestatistics-0.16.3.0Haskell2010

Statistics.Distribution

Type classes for probability distributions

  • 12 classes
  • 3 values

Type classes

3 declarations
classclass Distribution d where
#

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

Methods

  • cumulative :: d -> Double -> Double

    Cumulative distribution function. The probability that a random variable X is less or equal than x, i.e. P(X≤x). 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.

Instances20Distribution, …
classclass Distribution d => DiscreteDistr d where
#

Discrete probability distribution.

Methods

Instances7DiscreteDistr, …
classclass Distribution d => ContDistr d where
#

Continuous probability distribution.

Minimal complete definition is quantile and either density or logDensity.

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

  • logDensity :: d -> Double -> Double

    Natural logarithm of density.

  • quantile :: d -> Double -> Double

    Inverse of the cumulative distribution function. The value x for which P(X≤x) = 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)
Instances13ContDistr, …

Distribution statistics

classclass 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

Instances19MaybeMean, …
classclass 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

Instances17Mean, …
classclass 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

Instances19MaybeVariance, …
classclass (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

Methods

Instances17Variance, …
classclass 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

Instances20MaybeEntropy, …
classclass 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.

Instances19Entropy, …
classclass 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 if there is not enough data, or if no usable fit results from the method used, e.g., the estimated distribution parameters would be invalid or inaccurate.

Instances5FromSample
  • FromSample ExponentialDistribution DoubleDefined in statistics-0.16.3.0 · Statistics.Distribution.Exponential

    Create exponential distribution from sample. Estimates the rate with the maximum likelihood estimator, which is biased. Returns Nothing if the sample mean does not exist or is not positive.

  • FromSample LaplaceDistribution DoubleDefined in statistics-0.16.3.0 · Statistics.Distribution.Laplace

    Create Laplace distribution from sample. The location is estimated as the median of the sample, and the scale as the mean absolute deviation of the median.

  • FromSample LognormalDistribution DoubleDefined in statistics-0.16.3.0 · Statistics.Distribution.Lognormal

    Variance is estimated using maximum likelihood method (biased estimation) over the log of the data.

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

  • FromSample NormalDistribution DoubleDefined in statistics-0.16.3.0 · Statistics.Distribution.Normal

    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)

  • FromSample WeibullDistribution DoubleDefined in statistics-0.16.3.0 · Statistics.Distribution.Weibull

    Uses an approximation based on the mean and standard deviation in weibullDistrEstMeanStddevErr, with standard deviation estimated using maximum likelihood method (unbiased estimation).

    Returns Nothing if sample contains less than one element or variance is zero (all elements are equal), or if the estimated mean and standard-deviation lies outside the range for which the approximation is accurate.

Random number generation

classclass Distribution d => ContGen d where
#

Generate discrete random variates which have given distribution.

Methods

Instances16ContGen, …
classclass (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

Instances3DiscreteGen

Helper functions

2 declarations
valuefindRoot
  1. :: ContDistr d
  2. => d

    Distribution

  3. -> Double

    Probability p

  4. -> Double

    Initial guess

  5. -> Double

    Lower bound on interval

  6. -> Double

    Upper bound on interval

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