Fisher’s noncentral hypergeometric distribution

Preliminary version. The parameters may change.

mpsci.distributions.fishers_noncentral_hypergeometric.cdf(k, nc, ntotal, ngood, nsample)

CDF of Fisher’s noncentral hypergeometric distribution.

mpsci.distributions.fishers_noncentral_hypergeometric.mean(nc, ntotal, ngood, nsample)

Mean of Fisher’s noncentral hypergeometric distribution.

This calculation is implemented as a weighted sum over the support. It may be very slow for large parameters.

Returns:

m – The mean of the distribution.

Return type:

mpmath.mp.mpf

Examples

>>> from mpmath import mp
>>> from mpsci.distributions import fishers_noncentral_hypergeometric
>>> mp.dps = 24
>>> fishers_noncentral_hypergeometric.mean(2.5, 16, 8, 10)
mpf('5.89685838859408792634258808')
mpsci.distributions.fishers_noncentral_hypergeometric.mode(nc, ntotal, ngood, nsample)

Mode of Fisher’s noncentral hypergeometric distribution.

In cases where the maximum of the PMF occurs twice, the larger index of the two is returned.

Returns:

m – The mode of the distribution.

Return type:

mpmath.mp.mpf

Examples

>>> from mpsci.distributions import fishers_noncentral_hypergeometric
>>> fishers_noncentral_hypergeometric.mode(2.5, 16, 8, 10)
6

In this example, the PMF is symmetric about the mean, and the maximum value of the PMF occurs at k=3 and k=4. The value 4 is returned for the mode.

>>> fishers_noncentral_hypergeometric.support_pmf(1, 14, 7, 7)
(range(0, 8),
 [mpf('0.00029137529137529148'),
  mpf('0.014277389277389273'),
  mpf('0.12849650349650352'),
  mpf('0.35693473193473196'),
  mpf('0.35693473193473196'),
  mpf('0.12849650349650352'),
  mpf('0.014277389277389273'),
  mpf('0.00029137529137529148')])
>>> fishers_noncentral_hypergeometric.mode(1, 14, 7, 7)
4
mpsci.distributions.fishers_noncentral_hypergeometric.pmf(k, nc, ntotal, ngood, nsample)

PMF of Fisher’s noncentral hypergeometric distribution.

mpsci.distributions.fishers_noncentral_hypergeometric.sf(k, nc, ntotal, ngood, nsample)

Survival function of Fisher’s noncentral hypergeometric distribution.

mpsci.distributions.fishers_noncentral_hypergeometric.support(nc, ntotal, ngood, nsample)

Support for Fisher’s noncentral hypergeometric distribution.

The support of this distribution is the same as that of the hypergeometric distribution.

Returns:

sup – The range of integers in the support.

Return type:

range

mpsci.distributions.fishers_noncentral_hypergeometric.support_pmf(nc, ntotal, ngood, nsample)

Support and PMF values for Fisher’s noncentral hypergeometric distr.

Requires 0 < nc <\(\infty\).

The support of the distribution is \(k_{\textsf{min}} \le k \le k_{\textsf{max}}\), where

\[k_{\textsf{min}} = \textrm{max}(0, \textsf{nsample} - (\textsf{ntotal} - \textsf{ngood}))\]
\[k_{\textsf{max}} = \textrm{min}(\textsf{nsample}, \textsf{ngood}).\]

Let

\[c_k = \binom{\textsf{ngood}}{k}\binom{\textsf{ntotal} - \textsf{ngood}}{\textsf{nsample} - k}\textsf{nc}^{k}\]

The probability mass function is

\[p_k = \frac{c_k} {\sum_{j=k_{\textsf{min}}}^{k_{\textsf{max}}} c_j}\]
Returns:

  • sup (range) – The support of the distribution, represented as a Python range.

  • pmf (list) – The values of the probability mass function on the support.

Examples

>>> from mpmath import mp
>>> from mpsci.distributions import fishers_noncentral_hypergeometric
>>> mp.dps = 24
>>> sup, pmf = fishers_noncentral_hypergeometric(2.5, 16, 8, 10)
>>> sup
range(2, 9)
>>> pmf
[mpf('0.000147721056482530831000186887'),
 mpf('0.00590884225930123324000747648'),
 mpf('0.0646279622111072385625817892'),
 mpf('0.258511848844428954250327208'),
 mpf('0.403924763819420241016136111'),
 mpf('0.230814150753954423437792171'),
 mpf('0.0360647110553053786621550275')]