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

Copyright | (c) 2009 Bryan O'Sullivan
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Statistics.Distribution

Contents

- Type classes
  - Distribution statistics
  - Random number generation
- Helper functions

Description

Type classes for probability distributions

Synopsis

- class Distribution d where
  - cumulative :: d -> Double -> Double
  - complCumulative :: d -> Double -> Double
- class Distribution d => DiscreteDistr d where
  - probability :: d -> Int -> Double
  - logProbability :: d -> Int -> Double
- class Distribution d => ContDistr d where
  - density :: d -> Double -> Double
  - logDensity :: d -> Double -> Double
  - quantile :: d -> Double -> Double
  - complQuantile :: d -> Double -> Double
- class Distribution d => MaybeMean d where
  - maybeMean :: d -> Maybe Double
- class MaybeMean d => Mean d where
  - mean :: d -> Double
- class MaybeMean d => MaybeVariance d where
  - maybeVariance :: d -> Maybe Double
  - maybeStdDev :: d -> Maybe Double
- class (Mean d, MaybeVariance d) => Variance d where
  - variance :: d -> Double
  - stdDev :: d -> Double
- class Distribution d => MaybeEntropy d where
  - maybeEntropy :: d -> Maybe Double
- class MaybeEntropy d => Entropy d where
  - entropy :: d -> Double
- class FromSample d a where
  - fromSample :: Vector v a => v a -> Maybe d
- class Distribution d => ContGen d where
  - genContVar :: StatefulGen g m => d -> g -> m Double
- class (DiscreteDistr d, ContGen d) => DiscreteGen d where
  - genDiscreteVar :: StatefulGen g m => d -> g -> m Int
- genContinuous :: (ContDistr d, StatefulGen g m) => d -> g -> m Double
- findRoot :: ContDistr d => d -> Double -> Double -> Double -> Double -> Double
- sumProbabilities :: DiscreteDistr d => d -> Int -> Int -> Double

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

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.

#### Instances

Instances details

Distribution BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods cumulative :: BetaDistribution -> Double -> Double # complCumulative :: BetaDistribution -> Double -> Double #
Distribution BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods cumulative :: BinomialDistribution -> Double -> Double # complCumulative :: BinomialDistribution -> Double -> Double #
Distribution CauchyDistribution # |
Instance details Defined in Statistics.Distribution.CauchyLorentz Methods cumulative :: CauchyDistribution -> Double -> Double # complCumulative :: CauchyDistribution -> Double -> Double #
Distribution ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods cumulative :: ChiSquared -> Double -> Double # complCumulative :: ChiSquared -> Double -> Double #
Distribution DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods cumulative :: DiscreteUniform -> Double -> Double # complCumulative :: DiscreteUniform -> Double -> Double #
Distribution ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods cumulative :: ExponentialDistribution -> Double -> Double # complCumulative :: ExponentialDistribution -> Double -> Double #
Distribution FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods cumulative :: FDistribution -> Double -> Double # complCumulative :: FDistribution -> Double -> Double #
Distribution GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods cumulative :: GammaDistribution -> Double -> Double # complCumulative :: GammaDistribution -> Double -> Double #
Distribution GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods cumulative :: GeometricDistribution -> Double -> Double # complCumulative :: GeometricDistribution -> Double -> Double #
Distribution GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods cumulative :: GeometricDistribution0 -> Double -> Double # complCumulative :: GeometricDistribution0 -> Double -> Double #
Distribution HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods cumulative :: HypergeometricDistribution -> Double -> Double # complCumulative :: HypergeometricDistribution -> Double -> Double #
Distribution LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods cumulative :: LaplaceDistribution -> Double -> Double # complCumulative :: LaplaceDistribution -> Double -> Double #
Distribution LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods cumulative :: LognormalDistribution -> Double -> Double # complCumulative :: LognormalDistribution -> Double -> Double #
Distribution NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods cumulative :: NegativeBinomialDistribution -> Double -> Double # complCumulative :: NegativeBinomialDistribution -> Double -> Double #
Distribution NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods cumulative :: NormalDistribution -> Double -> Double # complCumulative :: NormalDistribution -> Double -> Double #
Distribution PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods cumulative :: PoissonDistribution -> Double -> Double # complCumulative :: PoissonDistribution -> Double -> Double #
Distribution StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods cumulative :: StudentT -> Double -> Double # complCumulative :: StudentT -> Double -> Double #
Distribution UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods cumulative :: UniformDistribution -> Double -> Double # complCumulative :: UniformDistribution -> Double -> Double #
Distribution WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods cumulative :: WeibullDistribution -> Double -> Double # complCumulative :: WeibullDistribution -> Double -> Double #
Distribution d => Distribution (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods cumulative :: LinearTransform d -> Double -> Double # complCumulative :: LinearTransform d -> Double -> Double #

class Distribution d => DiscreteDistr d where #

Discrete probability distribution.

Minimal complete definition

(probability | logProbability)

Methods

probability :: d -> Int -> Double #

Probability of n-th outcome.

logProbability :: d -> Int -> Double #

Logarithm of probability of n-th outcome

#### Instances

Instances details

DiscreteDistr BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods probability :: BinomialDistribution -> Int -> Double # logProbability :: BinomialDistribution -> Int -> Double #
DiscreteDistr DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods probability :: DiscreteUniform -> Int -> Double # logProbability :: DiscreteUniform -> Int -> Double #
DiscreteDistr GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods probability :: GeometricDistribution -> Int -> Double # logProbability :: GeometricDistribution -> Int -> Double #
DiscreteDistr GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods probability :: GeometricDistribution0 -> Int -> Double # logProbability :: GeometricDistribution0 -> Int -> Double #
DiscreteDistr HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods probability :: HypergeometricDistribution -> Int -> Double # logProbability :: HypergeometricDistribution -> Int -> Double #
DiscreteDistr NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods probability :: NegativeBinomialDistribution -> Int -> Double # logProbability :: NegativeBinomialDistribution -> Int -> Double #
DiscreteDistr PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods probability :: PoissonDistribution -> Int -> Double # logProbability :: PoissonDistribution -> Int -> Double #

class Distribution d => ContDistr d where #

Continuous probability distribution.

Minimal complete definition is `quantile` and either `density` or `logDensity`.

Minimal complete definition

(density | logDensity), (quantile | complQuantile)

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)

