The OpenD Programming Language

hypergeometricCCDF

Computes the hypergeometric complementary cumulative distribution function (CCDF).

Additional algorithms may be provided for calculating CCDF 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.

  1. T hypergeometricCCDF(size_t k, size_t N, size_t K, size_t n)
  2. template hypergeometricCCDF(HypergeometricAlgo hypergeometricAlgo = HypergeometricAlgo.direct)
    template hypergeometricCCDF (
    HypergeometricAlgo hypergeometricAlgo = HypergeometricAlgo.direct
    ) {}
  3. template hypergeometricCCDF(T, string hypergeometricAlgo)
  4. template hypergeometricCCDF(string hypergeometricAlgo)

Examples

import mir.test: shouldApprox;

0.hypergeometricCCDF(7, 4, 3).shouldApprox == 0.9714286;
1.hypergeometricCCDF(7, 4, 3).shouldApprox == 0.6285714;
2.hypergeometricCCDF(7, 4, 3).shouldApprox == 0.1142857;
3.hypergeometricCCDF(7, 4, 3).shouldApprox == 0.0;

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

Alternate algorithms

import mir.test: shouldApprox;
import mir.math.common: exp;

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

See Also

Meta