macroeco.models.geom_uptrunc = <macroeco.models._distributions.geom_uptrunc_gen object at 0x1086530d0>

An upper-truncated geometric discrete random variable.

\[P(x) = \frac{(1-p)^{x} p}{1 - (1-p)^{b+1}}\]

for x >= 0. geom_uptrunc takes two shape parameters: p and b, the upper limit. The loc parameter is not used.


x : array_like


q : array_like

lower or upper tail probability

p, 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 = geom_uptrunc(p, b, loc=0) :

  • Frozen RV object with the same methods but holding the given shape and location fixed.

mu : float

distribution mean

b : float

distribution upper limit, defaults to sum of data


The boundary p = 1 is a special case in which the ratio between successive terms of the distribution is 1 (i.e., the pmf is uniform). This arises when the mean of the distribution is precisely one-half the upper limit.

This distribution is known as the Pi distribution in the MaxEnt Theory of Ecology [1], where the p parameter is equivalent to 1 - exp(-lambda). The special case of a uniform pmf has been described as HEAP [2].


[1]Harte, J. (2011). Maximum Entropy and Ecology: A Theory of Abundance, Distribution, and Energetics (p. 264). Oxford, United Kingdom: Oxford University Press.
[2]Harte, J., Conlisk, E., Ostling, A., Green, J. L., & Smith, A. B. (2005). A theory of spatial structure in ecological communities at multiple spatial scales. Ecological Monographs, 75(2), 179-197.


>>> import macroeco.models as md
>>> # Get the geom parameters from a mean and upper limit
>>> mu = 20; b = 200
>>> p, b = md.geom_uptrunc.translate_args(mu, b)
>>> p, b
(array(0.047592556687674925), 200)
>>> # Get the pmf
>>> md.geom_uptrunc.pmf(np.arange(0, 5), p, b)
array([ 0.04759519,  0.04533002,  0.04317264,  0.04111795,  0.03916104])
>>> # Generate a rank abundance distribution
>>> rad = md.geom_uptrunc.rank(20, p, b)
>>> rad
array([  0.,   1.,   2.,   3.,   5.,   6.,   8.,   9.,  11.,  13.,  15.,
    17.,  20.,  23.,  26.,  30.,  35.,  42.,  53.,  75.])
>>> # Fit the geom to data
>>> md.geom_uptrunc.fit_mle(rad)
(0.048309175638750035, 394.0)


rvs(p, b, loc=0, size=1) Random variates.
pmf(x, p, b, loc=0) Probability mass function.
logpmf(x, p, b, loc=0) Log of the probability mass function.
cdf(x, p, b, loc=0) Cumulative density function.
logcdf(x, p, b, loc=0) Log of the cumulative density function.
sf(x, p, b, loc=0) Survival function (1-cdf — sometimes more accurate).
logsf(x, p, b, loc=0) Log of the survival function.
ppf(q, p, b, loc=0) Percent point function (inverse of cdf — percentiles).
isf(q, p, b, loc=0) Inverse survival function (inverse of sf).
stats(p, b, loc=0, moments=’mv’) Mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’).
entropy(p, b, loc=0) (Differential) entropy of the RV.
expect(func, p, b, loc=0, lb=None, ub=None, conditional=False) Expected value of a function (of one argument) with respect to the distribution.
median(p, b, loc=0) Median of the distribution.
mean(p, b, loc=0) Mean of the distribution.
var(p, b, loc=0) Variance of the distribution.
std(p, b, loc=0) Standard deviation of the distribution.
interval(alpha, p, b, loc=0) Endpoints of the range that contains alpha percent of the distribution