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)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\).
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] 2.6213179 2.2634405 5.2080916 0.4762990 2.1961705 1.4460740
#> [7] 0.6605219 256.3582586 0.5001634 1.2191401
#>
#> [[2]]
#> [1] 0.5031377 0.2279797 1.2797352 0.3565268 0.9475674 1.7909942 0.3664776
#> [8] 0.7476891 0.3780903 0.9671384
#>
#> [[3]]
#> [1] 0.4472460 0.2701471 0.4068668 0.5246646 1.2266273 0.2482667 0.6233011
#> [8] 0.6373356 0.2007577 0.2092655
#>
#> [[4]]
#> [1] 0.06733771 0.13384022 0.30555479 0.21132656 0.38265102 0.05609552
#> [7] 0.23928793 0.16327412 0.45018199 0.15228056
#>
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