# Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy

I am trying to fit a three parameter inverse gamma distribution to my data in either R or Python. I would like to do this using maximum likelihood estimation (MLE).

The pdf of the three parameter inverse gamma is given by:

Where Γ is the gamma function, ρ is the shape, α is the scale and s is the location parameter

I haven't spotted an R package that can perform MLE to this distribution directly (if you know of one, please let me know!). So I think this leaves either:

• (A) working out the log-likelihood function of the formula
• (B) transforming the data to a gamma distribution. However, this distribution only has two parameters so I'm not clear on how I would calculate the third parameter (I'm not a very mathematical person!).

Any help on a method to use MLE to fit an inverse gamma distribution to my data would be much appreciated! Many thanks in advance.

## 1 Answer

Since you know the density, you can just use fitdistr.

# Sample data
library(LaplacesDemon)
x <- rinvgamma(1000, 1,2)

library(MASS)
f <- function(x, rho, a, s)
1/(a*gamma(rho)) * (a / (x-s))^(rho+1) * exp( - a/(x-s) )
fitdistr( x, f, list(rho=1, a=1, s=0) )

• Thank you for your solution Vincent. Much appreciated! Will try this now. Jul 9, 2012 at 16:06