Gamma Distribution¶
Table of contents
Density Function¶
The density function of the Gamma distribution:
where \(\Gamma(\cdot)\) denotes the Gamma function, \(k\) is the shape parameter, and \(\theta\) is the scale parameter.
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.dgamma(x: float, shape: float = 1.0, scale: float = 1.0, log: bool = False) float
Density function of the Gamma distribution.
Example
>>> pystats.dgamma(2, 2, 3) 0.1140926931183538
- Parameters
x (float) – A real-valued input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
The density function evaluated at x.
List Input¶
- pystats.dgamma(x: List[float], shape: float = 1.0, scale: float = 1.0, log: bool = False) List[float]
Density function of the Gamma distribution.
Example
>>> pystats.dgamma([1.8, 0.7, 4.2], 2, 3) [0.1097623272188053, 0.061591410715083, 0.11507858317274963]
- Parameters
x (List[float]) – A standard list input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
A list of density values corresponding to the elements of x.
Cumulative Distribution Function¶
The cumulative distribution function (CDF) of the Gamma distribution:
where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.pgamma(p: float, shape: float = 1.0, scale: float = 1.0, log: bool = False) float
Distribution function of the Gamma distribution.
Example
>>> pystats.pgamma(2, 2, 3) 0.14430480161234657
- Parameters
p (float) – A real-valued input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
The cumulative distribution function evaluated at p.
List Input¶
- pystats.pgamma(p: List[float], shape: float = 1.0, scale: float = 1.0, log: bool = False) List[float]
Distribution function of the Gamma distribution.
Example
>>> pystats.pgamma([1.8, 0.7, 4.2], 2, 3) [0.12190138224955768, 0.023336201517969262, 0.4081672865401445]
- Parameters
p (List[float]) – A standard list input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
log (bool) – Return the log-density or the true form.
- Returns
A list of CDF values corresponding to the elements of p.
Quantile Function¶
The quantile function of the Gamma distribution:
where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.
Methods for scalar input, as well as for list input, are listed below.
Scalar Input¶
- pystats.qgamma(q: float, shape: float = 1.0, scale: float = 1.0) float
Quantile function of the Gamma distribution.
Example
>>> pystats.qgamma(0.15, 2, 3) 2.0497158392128205
- Parameters
q (float) – A real-valued input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
- Returns
The quantile function evaluated at q.
List Input¶
- pystats.qgamma(q: List[float], shape: float = 1.0, scale: float = 1.0) List[float]
Quantile function of the Gamma distribution.
Example
>>> pystats.qgamma([0.1, 0.2, 0.7], 2, 3) [1.5954348251688362, 2.473164927098954, 7.317649449840613]
- Parameters
q (List[float]) – A standard list input.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
- Returns
A list of quantiles values corresponding to the elements of q.
Random Sampling¶
Random sampling for the Gamma distribution is achieved via the Ziggurat method of Marsaglia and Tsang (2000).
Scalar Output¶
- pystats.rgamma(shape: float = 1.0, scale: float = 1.0) float
Random sampling function for the Gamma distribution.
Example
>>> pystats.rgamma(2, 3) 2.5950379008163194
- Parameters
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
- Returns
A pseudo-random draw from the Gamma distribution.
List Output¶
- pystats.rgamma(n: int, shape: float = 1.0, scale: float = 1.0) List[float]
Random sampling function for the Gamma distribution.
Example
>>> pystats.rgamma(3, 2, 3) [8.584541442906463, 4.491138145011711, 4.904685252957054]
- Parameters
n (int) – The number of output values.
shape (float) – The shape parameter, a real-valued input.
scale (float) – The scale parameter, a real-valued input.
- Returns
A list of pseudo-random draws from the Gamma distribution.