macroeco.models.nbinom

macroeco.models.nbinom = <macroeco.models._distributions.nbinom_gen object at 0x108653710>

A negative binomial discrete random variable.

This implementation of the negative binomial distribution differs from that in scipy.stats, as the distribution here uses the more common ecological parameterization.

\[P(x) = \frac{\gamma (k + x)}{\gamma(k) x!} \left(\frac{k}{k+\mu}\right)^k \left(\frac{\mu}{k+\mu}\right)^x\]

for x >= 0. In the traditional parameterization, n = k_agg (the size parameter) and p = k_agg / (k_agg + mu). the loc parameter is not used.

Parameters:

x : array_like

quantiles

q : array_like

lower or upper tail probability

mu, k_agg : array_like

shape parameters

loc : array_like, optional

location parameter (default=0)

size : int or tuple of ints, optional

shape of random variates (default computed from input arguments )

moments : str, optional

composed of letters [‘mvsk’] specifying which moments to compute where ‘m’ = mean, ‘v’ = variance, ‘s’ = (Fisher’s) skew and ‘k’ = (Fisher’s) kurtosis. (default=’mv’)

Alternatively, the object may be called (as a function) to fix the shape and :

location parameters returning a “frozen” discrete RV object: :

rv = nbinom(mu, k_agg, loc=0) :

  • Frozen RV object with the same methods but holding the given shape and location fixed.

mu : float

distribution mean

k_agg : float

clustering parameter

Examples

>>> import macroeco.models as md
>>> # Define a NBD distribution with mean = 10 and aggregation = 2
>>> nbd_dist = md.nbinom(mu=10, k_agg=2)
>>> # Get the pmf for some values
>>> nbd_dist.pmf(range(1, 10))
array([ 0.0462963 ,  0.05787037,  0.06430041,  0.0669796 ,  0.0669796 ,
    0.06511905,  0.06201814,  0.05814201,  0.05383519])
>>> # Get the cdf for some values
>>> nbd_dist.cdf(range(1, 10))
array([ 0.07407407,  0.13194444,  0.19624486,  0.26322445,  0.33020405,
    0.3953231 ,  0.45734124,  0.51548325,  0.56931845])
>>> # Get the logpmf using a different notation
>>> md.nbinom.logpmf(range(1, 10), 10, 2)
array([-3.07269331, -2.84954976, -2.74418925, -2.70336725, -2.70336725,
   -2.73153813, -2.78032829, -2.84486682, -2.92182786])
>>> # Get a random sample
>>> samp = md.nbinom.rvs(mu=10, k_agg=1, size=10)
>>> samp
array([12,  1,  4, 10, 23,  0, 12,  4,  1, 15])
>>> # Get the rank abundance distribution for n = 20
>>> rad = md.nbinom.rank(20, 10, 1)
>>> rad
array([  0.,   0.,   0.,   1.,   1.,   2.,   3.,   3.,   4.,   5.,   6.,
     7.,   9.,  10.,  12.,  14.,  17.,  20.,  26.,  37.])

Methods

rvs(mu, k_agg, loc=0, size=1) Random variates.
pmf(x, mu, k_agg, loc=0) Probability mass function.
logpmf(x, mu, k_agg, loc=0) Log of the probability mass function.
cdf(x, mu, k_agg, loc=0) Cumulative density function.
logcdf(x, mu, k_agg, loc=0) Log of the cumulative density function.
sf(x, mu, k_agg, loc=0) Survival function (1-cdf — sometimes more accurate).
logsf(x, mu, k_agg, loc=0) Log of the survival function.
ppf(q, mu, k_agg, loc=0) Percent point function (inverse of cdf — percentiles).
isf(q, mu, k_agg, loc=0) Inverse survival function (inverse of sf).
stats(mu, k_agg, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
entropy(mu, k_agg, loc=0) (Differential) entropy of the RV.
expect(func, mu, k_agg, loc=0, lb=None, ub=None, conditional=False) Expected value of a function (of one argument) with respect to the distribution.
median(mu, k_agg, loc=0) Median of the distribution.
mean(mu, k_agg, loc=0) Mean of the distribution.
var(mu, k_agg, loc=0) Variance of the distribution.
std(mu, k_agg, loc=0) Standard deviation of the distribution.
interval(alpha, mu, k_agg, loc=0) Endpoints of the range that contains alpha percent of the distribution