mrpy.base.stats.TGGDln

class mrpy.base.stats.TGGDln(scale=0.0, a=-1.0, b=1.0, xmin=-2.3025850929940459)

The Truncated Generalised Gamma Distribution in ln space.

Specifically, if exp(x) is drawn from a TGGD distribution (in real space), this function gives the distribution of x, using the same parameter values.

The ln TGGD has the following PDF:

\[\frac{ b (\exp((x-s)(a+1)) \exp(-\exp(b(x-s)))}{s \Gamma(\frac{a+1}{b},\exp(b(x-s)))}\]

where s corresponds to the scale argument of this class, and \(\Gamma\) is the incomplete gamma function, provided by mpmath.

Parameters:

scale : array_like, optional

Transition scale from power-law to exponential cut-off. Analogous to the scale parameter for the standard Gamma distribution.

a : float or array_like, optional

Power-law slope of the TGGD.

b : float or array_like, optional

Exponential cut-off parameter of the TGGD.

xmin : float or array_like, optional

Truncation value of the TGGD.

Examples

The following should create a sample and plot its histogram. The histogram should have a slope of -1.

>>> from mrpy.base.stats import TGGDln
>>> import matplotlib.pyplot as plt
>>> tggdln = TGGDln(a=-2)
>>> r = tggdln.rvs(100)
>>> plt.hist(r) 

Taking the quantile of the cumulative probability at each variate should return something close to the variate.

>>> a = tggdln.quantile(tggdln.cdf(r))/r  #should be close to 1
>>> np.all(np.isclose(a,1))
True

Show that the numerical integral is equal to the CDF.

>>> from scipy.integrate import quad
>>> tggdln = TGGDln(scale=14,a=-1.5,b=0.7,xmin=10)
>>> a = quad(tggdln.pdf,10,11)[0]/tggdln.cdf(11) # should be close to 1
>>> np.isclose(a,1)
True

The CDF should approach unity when x >> scale

>>> a = tggdln.cdf(np.log(1e18)) #Should be close to 1
>>> np.isclose(a,1)
True

To show the link to the log and ln variants, the following should be a sequence from 0 to 1 (by 0.1)

>>> from mrpy.base.stats import TGGDlog, TGGDln
>>> tggd = TGGD()
>>> tggd_log = TGGDlog()
>>> tggd_ln = TGGDln()
>>> a = tggd_log.cdf(np.log10(tggd.quantile(np.arange(0,1,0.1)))) 
>>> np.all(np.isclose(a,np.arange(0,1,0.1)))
True
>>> a = tggd_log.cdf(tggd_ln.quantile(np.arange(0,1,0.1))/np.log(10))
>>> np.all(np.isclose(a,np.arange(0,1,0.1)))
True

Methods

__init__([scale, a, b, xmin])
cdf(q[, lower_tail, log_p]) The cdf of the distribution.
central_moments(n) Calculate the nth central moment, E[(X-mu)^n].
normalised_central_moments(n) Calculate the nth standardized central moment, E[(X-mu)^n]/sigma^n.
pdf(x[, log]) The pdf of the distribution.
quantile(p[, lower_tail, log_p, res_approx]) The quantile of the distribution.
raw_moments(n) Calculate the nth raw moment, E[X^n].
rvs(n[, res_approx]) Generate random variates from the distribution.