The OpenD Programming Language

binomialPMF

Computes the binomial probability mass function (PMF).

Additional algorithms may be provided for calculating PMF that allow trading off time and accuracy. If approxPoisson is provided, the default is PoissonAlgo.gamma

  1. T binomialPMF(size_t k, size_t n, T p)
    template binomialPMF(BinomialAlgo binomialAlgo = BinomialAlgo.direct, PoissonAlgo poissonAlgo = PoissonAlgo.gamma)
    @safe pure nothrow @nogc
    T
    binomialPMF
    (
    T
    )
    (
    const size_t k
    ,
    const size_t n
    ,
    const T p
    )
    if (
    isFloatingPoint!T
    )
  2. template binomialPMF(string binomialAlgo, string poissonAlgo = "gamma")

Members

Functions

binomialPMF
T binomialPMF(size_t k, size_t n, T p)

Parameters

binomialAlgo

algorithm for calculating PMF (default: BinomialAlgo.direct)

poissonAlgo

algorithm for poisson approximation (default: PoissonAlgo.gamma)

Examples

import mir.math.common: approxEqual, pow;

assert(4.binomialPMF(6, 2.0 / 3).approxEqual(15.0 * pow(2.0 / 3, 4) * pow(1.0 / 3, 2)));
// For large values of `n` with `p` not too extreme, can approximate with normal distribution
assert(550_000.binomialPMF!"approxNormal"(1_000_000, 0.55).approxEqual(0.0008019042));
// Or closer with continuity correction
assert(550_000.binomialPMF!"approxNormalContinuityCorrection"(1_000_000, 0.55).approxEqual(0.000801904));
// Poisson approximation is better when `p` is low
assert(10_000.binomialPMF!"approxPoisson"(1_000_000, 0.01).approxEqual(0.00398939));

See Also

Meta