statistics-0.16.4.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 Source #

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

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

Instances details

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

class Distribution d => DiscreteDistr d where Source #

Discrete probability distribution.

Minimal complete definition

(probability | logProbability)

Methods

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

Probability of n-th outcome.

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

Logarithm of probability of n-th outcome

#### Instances

Instances details

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

class Distribution d => ContDistr d where Source #

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

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

Natural logarithm of density.

quantile :: d -> Double -> Double Source #

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

1-complement of `quantile`:

    complQuantile x ≡ quantile (1 - x)

#### Instances

Instances details

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

Methods

maybeMean :: d -> Maybe Double Source #

#### Instances

Instances details

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

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

Instances details

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

Minimal complete definition

(maybeVariance | maybeStdDev)

Methods

maybeVariance :: d -> Maybe Double Source #

maybeStdDev :: d -> Maybe Double Source #

#### Instances

Instances details

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

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

(variance | stdDev)

Methods

variance :: d -> Double Source #

stdDev :: d -> Double Source #

#### Instances

Instances details

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

Methods

maybeEntropy :: d -> Maybe Double Source #

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

#### Instances

Instances details

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

Methods

entropy :: d -> Double Source #

Returns the entropy of a distribution, in nats.

#### Instances

Instances details

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

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` 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 Source # | 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 Source #
FromSample LaplaceDistribution Double Source # | 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 Source #
FromSample LognormalDistribution Double Source # | 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 Source #
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 Methods fromSample :: Vector v Double => v Double -> Maybe NormalDistribution Source #

FromSample WeibullDistribution Double Source #

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

## Random number generation

class Distribution d => ContGen d where Source #

Generate discrete random variates which have given distribution.

Methods

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

#### Instances

Instances details

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

Methods

genDiscreteVar :: StatefulGen g m => d -> g -> m Int Source #

#### Instances

Instances details

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

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

Generate variates from continuous distribution using inverse transform rule.

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