# Sampling from an Inverse Gamma distribution

I am using Gibbs sampling in the MCMC estimation of a stochastic volatility model. One of the posterior distributions is an Inverse Gamma distribution.
I was struggling with the sampling procedure or to be precise with the link to the Gamma distribution. Is it true that to get $Y \sim IG(alpha,beta)$, I have to sample $X \sim Gamma(\alpha,1/\beta)$ and take $Y = 1/X$? This is also inline with posts on mathworks.

However, I also read it up on wolfram and in my opinion they contradict themselves in the article (https://reference.wolfram.com/language/ref/InverseGammaDistribution.html).

From the paragraph Background&Context (which deals with the generalized gamma distribution though):

vs. the description from Details (specifically the fourth point):

Does this discrepancy arise due to the difference between the inverse gamma and the generalized inverse gamma?

This discrepancy arises because there are two different parameterizations of the Gamma distribution and each relate differently to the Inverse Gamma distribution.

On Wikipedia, the two parameterizations for the Gamma distribution are differentiated by using $(k,\theta)$ and $(\alpha, \beta)$. $$\text{If } X \sim \text{Gamma}(k, \theta) , \,\,\,\, f(x) = \dfrac{1}{\Gamma(k) \theta^k} x^{k-1} e^{x/\theta}\,.$$ $$\text{If } X \sim \text{Gamma}(\alpha, \beta) , \,\,\,\, f(x) = \dfrac{\beta^{\alpha}}{\Gamma(\alpha)} x^{\alpha-1} e^{x\beta}\,.$$

Here $\alpha$ and $k$ are exactly the same in the pdfs but $\theta$ is and $\beta$ are different. $\theta$ is called the scale parameter and $\beta$ is called the rate parameter. The relation between these two is that $\beta = 1/\theta$.

If $X \sim \text{Gamma}(\alpha, \beta)$ where $\beta$ is the rate parameter, then $1/X \sim IG(\alpha, \beta)$.

If $X \sim \text{Gamma}(k, \theta)$, where $\theta$ is the scale parameter, then $1/X \sim IG(k, 1/\theta)$.

In both those cases, the pdf of the IG is the same. If $Y \sim IG(\alpha, \beta)$, then the pdf of $Y$ is always $$f(y) = \dfrac{\beta^{\alpha}}{\Gamma(\alpha)} x^{-\alpha-1} e^{-\beta/x}.$$

• I have two papers in front of me, where one indeed specifies the parameters of the inverse gamma as $\alpha$ and $\beta$. In the other paper they are named m and M instead. So, I assume there is no way to find out the terminology used by the authors by just looking at the expression $X \sim IG(p_1, p_2)$? Cause they neither call the latter parameter scale nor rate. Thank you! – mscnvrsy Jul 20 '16 at 13:43
• If they have $IG(\alpha, \beta)$, there is no question as to what the pdf is, since there is only one parameterization for $IG$. – Greenparker Jul 20 '16 at 13:50
• But from $IG(m,M)$ it's not that obvious, is it? Anyway, thank you very much (again)! I've been dealing with that issue for 3 weeks now... Finally, it's solved. – mscnvrsy Jul 20 '16 at 13:52
• @mscnvrsy It is obvious even for $IG(m, M)$ because there is only one parametrization for IG. Its how it relates to Gamma that might be confusing. Given $Y \sim IG(m,M)$, $1/Y \sim Gamma(m, M)$ or $1/Y \sim Gamma(m, 1/M)$ depending on the parameterization for Gamma that you choose. But the pdf of the IG will not be different based on these parameterizations. I have edited my answer to explain this a little bit more. – Greenparker Jul 20 '16 at 13:53
• But how can I infer whether they provide $\theta$ or $\beta$ just from the expression $X \sim IG(m,M)$ with neither the $(\alpha,\beta)$ nor the $(k,\theta)$ specification, nor the formula for the pdf? I think we're talking past each other right now – mscnvrsy Jul 20 '16 at 13:56