# macroeco.models.nbinom_ztrunc¶

macroeco.models.nbinom_ztrunc = <macroeco.models._distributions.nbinom_ztrunc_gen object at 0x108653290>

The zero-truncated negative binomial random variable.

This distribution is described by Sampford (1955) [1].

$P(x) = \frac{(k + x - 1)!}{(k - 1)!x!} \left(\frac{p} {1 + p}\right)^{x} \frac{1}{(1 + p)^{k - 1}}$

for x >= 1. p can be computed directly from the mean of the distribution and is calculated internally so that the distribution is parameterized by \mu and k_agg analogous to nbinom.

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_ztrunc(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

References

 [1] Sampford, M. R. (1955). The truncated negative binomial distribution. Biometrika, 42(1), 58-69

Examples

>>> import macroeco.models as md

>>> # Define a zero_truncated NBD distribution with mean = 10 and aggregation = 2
>>> nbd_dist = md.nbinom_ztrunc(mu=10, k_agg=2)

>>> # Get the pmf for some values
>>> nbd_dist.pmf(range(1, 10))
array([ 0.04984472,  0.06199534,  0.06854036,  0.07104033,  0.07068624,
0.06838018,  0.06479938,  0.06044661,  0.05569011])

>>> # Get the cdf for some values
>>> nbd_dist.cdf(range(1, 10))
array([ 0.04984472,  0.11184006,  0.18038041,  0.25142075,  0.32210698,
0.39048717,  0.45528654,  0.51573315,  0.57142326])

>>> # Get the logpmf using a different notation
>>> md.nbinom_ztrunc.logpmf(range(1, 10), 10, 2)
array([-2.99884273, -2.78069611, -2.68033253, -2.64450747, -2.64950441,
-2.68267222, -2.73645932, -2.80599478, -2.88795275])

>>> # Get and fit random sample
>>> samp = md.nbinom_ztrunc.rvs(mu=10, k_agg=1, size=100)
>>> md.nbinom_ztrunc.fit_mle(samp)
(10.210000000000001, 0.93369140625000113)

>>> # Get the rank abundance distribution for n = 20
>>> rad = md.nbinom_ztrunc.rank(20, 10, 1)