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.6132127 0.4127031 72.5775113 7.0167154 0.8867238 11.4242776
#> [7] 0.6792793 3.0921280 3.1121877 0.4747536
#>
#> [[2]]
#> [1] 0.6102953 0.5391927 0.2469765 0.4393749 0.7003396 0.8959872 0.4510678
#> [8] 1.1437459 0.4485920 0.7079026
#>
#> [[3]]
#> [1] 0.2635877 0.5319891 0.6631608 0.2090058 0.5418861 0.3079863 0.6337484
#> [8] 0.1402588 0.5238718 0.5537360
#>
#> [[4]]
#> [1] 0.12561903 0.58373410 0.29681654 0.08910829 0.08867388 0.69120564
#> [7] 0.21761724 0.05986397 0.10355521 0.20414696
#>
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