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.

  1. T hypergeometricCDF(size_t k, size_t N, size_t K, size_t n)
    @safe pure @nogc nothrow
    T
    hypergeometricCDF
    (
    const size_t k
    ,
    const size_t N
    ,
    const size_t K
    ,
    const size_t n
    )
    if (
    isFloatingPoint!T
    )
  2. template hypergeometricCDF(HypergeometricAlgo hypergeometricAlgo = HypergeometricAlgo.direct)
  3. template hypergeometricCDF(T, string hypergeometricAlgo)
  4. template hypergeometricCDF(string hypergeometricAlgo)

Parameters

k size_t

value to evaluate CDF (e.g. number of correct draws of object of interest)

N size_t

total population size

K size_t

number of relevant objects in population

n size_t

number of draws

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