macroeco.models.cnbinom

macroeco.models.cnbinom = <macroeco.models._distributions.cnbinom_gen object at 0x108653d10>

The conditional negative binomial random variable.

This distribution was described by Zillio and He (2010) [1] and Conlisk et al. (2007) [2]

\[P(x) = \frac{\binom{x + k - 1}{x} \binom{b - x + k/a - k -1}{b -x}}{\binom{b + k/a - 1}{b}}\]

for x >= 0. In this parameterization a = E[p(x)] / b where b is the upper limit of the distribution.

Parameters:

x : array_like

quantiles

q : array_like

lower or upper tail probability

mu, k_agg, b : 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 = cnbinom(mu, k_agg, b, 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 (refered to as k above)

b : float

Upper bound of distribution

References

[1]Zillio, T. & He, F. (2010). Modeling spatial aggregation of finite populations. Ecology, 91(12), 3698-3706
[2]Conlisk, E., Bloxham, M., Conlisk, J, Enquist, E., and Harte, J. (2007). A new class of models of spatial distribution. Ecological Monographs, 77(2), 269-284

Examples

>>> import macroeco.models as md
>>> # Define a conditional NBD distribution with mean = 10, agg = 2,
>>> # and an upper bound (b) = 300
>>> cnbd_dist = md.cnbinom(mu=10, k_agg=2, b=300)
>>> # Get the pmf for some values
>>> cnbd_dist.pmf(range(0, 10))
array([ 0.02662579,  0.04474923,  0.05637649,  0.06309932,  0.06617407,
    0.06658649,  0.06510469,  0.06232244,  0.05869438,  0.05456466])
>>> # Get the cdf for some values
>>> cnbd_dist.cdf(range(0, 10))
array([ 0.02662579,  0.07137502,  0.12775151,  0.19085083,  0.2570249 ,
    0.32361139,  0.38871607,  0.45103851,  0.50973289,  0.56429755])
>>> # Get the logpmf using a different notation
>>> md.cnbinom.logpmf(range(1, 10), 10, 2, 300)
array([-3.10668105, -2.8757031 , -2.76304533, -2.71546655, -2.7092536 ,
   -2.73175874, -2.7754338 , -2.83541131, -2.90836891])
>>> # Get and fit random sample
>>> samp = md.cnbinom.rvs(mu=10, k_agg=1, b=300, size=100)
>>> md.cnbinom.fit_mle(samp)
(11.640000000000001, 1.2000000000000002, 1164)
>>> # Be more specific about fit_mle
>>> md.cnbinom.fit_mle(samp, k_array=np.linspace(1, 1.5, num=1000))
(11.640000000000001, 1.1966966966966968, 1164)
>>> # Get the rank abundance distribution for n = 20
>>> rad = md.cnbinom.rank(20, 10, 1, 300)
>>> rad
array([  0.,   0.,   1.,   2.,   2.,   3.,   4.,   5.,   5.,   6.,   7.,
     9.,  10.,  11.,  13.,  15.,  18.,  21.,  26.,  37.])

Methods

rvs(mu, k_agg, b, loc=0, size=1) Random variates.
pmf(x, mu, k_agg, b, loc=0) Probability mass function.
logpmf(x, mu, k_agg, b, loc=0) Log of the probability mass function.
cdf(x, mu, k_agg, b, loc=0) Cumulative density function.
logcdf(x, mu, k_agg, b, loc=0) Log of the cumulative density function.
sf(x, mu, k_agg, b, loc=0) Survival function (1-cdf — sometimes more accurate).
logsf(x, mu, k_agg, b, loc=0) Log of the survival function.
ppf(q, mu, k_agg, b, loc=0) Percent point function (inverse of cdf — percentiles).
isf(q, mu, k_agg, b, loc=0) Inverse survival function (inverse of sf).
stats(mu, k_agg, b, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
entropy(mu, k_agg, b, loc=0) (Differential) entropy of the RV.
expect(func, mu, k_agg, b, 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, b, loc=0) Median of the distribution.
mean(mu, k_agg, b, loc=0) Mean of the distribution.
var(mu, k_agg, b, loc=0) Variance of the distribution.
std(mu, k_agg, b, loc=0) Standard deviation of the distribution.
interval(alpha, mu, k_agg, b, loc=0) Endpoints of the range that contains alpha percent of the distribution