The OpenD Programming Language

hypergeometricInvCDF

Computes the hypergeometric inverse cumulative distribution function (InvCDF).

Additional algorithms may be provided for calculating InvCDF that allow trading off time and accuracy. If approxPoisson is provided, PoissonAlgo.direct is assumed. This is different from other functions that use PoissonAlgo.gamma since in this case it does not provide the same result.

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

  1. size_t hypergeometricInvCDF(T p, size_t N, size_t K, size_t n)
  2. template hypergeometricInvCDF(T, string hypergeometricAlgo)
  3. template hypergeometricInvCDF(string hypergeometricAlgo)
    @safe pure nothrow @nogc
    template hypergeometricInvCDF (
    string hypergeometricAlgo
    )

Examples

import mir.test: should;

0.0.hypergeometricInvCDF(40, 15, 20).should == 0;
0.1.hypergeometricInvCDF(40, 15, 20).should == 6;
0.2.hypergeometricInvCDF(40, 15, 20).should == 6;
0.3.hypergeometricInvCDF(40, 15, 20).should == 7;
0.4.hypergeometricInvCDF(40, 15, 20).should == 7;
0.5.hypergeometricInvCDF(40, 15, 20).should == 7;
0.6.hypergeometricInvCDF(40, 15, 20).should == 8;
0.7.hypergeometricInvCDF(40, 15, 20).should == 8;
0.8.hypergeometricInvCDF(40, 15, 20).should == 9;
0.9.hypergeometricInvCDF(40, 15, 20).should == 9;
1.0.hypergeometricInvCDF(40, 15, 20).should == 15;

Alternate algorithms

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

// Can approximate hypergeometric with binomial distribution
0.5.hypergeometricInvCDF!"approxBinomial"(750_000, 250_000, 50).shouldApprox!double == 17;
// Can approximate hypergeometric with poisson distribution
0.4.hypergeometricInvCDF!"approxPoisson"(100_000, 100, 5_000).shouldApprox!double == 4;
// Can approximate hypergeometric with normal distribution
0.6.hypergeometricInvCDF!"approxNormal"(10_000, 7_500, 5_000).shouldApprox!double == 3755;
// Can approximate hypergeometric with normal distribution
0.6.hypergeometricInvCDF!"approxNormalContinuityCorrection"(10_000, 7_500, 5_000).shouldApprox!double(1) == 3755;

See Also

Meta