简体   繁体   English

将逆伽马分布拟合到R中的数据

[英]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 ). 假设我有一个样本,该样本可以遵循反伽马分布(请参阅Empirical PDF )。

I would like to estimate the shape parameter alpha and the scale parameter beta with something like fitdistr . 我想用fitdistr估算形状参数alpha和比例参数beta。 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 ): 我已经尝试了以下解决方案(遵循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]. 它说:非有限的有限差分值[2]。

The data can be found at https://www.dropbox.com/s/j4n09w1sszcv0ud/data.txt?dl=0 . 可以在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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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