#### Instances

Instances details

ContDistr BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods density :: BetaDistribution -> Double -> Double # logDensity :: BetaDistribution -> Double -> Double # quantile :: BetaDistribution -> Double -> Double # complQuantile :: BetaDistribution -> Double -> Double #
ContDistr CauchyDistribution # |
Instance details Defined in Statistics.Distribution.CauchyLorentz Methods density :: CauchyDistribution -> Double -> Double # logDensity :: CauchyDistribution -> Double -> Double # quantile :: CauchyDistribution -> Double -> Double # complQuantile :: CauchyDistribution -> Double -> Double #
ContDistr ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods density :: ChiSquared -> Double -> Double # logDensity :: ChiSquared -> Double -> Double # quantile :: ChiSquared -> Double -> Double # complQuantile :: ChiSquared -> Double -> Double #
ContDistr ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods density :: ExponentialDistribution -> Double -> Double # logDensity :: ExponentialDistribution -> Double -> Double # quantile :: ExponentialDistribution -> Double -> Double # complQuantile :: ExponentialDistribution -> Double -> Double #
ContDistr FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods density :: FDistribution -> Double -> Double # logDensity :: FDistribution -> Double -> Double # quantile :: FDistribution -> Double -> Double # complQuantile :: FDistribution -> Double -> Double #
ContDistr GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods density :: GammaDistribution -> Double -> Double # logDensity :: GammaDistribution -> Double -> Double # quantile :: GammaDistribution -> Double -> Double # complQuantile :: GammaDistribution -> Double -> Double #
ContDistr LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods density :: LaplaceDistribution -> Double -> Double # logDensity :: LaplaceDistribution -> Double -> Double # quantile :: LaplaceDistribution -> Double -> Double # complQuantile :: LaplaceDistribution -> Double -> Double #
ContDistr LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods density :: LognormalDistribution -> Double -> Double # logDensity :: LognormalDistribution -> Double -> Double # quantile :: LognormalDistribution -> Double -> Double # complQuantile :: LognormalDistribution -> Double -> Double #
ContDistr NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods density :: NormalDistribution -> Double -> Double # logDensity :: NormalDistribution -> Double -> Double # quantile :: NormalDistribution -> Double -> Double # complQuantile :: NormalDistribution -> Double -> Double #
ContDistr StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods density :: StudentT -> Double -> Double # logDensity :: StudentT -> Double -> Double # quantile :: StudentT -> Double -> Double # complQuantile :: StudentT -> Double -> Double #
ContDistr UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods density :: UniformDistribution -> Double -> Double # logDensity :: UniformDistribution -> Double -> Double # quantile :: UniformDistribution -> Double -> Double # complQuantile :: UniformDistribution -> Double -> Double #
ContDistr WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods density :: WeibullDistribution -> Double -> Double # logDensity :: WeibullDistribution -> Double -> Double # quantile :: WeibullDistribution -> Double -> Double # complQuantile :: WeibullDistribution -> Double -> Double #
ContDistr d => ContDistr (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods density :: LinearTransform d -> Double -> Double # logDensity :: LinearTransform d -> Double -> Double # quantile :: LinearTransform d -> Double -> Double # complQuantile :: LinearTransform d -> Double -> Double #

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

Instances details

MaybeMean BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods maybeMean :: BetaDistribution -> Maybe Double #
MaybeMean BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods maybeMean :: BinomialDistribution -> Maybe Double #
MaybeMean ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods maybeMean :: ChiSquared -> Maybe Double #
MaybeMean DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods maybeMean :: DiscreteUniform -> Maybe Double #
MaybeMean ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods maybeMean :: ExponentialDistribution -> Maybe Double #
MaybeMean FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods maybeMean :: FDistribution -> Maybe Double #
MaybeMean GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods maybeMean :: GammaDistribution -> Maybe Double #
MaybeMean GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeMean :: GeometricDistribution -> Maybe Double #
MaybeMean GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeMean :: GeometricDistribution0 -> Maybe Double #
MaybeMean HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods maybeMean :: HypergeometricDistribution -> Maybe Double #
MaybeMean LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods maybeMean :: LaplaceDistribution -> Maybe Double #
MaybeMean LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods maybeMean :: LognormalDistribution -> Maybe Double #
MaybeMean NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods maybeMean :: NegativeBinomialDistribution -> Maybe Double #
MaybeMean NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods maybeMean :: NormalDistribution -> Maybe Double #
MaybeMean PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods maybeMean :: PoissonDistribution -> Maybe Double #
MaybeMean StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods maybeMean :: StudentT -> Maybe Double #
MaybeMean UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods maybeMean :: UniformDistribution -> Maybe Double #
MaybeMean WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods maybeMean :: WeibullDistribution -> Maybe Double #
MaybeMean d => MaybeMean (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods maybeMean :: LinearTransform d -> Maybe Double #

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

Instances details

Mean BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods mean :: BetaDistribution -> Double #
Mean BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods mean :: BinomialDistribution -> Double #
Mean ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods mean :: ChiSquared -> Double #
Mean DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods mean :: DiscreteUniform -> Double #
Mean ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods mean :: ExponentialDistribution -> Double #
Mean GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods mean :: GammaDistribution -> Double #
Mean GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods mean :: GeometricDistribution -> Double #
Mean GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods mean :: GeometricDistribution0 -> Double #
Mean HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods mean :: HypergeometricDistribution -> Double #
Mean LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods mean :: LaplaceDistribution -> Double #
Mean LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods mean :: LognormalDistribution -> Double #
Mean NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods mean :: NegativeBinomialDistribution -> Double #
Mean NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods mean :: NormalDistribution -> Double #
Mean PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods mean :: PoissonDistribution -> Double #
Mean UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods mean :: UniformDistribution -> Double #
Mean WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods mean :: WeibullDistribution -> Double #
Mean d => Mean (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods mean :: LinearTransform 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`

Minimal complete definition

(maybeVariance | maybeStdDev)

Methods

maybeVariance :: d -> Maybe Double #

maybeStdDev :: d -> Maybe Double #

#### Instances

Instances details

MaybeVariance BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods maybeVariance :: BetaDistribution -> Maybe Double # maybeStdDev :: BetaDistribution -> Maybe Double #
MaybeVariance BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods maybeVariance :: BinomialDistribution -> Maybe Double # maybeStdDev :: BinomialDistribution -> Maybe Double #
MaybeVariance ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods maybeVariance :: ChiSquared -> Maybe Double # maybeStdDev :: ChiSquared -> Maybe Double #
MaybeVariance DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods maybeVariance :: DiscreteUniform -> Maybe Double # maybeStdDev :: DiscreteUniform -> Maybe Double #
MaybeVariance ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods maybeVariance :: ExponentialDistribution -> Maybe Double # maybeStdDev :: ExponentialDistribution -> Maybe Double #
MaybeVariance FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods maybeVariance :: FDistribution -> Maybe Double # maybeStdDev :: FDistribution -> Maybe Double #
MaybeVariance GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods maybeVariance :: GammaDistribution -> Maybe Double # maybeStdDev :: GammaDistribution -> Maybe Double #
MaybeVariance GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeVariance :: GeometricDistribution -> Maybe Double # maybeStdDev :: GeometricDistribution -> Maybe Double #
MaybeVariance GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeVariance :: GeometricDistribution0 -> Maybe Double # maybeStdDev :: GeometricDistribution0 -> Maybe Double #
MaybeVariance HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods maybeVariance :: HypergeometricDistribution -> Maybe Double # maybeStdDev :: HypergeometricDistribution -> Maybe Double #
MaybeVariance LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods maybeVariance :: LaplaceDistribution -> Maybe Double # maybeStdDev :: LaplaceDistribution -> Maybe Double #
MaybeVariance LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods maybeVariance :: LognormalDistribution -> Maybe Double # maybeStdDev :: LognormalDistribution -> Maybe Double #
MaybeVariance NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods maybeVariance :: NegativeBinomialDistribution -> Maybe Double # maybeStdDev :: NegativeBinomialDistribution -> Maybe Double #
MaybeVariance NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods maybeVariance :: NormalDistribution -> Maybe Double # maybeStdDev :: NormalDistribution -> Maybe Double #
MaybeVariance PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods maybeVariance :: PoissonDistribution -> Maybe Double # maybeStdDev :: PoissonDistribution -> Maybe Double #
MaybeVariance StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods maybeVariance :: StudentT -> Maybe Double # maybeStdDev :: StudentT -> Maybe Double #
MaybeVariance UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods maybeVariance :: UniformDistribution -> Maybe Double # maybeStdDev :: UniformDistribution -> Maybe Double #
MaybeVariance WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods maybeVariance :: WeibullDistribution -> Maybe Double # maybeStdDev :: WeibullDistribution -> Maybe Double #
MaybeVariance d => MaybeVariance (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods maybeVariance :: LinearTransform d -> Maybe Double # maybeStdDev :: LinearTransform d -> Maybe Double #

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

(variance | stdDev)

Methods

variance :: d -> Double #

stdDev :: d -> Double #

#### Instances

Instances details

Variance BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods variance :: BetaDistribution -> Double # stdDev :: BetaDistribution -> Double #
Variance BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods variance :: BinomialDistribution -> Double # stdDev :: BinomialDistribution -> Double #
Variance ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods variance :: ChiSquared -> Double # stdDev :: ChiSquared -> Double #
Variance DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods variance :: DiscreteUniform -> Double # stdDev :: DiscreteUniform -> Double #
Variance ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods variance :: ExponentialDistribution -> Double # stdDev :: ExponentialDistribution -> Double #
Variance GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods variance :: GammaDistribution -> Double # stdDev :: GammaDistribution -> Double #
Variance GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods variance :: GeometricDistribution -> Double # stdDev :: GeometricDistribution -> Double #
Variance GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods variance :: GeometricDistribution0 -> Double # stdDev :: GeometricDistribution0 -> Double #
Variance HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods variance :: HypergeometricDistribution -> Double # stdDev :: HypergeometricDistribution -> Double #
Variance LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods variance :: LaplaceDistribution -> Double # stdDev :: LaplaceDistribution -> Double #
Variance LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods variance :: LognormalDistribution -> Double # stdDev :: LognormalDistribution -> Double #
Variance NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods variance :: NegativeBinomialDistribution -> Double # stdDev :: NegativeBinomialDistribution -> Double #
Variance NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods variance :: NormalDistribution -> Double # stdDev :: NormalDistribution -> Double #
Variance PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods variance :: PoissonDistribution -> Double # stdDev :: PoissonDistribution -> Double #
Variance UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods variance :: UniformDistribution -> Double # stdDev :: UniformDistribution -> Double #
Variance WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods variance :: WeibullDistribution -> Double # stdDev :: WeibullDistribution -> Double #
Variance d => Variance (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods variance :: LinearTransform d -> Double # stdDev :: LinearTransform d -> Double #

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

Instances details

MaybeEntropy BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods maybeEntropy :: BetaDistribution -> Maybe Double #
MaybeEntropy BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods maybeEntropy :: BinomialDistribution -> Maybe Double #
MaybeEntropy CauchyDistribution # |
Instance details Defined in Statistics.Distribution.CauchyLorentz Methods maybeEntropy :: CauchyDistribution -> Maybe Double #
MaybeEntropy ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods maybeEntropy :: ChiSquared -> Maybe Double #
MaybeEntropy DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods maybeEntropy :: DiscreteUniform -> Maybe Double #
MaybeEntropy ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods maybeEntropy :: ExponentialDistribution -> Maybe Double #
MaybeEntropy FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods maybeEntropy :: FDistribution -> Maybe Double #
MaybeEntropy GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods maybeEntropy :: GammaDistribution -> Maybe Double #
MaybeEntropy GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeEntropy :: GeometricDistribution -> Maybe Double #
MaybeEntropy GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods maybeEntropy :: GeometricDistribution0 -> Maybe Double #
MaybeEntropy HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods maybeEntropy :: HypergeometricDistribution -> Maybe Double #
MaybeEntropy LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods maybeEntropy :: LaplaceDistribution -> Maybe Double #
MaybeEntropy LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods maybeEntropy :: LognormalDistribution -> Maybe Double #
MaybeEntropy NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods maybeEntropy :: NegativeBinomialDistribution -> Maybe Double #
MaybeEntropy NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods maybeEntropy :: NormalDistribution -> Maybe Double #
MaybeEntropy PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods maybeEntropy :: PoissonDistribution -> Maybe Double #
MaybeEntropy StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods maybeEntropy :: StudentT -> Maybe Double #
MaybeEntropy UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods maybeEntropy :: UniformDistribution -> Maybe Double #
MaybeEntropy WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods maybeEntropy :: WeibullDistribution -> Maybe Double #
MaybeEntropy d => MaybeEntropy (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods maybeEntropy :: LinearTransform d -> Maybe Double #

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

Instances details

Entropy BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods entropy :: BetaDistribution -> Double #
Entropy BinomialDistribution # |
Instance details Defined in Statistics.Distribution.Binomial Methods entropy :: BinomialDistribution -> Double #
Entropy CauchyDistribution # |
Instance details Defined in Statistics.Distribution.CauchyLorentz Methods entropy :: CauchyDistribution -> Double #
Entropy ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods entropy :: ChiSquared -> Double #
Entropy DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods entropy :: DiscreteUniform -> Double #
Entropy ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods entropy :: ExponentialDistribution -> Double #
Entropy FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods entropy :: FDistribution -> Double #
Entropy GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods entropy :: GeometricDistribution -> Double #
Entropy GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods entropy :: GeometricDistribution0 -> Double #
Entropy HypergeometricDistribution # |
Instance details Defined in Statistics.Distribution.Hypergeometric Methods entropy :: HypergeometricDistribution -> Double #
Entropy LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods entropy :: LaplaceDistribution -> Double #
Entropy LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods entropy :: LognormalDistribution -> Double #
Entropy NegativeBinomialDistribution # |
Instance details Defined in Statistics.Distribution.NegativeBinomial Methods entropy :: NegativeBinomialDistribution -> Double #
Entropy NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods entropy :: NormalDistribution -> Double #
Entropy PoissonDistribution # |
Instance details Defined in Statistics.Distribution.Poisson Methods entropy :: PoissonDistribution -> Double #
Entropy StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods entropy :: StudentT -> Double #
Entropy UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods entropy :: UniformDistribution -> Double #
Entropy WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods entropy :: WeibullDistribution -> Double #
Entropy d => Entropy (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods entropy :: LinearTransform d -> Double #

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

#### Instances

Instances details

FromSample ExponentialDistribution Double # | 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.
Instance details Defined in Statistics.Distribution.Exponential Methods fromSample :: Vector v Double => v Double -> Maybe ExponentialDistribution #
FromSample LaplaceDistribution Double # | 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.
Instance details Defined in Statistics.Distribution.Laplace Methods fromSample :: Vector v Double => v Double -> Maybe LaplaceDistribution #
FromSample LognormalDistribution Double # | 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)
Instance details Defined in Statistics.Distribution.Lognormal Methods fromSample :: Vector v Double => v Double -> Maybe LognormalDistribution #
FromSample NormalDistribution Double # | 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 Methods fromSample :: Vector v Double => v Double -> Maybe NormalDistribution #
FromSample WeibullDistribution Double # | 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.
Instance details Defined in Statistics.Distribution.Weibull Methods fromSample :: Vector v Double => v Double -> Maybe WeibullDistribution #

## Random number generation

class Distribution d => ContGen d where #

Generate discrete random variates which have given distribution.

Methods

genContVar :: StatefulGen g m => d -> g -> m Double #

#### Instances

Instances details

ContGen BetaDistribution # |
Instance details Defined in Statistics.Distribution.Beta Methods genContVar :: StatefulGen g m => BetaDistribution -> g -> m Double #
ContGen CauchyDistribution # |
Instance details Defined in Statistics.Distribution.CauchyLorentz Methods genContVar :: StatefulGen g m => CauchyDistribution -> g -> m Double #
ContGen ChiSquared # |
Instance details Defined in Statistics.Distribution.ChiSquared Methods genContVar :: StatefulGen g m => ChiSquared -> g -> m Double #
ContGen DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods genContVar :: StatefulGen g m => DiscreteUniform -> g -> m Double #
ContGen ExponentialDistribution # |
Instance details Defined in Statistics.Distribution.Exponential Methods genContVar :: StatefulGen g m => ExponentialDistribution -> g -> m Double #
ContGen FDistribution # |
Instance details Defined in Statistics.Distribution.FDistribution Methods genContVar :: StatefulGen g m => FDistribution -> g -> m Double #
ContGen GammaDistribution # |
Instance details Defined in Statistics.Distribution.Gamma Methods genContVar :: StatefulGen g m => GammaDistribution -> g -> m Double #
ContGen GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods genContVar :: StatefulGen g m => GeometricDistribution -> g -> m Double #
ContGen GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods genContVar :: StatefulGen g m => GeometricDistribution0 -> g -> m Double #
ContGen LaplaceDistribution # |
Instance details Defined in Statistics.Distribution.Laplace Methods genContVar :: StatefulGen g m => LaplaceDistribution -> g -> m Double #
ContGen LognormalDistribution # |
Instance details Defined in Statistics.Distribution.Lognormal Methods genContVar :: StatefulGen g m => LognormalDistribution -> g -> m Double #
ContGen NormalDistribution # |
Instance details Defined in Statistics.Distribution.Normal Methods genContVar :: StatefulGen g m => NormalDistribution -> g -> m Double #
ContGen StudentT # |
Instance details Defined in Statistics.Distribution.StudentT Methods genContVar :: StatefulGen g m => StudentT -> g -> m Double #
ContGen UniformDistribution # |
Instance details Defined in Statistics.Distribution.Uniform Methods genContVar :: StatefulGen g m => UniformDistribution -> g -> m Double #
ContGen WeibullDistribution # |
Instance details Defined in Statistics.Distribution.Weibull Methods genContVar :: StatefulGen g m => WeibullDistribution -> g -> m Double #
ContGen d => ContGen (LinearTransform d) # |
Instance details Defined in Statistics.Distribution.Transform Methods genContVar :: StatefulGen g m => LinearTransform d -> g -> m Double #

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 :: StatefulGen g m => d -> g -> m Int #

#### Instances

Instances details

DiscreteGen DiscreteUniform # |
Instance details Defined in Statistics.Distribution.DiscreteUniform Methods genDiscreteVar :: StatefulGen g m => DiscreteUniform -> g -> m Int #
DiscreteGen GeometricDistribution # |
Instance details Defined in Statistics.Distribution.Geometric Methods genDiscreteVar :: StatefulGen g m => GeometricDistribution -> g -> m Int #
DiscreteGen GeometricDistribution0 # |
Instance details Defined in Statistics.Distribution.Geometric Methods genDiscreteVar :: StatefulGen g m => GeometricDistribution0 -> g -> m Int #

genContinuous :: (ContDistr d, StatefulGen g m) => d -> g -> m Double #

Generate variates from continuous 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.