macroeco.models.dgamma¶
- macroeco.models.dgamma = <macroeco.models._distributions.dgamma_gen object at 0x108653850>¶
A discrete gamma random variable.
\[P(x) = k * x^{(\alpha - 1)} * e^{(-1 / \theta)*x}\]for x >= 1, \theta > 0. k is the normalizing constant. \alpha is analogous to the k_{agg} parameter in the zero-truncated negative binomial.
Parameters: x : array_like
quantiles
q : array_like
lower or upper tail probability
alpha, theta : 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 = dgamma(alpha, theta, loc=0) :
- Frozen RV object with the same methods but holding the given shape and location fixed.
alpha : float
distribution parameter
theta : float
distribution parameter
Notes
This parameterization of the discrete gamma was taken from [1].
References
[1] Frank, F. (2011). Measurement scale in maximum entropy models of species abundance. Journal of Evolutionary Biology, 24(3), 485-496 Examples
>>> import macroeco.models as md
>>> # dgamma takes two parameters >>> dgamma_dist = md.dgamma(alpha=1, theta=2)
>>> # When alpha = 1 and theta = 2, should be similar to a to >>> # zero_truncated NBD with mu = 2.541. >>> dgamma_dist.pmf(np.arange(1, 10)) array([ 0.39346934, 0.23865122, 0.14474928, 0.08779488, 0.05325028, 0.03229793, 0.01958968, 0.01188174, 0.00720664])
>>> md.nbinom_ztrunc.pmf(np.arange(1, 10), mu=2.541, k_agg=1) array([ 0.39354585, 0.23866751, 0.1447409 , 0.08777872, 0.05323377, 0.03228384, 0.01957867, 0.01187357, 0.00720077])
>>> # Get the approximate mean and variance >>> dgamma_dist.stats() (array(2.541494082536799), array(3.917698089032762))
>>> # Draw random numbers from the discrete gamma distribution >>> dgamma_dist.rvs(size=20) array([5, 4, 2, 1, 1, 1, 3, 3, 3, 3, 1, 1, 2, 1, 1, 1, 3, 1, 1, 3])
Methods
rvs(alpha, theta, loc=0, size=1) Random variates. pmf(x, alpha, theta, loc=0) Probability mass function. logpmf(x, alpha, theta, loc=0) Log of the probability mass function. cdf(x, alpha, theta, loc=0) Cumulative density function. logcdf(x, alpha, theta, loc=0) Log of the cumulative density function. sf(x, alpha, theta, loc=0) Survival function (1-cdf — sometimes more accurate). logsf(x, alpha, theta, loc=0) Log of the survival function. ppf(q, alpha, theta, loc=0) Percent point function (inverse of cdf — percentiles). isf(q, alpha, theta, loc=0) Inverse survival function (inverse of sf). stats(alpha, theta, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’). entropy(alpha, theta, loc=0) (Differential) entropy of the RV. expect(func, alpha, theta, loc=0, lb=None, ub=None, conditional=False) Expected value of a function (of one argument) with respect to the distribution. median(alpha, theta, loc=0) Median of the distribution. mean(alpha, theta, loc=0) Mean of the distribution. var(alpha, theta, loc=0) Variance of the distribution. std(alpha, theta, loc=0) Standard deviation of the distribution. interval(alpha, alpha, theta, loc=0) Endpoints of the range that contains alpha percent of the distribution