Density, distribution function, quantile function, and highest density region calculation for the inverse-Gamma distribution with parameters alpha and beta.
alpha,beta: rate and shape parameters of the inverse-Gamma density, both positive
content: scalar, 0 < content < 1, volume of highest density region
debug: logical; if TRUE, debugging information from the search for the HDR is printed
Details
The inverse-Gamma density arises frequently in Bayesian analysis of normal data, as the (marginal) conjugate prior for the unknown variance parameter. The inverse-Gamma density for x>0 with parameters α>0 and β>0
is
f(x)=Γ(α)βαx−α−1exp(−β/x)
where Γ(x) is the gamma function
Γ(a)=∫0∞ta−1exp(−t)dt
and so ensures f(x) integrates to one. The inverse-Gamma density has a mean at beta/(alpha−1) for alpha>1 and has variance beta2/((alpha−1)2(alpha−2)) for alpha>2. The inverse-Gamma density has a unique mode at beta/(alpha+1).
The evaluation of the density, cumulative distribution function and quantiles is done by calls to the dgamma, pgamma and igamma
functions, with the arguments appropriately transformed. That is, note that if xIG(alpha,beta then 1/xG(alpha,beta).
Highest Density Regions. In general, suppose x
has a density f(x), where x∈Θ. Then a highest density region (HDR) for x with content c("p\n", "in(0,1]") is a region (or set of regions) c("mathcalQ\n", "subseteqTheta") such that:
∫Qf(x)dx=p
and
f(x)>f(x∗)∀x∈Q,x∗∈Q.
For a continuous, unimodal density defined with respect to a single parameter (like the inverse-Gamma case considered here with parameters c("0<\n", "alpha<infty,,,0<beta<infty")), a HDR region Q
of content p (with 0<p<1) is a unique, closed interval on the real half-line.
This function uses numerical methods to solve for the boundaries of a HDR with contentp for the inverse-Gamma density, via repeated calls the functions densigamma, pigamma and qigamma. In particular, the function uniroot is used to find points v and w such that
f(v)=f(w)
subject to the constraint
∫vwf(x;α,β)dθ=p.
Returns
densigamma gives the density, pigamma the distribution function, qigamma the quantile function, rigamma generates random samples, and igammaHDR gives the lower and upper limits of the HDR, as defined above (NAs if the optimization is not successful).
Note
The densigamma is named so as not to conflict with the digamma function in the R base package (the derivative of the gamma function).