Inverse-Gamma Distribution

Table of contents


Density Function

The density function of the inverse-Gamma distribution:

\[f(x; \alpha, \beta) = \dfrac{\beta^{\alpha}}{\Gamma(\alpha)} x^{-\alpha-1} \exp\left(-\frac{\beta}{x}\right) \times \mathbf{1}[ x \geq 0 ]\]

where \(\Gamma(\cdot)\) denotes the Gamma function, \(\alpha\) is the shape parameter, and \(\beta\) is the rate parameter.

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.dinvgamma(x: float, shape: float = 1.0, rate: float = 1.0, log: bool = False) float

Density function of the inverse-Gamma distribution.

Example

>>> pystats.dinvgamma(1.5, 2, 1)
0.15212359082447174
Parameters
  • x (float) – A real-valued input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate 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.dinvgamma(x: List[float], shape: float = 1.0, rate: float = 1.0, log: bool = False) List[float]

Density function of the inverse-Gamma distribution.

Example

>>> pystats.dinvgamma([1.8, 0.7, 4.2], 3, 2)
[0.12543552347504414, 0.9568116496062874, 0.007984650912112904]
Parameters
  • x (List[float]) – A standard list input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate 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 inverse-Gamma distribution:

\[F(x; \alpha, \beta) = \int_0^x f(z; \alpha, \beta) dz = 1 - \frac{\gamma(1/x,\beta/x)}{\Gamma (\alpha)}\]

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.pinvgamma(p: float, shape: float = 1.0, rate: float = 1.0, log: bool = False) float

Distribution function of the inverse-Gamma distribution.

Example

>>> pystats.pinvgamma(1.5, 2, 1)
0.8556951983876534
Parameters
  • p (float) – A real-valued input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate 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.pinvgamma(p: List[float], shape: float = 1.0, rate: float = 1.0, log: bool = False) List[float]

Distribution function of the inverse-Gamma distribution.

Example

>>> pystats.pinvgamma([1.8, 0.7, 4.2], 3, 2)
[0.8981685222907052, 0.4559446713286356, 0.9873531870485975]
Parameters
  • p (List[float]) – A standard list input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate 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 inverse-Gamma distribution:

\[q(p; \alpha, \beta) = \inf \left\{ x : p \leq 1 - \frac{\gamma(1/x,\beta/x)}{\Gamma (\alpha)} \right\}\]

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.qinvgamma(q: float, shape: float = 1.0, rate: float = 1.0) float

Quantile function of the inverse-Gamma distribution.

Example

>>> pystats.qinvgamma(0.95, 2, 1)
2.8140357632821265
Parameters
  • q (float) – A real-valued input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate parameter, a real-valued input.

Returns

The quantile function evaluated at q.

List Input

pystats.qinvgamma(q: List[float], shape: float = 1.0, rate: float = 1.0) List[float]

Quantile function of the inverse-Gamma distribution.

Example

>>> pystats.qinvgamma([0.3, 0.5, 0.6], 3, 2)
[0.5531634821501723, 0.7479262863802247, 0.8752440657450371]
Parameters
  • q (List[float]) – A standard list input.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate parameter, a real-valued input.

Returns

A list of quantiles values corresponding to the elements of q.


Random Sampling

Random sampling for the inverse-Gamma distribution is achieved by simulating \(X \sim G(\alpha, 1/\beta)\), then returning

\[Z = \frac{1}{X} \sim \text{IG}(\alpha,\beta)\]

Scalar Output

pystats.rinvgamma(shape: float = 1.0, rate: float = 1.0) float

Random sampling function for the inverse-Gamma distribution.

Example

>>> pystats.rinvgamma(2, 1)
0.29563080448131196
Parameters
  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate parameter, a real-valued input.

Returns

A pseudo-random draw from the inverse-Gamma distribution.

List Output

pystats.rinvgamma(n: int, shape: float = 1.0, rate: float = 1.0) List[float]

Random sampling function for the inverse-Gamma distribution.

Example

>>> pystats.rinvgamma(3, 2, 1)
[0.31841204990923705, 0.47383794440642224, 0.4720582119984054]
Parameters
  • n (int) – The number of output values.

  • shape (float) – The shape parameter, a real-valued input.

  • rate (float) – The rate parameter, a real-valued input.

Returns

A list of pseudo-random draws from the inverse-Gamma distribution.