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)
>>> rad
array([  1.,   1.,   2.,   2.,   3.,   4.,   4.,   5.,   6.,   7.,   8.,
     9.,  10.,  11.,  13.,  15.,  17.,  20.,  25.,  36.])

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