bundles / scipy 1.17.1 / scipy / stats / _discrete_distns / nhypergeom_gen
class
scipy.stats._discrete_distns:nhypergeom_gen
Signature
class nhypergeom_gen ( a = 0 , b = inf , name = None , badvalue = None , moment_tol = 1e-08 , values = None , inc = 1 , longname = None , shapes = None , seed = None ) Members
Summary
A negative hypergeometric discrete random variable.
Extended Summary
Consider a box containing balls:, red and blue. We randomly sample balls from the box, one at a time and without replacement, until we have picked blue balls. nhypergeom is the distribution of the number of red balls we have picked.
%(before_notes)s
Notes
The symbols used to denote the shape parameters (M, n, and r) are not universally accepted. See the Examples for a clarification of the definitions used here.
The probability mass function is defined as,
for , , , and the binomial coefficient is:
It is equivalent to observing successes in samples with 'th sample being a failure. The former can be modelled as a hypergeometric distribution. The probability of the latter is simply the number of failures remaining divided by the size of the remaining population . This relationship can be shown as:
where is probability mass function (PMF) of the negative hypergeometric distribution and is the PMF of the hypergeometric distribution.
%(after_notes)s
Examples
import numpy as np from scipy.stats import nhypergeom import matplotlib.pyplot as plt✓
M, n, r = [20, 7, 12] rv = nhypergeom(M, n, r) x = np.arange(0, n+2) pmf_dogs = rv.pmf(x)✓
fig = plt.figure() ax = fig.add_subplot(111)✓
ax.plot(x, pmf_dogs, 'bo') ax.vlines(x, 0, pmf_dogs, lw=2) ax.set_xlabel('# of dogs in our group with given 12 failures') ax.set_ylabel('nhypergeom PMF')✗
plt.show()
✓
prb = nhypergeom.pmf(x, M, n, r)
✓R = nhypergeom.rvs(M, n, r, size=10)
✓from scipy.stats import hypergeom, nhypergeom M, n, r = 45, 13, 8 k = 6✓
nhypergeom.pmf(k, M, n, r) hypergeom.pmf(k, M, n, k+r-1) * (M - n - (r-1)) / (M - (k+r-1))✗
See also
- binom
- hypergeom
- nbinom
Aliases
-
scipy.stats._discrete_distns.nhypergeom_gen