scipy.stats.hypergeom¶

scipy.stats.hypergeom()

A hypergeometric discrete random variable.

Discrete random variables are defined from a standard form and may require some shape parameters to complete its specification. Any optional keyword parameters can be passed to the methods of the RV object as given below:

Methods: hypergeom.rvs(M,n,N,loc=0,size=1) : random variates hypergeom.pmf(x,M,n,N,loc=0) : probability mass function hypergeom.cdf(x,M,n,N,loc=0) : cumulative density function hypergeom.sf(x,M,n,N,loc=0) : survival function (1-cdf — sometimes more accurate) hypergeom.ppf(q,M,n,N,loc=0) : percent point function (inverse of cdf — percentiles) hypergeom.isf(q,M,n,N,loc=0) : inverse survival function (inverse of sf) hypergeom.stats(M,n,N,loc=0,moments=’mv’) : mean(‘m’,axis=0), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) hypergeom.entropy(M,n,N,loc=0) : entropy of the RV Alternatively, the object may be called (as a function) to fix : the shape and location parameters returning a : “frozen” discrete RV object: : myrv = hypergeom(M,n,N,loc=0) : frozen RV object with the same methods but holding the given shape and location fixed. You can construct an aribtrary discrete rv where P{X=xk} = pk : by passing to the rv_discrete initialization method (through the values= : keyword) a tuple of sequences (xk,pk) which describes only those values of : X (xk) that occur with nonzero probability (pk). :

Examples

```>>> import matplotlib.pyplot as plt
>>> numargs = hypergeom.numargs
>>> [ M,n,N ] = ['Replace with resonable value',]*numargs
```

Display frozen pmf:

```>>> rv = hypergeom(M,n,N)
>>> x = np.arange(0,np.min(rv.dist.b,3)+1)
>>> h = plt.plot(x,rv.pmf(x))
```

Check accuracy of cdf and ppf:

```>>> prb = hypergeom.cdf(x,M,n,N)
>>> h = plt.semilogy(np.abs(x-hypergeom.ppf(prb,M,n,N))+1e-20)
```

Random number generation:

```>>> R = hypergeom.rvs(M,n,N,size=100)
```

```>>> vals = [arange(7),(0.1,0.2,0.3,0.1,0.1,0.1,0.1)]
>>> custm = rv_discrete(name='custm',values=vals)
>>> h = plt.plot(vals[0],custm.pmf(vals[0]))
```

Hypergeometric distribution

Models drawing objects from a bin. M is total number of objects, n is total number of Type I objects. RV counts number of Type I objects in N drawn without replacement from population.

hypergeom.pmf(k, M, n, N) = choose(n,k)*choose(M-n,N-k)/choose(M,N) for N - (M-n) <= k <= min(m,N)

scipy.stats.geom

Next topic

scipy.stats.logser