user10572895
user10572895

Reputation:

Fit inverse gamma distribution to data in R

Let's say I have a sample that could follow an inverse gamma distribution (see Empirical PDF).

I would like to estimate the shape parameter alpha and the scale parameter beta with something like fitdistr. Is it possible?

I have tried the this solution (following https://stats.stackexchange.com/questions/31934/maximum-likelihood-estimation-of-inverse-gamma-distribution-in-r-or-rpy):

f <- function(x, a, b){
  ((b^a)/gamma(a))*((1/x)^(a-1))*exp(-b/x) #PDF Inv. Gamma
}
fitdistr(x, f, list(a=.01, b=.01))

but it does not work for me. It says: non-finite finite-difference value [2].

The data can be found at https://www.dropbox.com/s/j4n09w1sszcv0ud/data.txt?dl=0 .

Upvotes: 0

Views: 1793

Answers (1)

user10572895
user10572895

Reputation:

I have the answer. It is as simple as

fit = MASS::fitdistr(1/x1, "gamma")

Upvotes: 1

Related Questions