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] 0.9917914 3.1186729 47.1285069 19.4519820 1.1407050 2.1386756
#> [7] 44.1410852 3.8318874 6.3278763 10.5052104
#>
#> [[2]]
#> [1] 0.3733395 0.7154693 0.3985912 0.4477348 2.0754918 0.8672564 0.7758725
#> [8] 0.7153657 1.0945662 0.2585611
#>
#> [[3]]
#> [1] 0.4168679 0.3437469 0.2257971 1.1402373 0.1910216 0.3157200 0.3205713
#> [8] 0.1664944 0.6499774 0.2423886
#>
#> [[4]]
#> [1] 0.26115203 0.41051559 0.09656743 0.21845522 0.12719092 0.26514069
#> [7] 0.22362301 0.13507356 0.20343338 0.26233230
#>
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