The OpenD Programming Language

hypergeometricCDF

Computes the hypergeometric cumulative distribution function (CDF).

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

Setting hypergeometricAlgo = HypergeometricAlgo.direct results in direct summation being used, which can result in significant slowdowns for large values of k.

Examples

import mir.test: shouldApprox;

0.hypergeometricCDF(7, 4, 3).shouldApprox == 0.02857143;
1.hypergeometricCDF(7, 4, 3).shouldApprox == 0.3714286;
2.hypergeometricCDF(7, 4, 3).shouldApprox == 0.8857143;
3.hypergeometricCDF(7, 4, 3).shouldApprox == 1.0;

// can also provide a template argument to change output type
static assert(is(typeof(hypergeometricCDF!float(3, 7, 4, 3)) == float));

Alternate algorithms

import mir.test: shouldApprox;

// Can approximate hypergeometric with binomial distribution
20.hypergeometricCDF!"approxBinomial"(750_000, 250_000, 50).shouldApprox(1e-2) == 0.8740839;
// Can approximate hypergeometric with poisson distribution
8.hypergeometricCDF!"approxPoisson"(100_000, 100, 5_000).shouldApprox(1e-2) == 0.9370063;
// Can approximate hypergeometric with normal distribution
3_750.hypergeometricCDF!"approxNormal"(10_000, 7_500, 5_000).shouldApprox(2e-2) == 0.5092122;
// Can approximate hypergeometric with normal distribution
3_750.hypergeometricCDF!"approxNormalContinuityCorrection"(10_000, 7_500, 5_000).shouldApprox(1e-2) == 0.5092122;

See Also

Meta