stats._discrete_distns

Module Contents

Classes

binom_gen() A binomial discrete random variable.
bernoulli_gen() A Bernoulli discrete random variable.
nbinom_gen() A negative binomial discrete random variable.
geom_gen() A geometric discrete random variable.
hypergeom_gen() rA hypergeometric discrete random variable.
logser_gen() A Logarithmic (Log-Series, Series) discrete random variable.
poisson_gen() A Poisson discrete random variable.
planck_gen() A Planck discrete exponential random variable.
boltzmann_gen() A Boltzmann (Truncated Discrete Exponential) random variable.
randint_gen() A uniform discrete random variable.
zipf_gen() A Zipf discrete random variable.
dlaplace_gen() A Laplacian discrete random variable.
skellam_gen() A Skellam discrete random variable.
class binom_gen

A binomial discrete random variable.

%(before_notes)s

The probability mass function for binom is:

binom.pmf(k) = choose(n, k) * p**k * (1-p)**(n-k)

for k in {0, 1,..., n}.

binom takes n and p as shape parameters.

%(after_notes)s

%(example)s

_rvs(n, p)
_argcheck(n, p)
_logpmf(x, n, p)
_pmf(x, n, p)
_cdf(x, n, p)
_sf(x, n, p)
_ppf(q, n, p)
_stats(n, p, moments="mv")
_entropy(n, p)
class bernoulli_gen

A Bernoulli discrete random variable.

%(before_notes)s

The probability mass function for bernoulli is:

bernoulli.pmf(k) = 1-p  if k = 0
                 = p    if k = 1

for k in {0, 1}.

bernoulli takes p as shape parameter.

%(after_notes)s

%(example)s

_rvs(p)
_argcheck(p)
_logpmf(x, p)
_pmf(x, p)
_cdf(x, p)
_sf(x, p)
_ppf(q, p)
_stats(p)
_entropy(p)
class nbinom_gen

A negative binomial discrete random variable.

%(before_notes)s

Negative binomial distribution describes a sequence of i.i.d. Bernoulli trials, repeated until a predefined, non-random number of successes occurs.

The probability mass function of the number of failures for nbinom is:

nbinom.pmf(k) = choose(k+n-1, n-1) * p**n * (1-p)**k

for k >= 0.

nbinom takes n and p as shape parameters where n is the number of successes, whereas p is the probability of a single success.

%(after_notes)s

%(example)s

_rvs(n, p)
_argcheck(n, p)
_pmf(x, n, p)
_logpmf(x, n, p)
_cdf(x, n, p)
_sf_skip(x, n, p)
_ppf(q, n, p)
_stats(n, p)
class geom_gen

A geometric discrete random variable.

%(before_notes)s

The probability mass function for geom is:

geom.pmf(k) = (1-p)**(k-1)*p

for k >= 1.

geom takes p as shape parameter.

%(after_notes)s

%(example)s

_rvs(p)
_argcheck(p)
_pmf(k, p)
_logpmf(k, p)
_cdf(x, p)
_sf(x, p)
_logsf(x, p)
_ppf(q, p)
_stats(p)
class hypergeom_gen

rA hypergeometric discrete random variable.

The hypergeometric distribution models drawing objects from a bin. M is the total number of objects, n is total number of Type I objects. The random variate represents the number of Type I objects in N drawn without replacement from the total population.

%(before_notes)s

The symbols used to denote the shape parameters (M, n, and N) are not universally accepted. See the Examples for a clarification of the definitions used here.

The probability mass function is defined as,

for , where the binomial coefficients are defined as,

%(after_notes)s

>>> from scipy.stats import hypergeom
>>> import matplotlib.pyplot as plt

Suppose we have a collection of 20 animals, of which 7 are dogs. Then if we want to know the probability of finding a given number of dogs if we choose at random 12 of the 20 animals, we can initialize a frozen distribution and plot the probability mass function:

>>> [M, n, N] = [20, 7, 12]
>>> rv = hypergeom(M, n, N)
>>> x = np.arange(0, n+1)
>>> 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 of chosen animals')
>>> ax.set_ylabel('hypergeom PMF')
>>> plt.show()

Instead of using a frozen distribution we can also use hypergeom methods directly. To for example obtain the cumulative distribution function, use:

>>> prb = hypergeom.cdf(x, M, n, N)

And to generate random numbers:

