algorithm for calculating PMF (default: BinomialAlgo.direct)
algorithm for poisson approximation (default: PoissonAlgo.gamma)
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));
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