简体   繁体   中英

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 .

I have the answer. It is as simple as

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM