R – How to Perform Maximum Likelihood Estimation of Inverse Gamma Distribution in R or RPy

curve fittingdensity functiongamma distributionr

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:

enter image description here

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.

Best 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) )