# Why doesn't the method of moments work when calculating the variance of the inverse gamma distribution?

I'm trying to calculate the variance of the inverse gamma distribution using the method of movements. According to wikipedia the variance should be:

$$\sigma^2 =\frac{\beta^2}{(\alpha-1)^2(\alpha-2)}$$

Where $\alpha$ is the shape and $\beta$ is the scale of the inverse gamma distribution. When trying this out in R it works reasonably well when $\alpha$ is not to close to 2. For example:

library(MCMCpack) # for the rinvgamma function
a <- 10
b 100

# The variance according to the method of movements
b^2/((a-1)^2*(a-2))
## 15.4321

# The variance by generating inverse gamma distributed random numbers and
# calculating the sample variance
var(rinvgamma(n=9999, shape=a, scale=b)) #
## 15.84388


But when $\alpha$ gets close to 2 the method of movements doesn't seem to work anymore. In the following example the sample variance is much smaller than the method of movements variance:

a <- 2.2
b <- 100

# The variance according to the method of movements
b^2/((a-1)^2*(a-2))
## 34722.22

# The variance by generating inverse gamma distributed random numbers and
# calculating the sample variance
var(rinvgamma(n=9999, shape=a, scale=b)) #
##14479.56


Why doesn't the method of movements work? Am I doing something wrong that can be fixed or is there some other way that I can calculate the variance of an inverse gamma distribution?

• With such a huge theoretical variance, you need a quite large sample to estimate it accurately. Even with the normal distribution you will observe discrepancies var(rnorm(10000,100,35000)) (less severe, of course). – user10525 Nov 6 '12 at 11:14
• When $\alpha \rightarrow 2$, the variance goes to infinity. You cannot hope to approach "infinity" accurately – ocram Nov 6 '12 at 11:15
• @Procrastinator: sorry, we have posted at the same time! – ocram Nov 6 '12 at 11:15
• for small $\hat{\alpha}-2$ the variance of the estimate may be infinite (I haven't checked, but I'd expect that to be the case). – Glen_b Nov 6 '12 at 11:39
• @RasmusBååth Well, you are not using the method of moments precisely. The expression b^2/((a-1)^2*(a-2)) is actually the theoretical variance. The method of moments consists of solving the system $\dfrac{\beta}{\alpha-1}=\bar{x}$ and $\dfrac{\beta^2}{(\alpha-1)^2(\alpha-2)}=\dfrac{1}{n}\sum_{j=1}^n(x_j-\bar{x})^2$ in terms of $(\alpha,\beta)$. After this, you could plug the solutions $(\hat{\alpha},\hat{\beta})$ into the expression for the variance $\dfrac{\beta^2}{(\alpha-1)^2(\alpha-2)}$ in order to obtain an estimator of this quantity. – user10525 Nov 6 '12 at 12:30