>>> R = hypergeom.rvs(M, n, N, size=10)
_rvs(M, n, N)
_argcheck(M, n, N)
_logpmf(k, M, n, N)
_pmf(k, M, n, N)
_stats(M, n, N)
_entropy(M, n, N)
_sf(k, M, n, N)

More precise calculation, 1 - cdf doesn’t cut it.

_logsf(k, M, n, N)

More precise calculation than log(sf)

class logser_gen

A Logarithmic (Log-Series, Series) discrete random variable.

%(before_notes)s

The probability mass function for logser is:

logser.pmf(k) = - p**k / (k*log(1-p))

for k >= 1.

logser takes p as shape parameter.

%(after_notes)s

%(example)s

_rvs(p)
_argcheck(p)
_pmf(k, p)
_stats(p)
class poisson_gen

A Poisson discrete random variable.

%(before_notes)s

The probability mass function for poisson is:

poisson.pmf(k) = exp(-mu) * mu**k / k!

for k >= 0.

poisson takes mu as shape parameter.

%(after_notes)s

%(example)s

_argcheck(mu)
_rvs(mu)
_logpmf(k, mu)
_pmf(k, mu)
_cdf(x, mu)
_sf(x, mu)
_ppf(q, mu)
_stats(mu)
class planck_gen

A Planck discrete exponential random variable.

%(before_notes)s

The probability mass function for planck is:

planck.pmf(k) = (1-exp(-lambda_))*exp(-lambda_*k)

for k*lambda_ >= 0.

planck takes lambda_ as shape parameter.

%(after_notes)s

%(example)s

_argcheck(lambda_)
_pmf(k, lambda_)
_cdf(x, lambda_)
_sf(x, lambda_)
_logsf(x, lambda_)
_ppf(q, lambda_)
_stats(lambda_)
_entropy(lambda_)
class boltzmann_gen

A Boltzmann (Truncated Discrete Exponential) random variable.

%(before_notes)s

The probability mass function for boltzmann is:

boltzmann.pmf(k) = (1-exp(-lambda_)*exp(-lambda_*k)/(1-exp(-lambda_*N))

for k = 0,..., N-1.

boltzmann takes lambda_ and N as shape parameters.

%(after_notes)s

%(example)s

_pmf(k, lambda_, N)
_cdf(x, lambda_, N)
_ppf(q, lambda_, N)
_stats(lambda_, N)
class randint_gen

A uniform discrete random variable.

%(before_notes)s

The probability mass function for randint is:

randint.pmf(k) = 1./(high - low)

for k = low, ..., high - 1.

randint takes low and high as shape parameters.

%(after_notes)s

%(example)s

_argcheck(low, high)
_pmf(k, low, high)
_cdf(x, low, high)
_ppf(q, low, high)
_stats(low, high)
_rvs(low, high)

An array of size random integers >= low and < high.

_entropy(low, high)
class zipf_gen

A Zipf discrete random variable.

%(before_notes)s

The probability mass function for zipf is:

zipf.pmf(k, a) = 1/(zeta(a) * k**a)

for k >= 1.

zipf takes a as shape parameter.

%(after_notes)s

%(example)s

_rvs(a)
_argcheck(a)
_pmf(k, a)
_munp(n, a)
class dlaplace_gen

A Laplacian discrete random variable.

%(before_notes)s

The probability mass function for dlaplace is:

dlaplace.pmf(k) = tanh(a/2) * exp(-a*abs(k))

for a > 0.

dlaplace takes a as shape parameter.

%(after_notes)s

%(example)s

_pmf(k, a)
_cdf(x, a)
_ppf(q, a)
_stats(a)
_entropy(a)
class skellam_gen

A Skellam discrete random variable.

%(before_notes)s

Probability distribution of the difference of two correlated or uncorrelated Poisson random variables.

Let k1 and k2 be two Poisson-distributed r.v. with expected values lam1 and lam2. Then, k1 - k2 follows a Skellam distribution with parameters mu1 = lam1 - rho*sqrt(lam1*lam2) and mu2 = lam2 - rho*sqrt(lam1*lam2), where rho is the correlation coefficient between k1 and k2. If the two Poisson-distributed r.v. are independent then rho = 0.

Parameters mu1 and mu2 must be strictly positive.

For details see: http://en.wikipedia.org/wiki/Skellam_distribution

skellam takes mu1 and mu2 as shape parameters.

%(after_notes)s

%(example)s

_rvs(mu1, mu2)
_pmf(x, mu1, mu2)
_cdf(x, mu1, mu2)
_stats(mu1, mu2)