[Stable]

The Inverse Gamma distribution is commonly used as a prior distribution in Bayesian statistics, particularly for variance parameters.

dist_inverse_gamma(shape, rate = 1/scale, scale)

Arguments

shape, scale

parameters. Must be strictly positive.

rate

an alternative way to specify the scale.

Details

We recommend reading this documentation on pkgdown which renders math nicely. https://pkg.mitchelloharawild.com/distributional/reference/dist_inverse_gamma.html

In the following, let \(X\) be an Inverse Gamma random variable with shape parameter shape = \(\alpha\) and rate parameter rate = \(\beta\) (equivalently, scale = \(1/\beta\)).

Support: \(x \in (0, \infty)\)

Mean: \(\frac{\beta}{\alpha - 1}\) for \(\alpha > 1\), otherwise undefined

Variance: \(\frac{\beta^2}{(\alpha - 1)^2 (\alpha - 2)}\) for \(\alpha > 2\), otherwise undefined

Probability density function (p.d.f):

$$ f(x) = \frac{\beta^\alpha}{\Gamma(\alpha)} x^{-\alpha - 1} e^{-\beta/x} $$

Cumulative distribution function (c.d.f):

$$ F(x) = \frac{\Gamma(\alpha, \beta/x)}{\Gamma(\alpha)} = Q(\alpha, \beta/x) $$

where \(\Gamma(\alpha, z)\) is the upper incomplete gamma function and \(Q\) is the regularized incomplete gamma function.

Moment generating function (m.g.f):

$$ M_X(t) = \frac{2 (-\beta t)^{\alpha/2}}{\Gamma(\alpha)} K_\alpha\left(\sqrt{-4\beta t}\right) $$

for \(t < 0\), where \(K_\alpha\) is the modified Bessel function of the second kind. The MGF does not exist for \(t \ge 0\).

Examples

dist <- dist_inverse_gamma(shape = c(1,2,3,3), rate = c(1,1,1,2))
dist
#> <distribution[4]>
#> [1] InvGamma(1, 1)   InvGamma(2, 1)   InvGamma(3, 1)   InvGamma(3, 0.5)

mean(dist)
#> [1]   NA 1.00 0.50 0.25
variance(dist)
#> [1]     NA     NA 0.2500 0.0625
support(dist)
#> <support_region[4]>
#> [1] (0,Inf) (0,Inf) (0,Inf) (0,Inf)
generate(dist, 10)
#> [[1]]
#>  [1]   0.6605219 256.3582586   0.5001634   1.2191401   1.2563643   0.4022428
#>  [7]   7.4514159   0.7468579   3.8498618  18.9712486
#> 
#> [[2]]
#>  [1] 0.3664776 0.7476891 0.3780903 0.9671384 0.7709538 0.4069481 0.6814969
#>  [8] 0.9533425 3.3480869 0.3670534
#> 
#> [[3]]
#>  [1] 0.6233011 0.6373356 0.2007577 0.2092655 0.1346754 0.2676804 0.6111096
#>  [8] 0.4226531 0.7653020 0.1121910
#> 
#> [[4]]
#>  [1] 0.2392879 0.1632741 0.4501820 0.1522806 0.0644651 0.1349977 0.5484456
#>  [8] 1.3034066 0.1192222 0.1190331
#> 

density(dist, 2)
#> [1] 0.151632665 0.075816332 0.018954083 0.003042191
density(dist, 2, log = TRUE)
#> [1] -1.886294 -2.579442 -3.965736 -5.795177

cdf(dist, 4)
#> [1] 0.7788008 0.9735010 0.9978385 0.9997035

quantile(dist, 0.7)
#> [1] 2.8036733 0.9112869 0.5225272 0.2612636