# 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)