在R中使用fitdist的错误代码100 fit exp分布

时间:2018-11-30 11:51:59

标签: r

我正在尝试对数据进行指数分布,但出现以下错误

"Error in fitdist(x41, "exp", method = "mle") : 
  the function mle failed to estimate the parameters, 
                with the error code 100"

我已经尝试过mme了,但是我还有其他的mle发行版,所以我也需要指数分布的mle。我被困了好几天。有人可以帮我吗?

我的数据如下。

2795.5
304.6833
2786.45
5897.75
4381.367
1178.1
351.3167
109.85
459.6167
13.26667
0.033333
846.3833
3698.45
1527.1
94.31667
15.01667
271.8833
473

这是我的代码

ExpMle41 <- fitdist(x41, "exp", method="mle") 
ExpMle41
plot(ExpMle41)

任何帮助将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

假设这是fitdist包中的fitdistrplus,我可以复制您的错误:

> fitdist(x41, "exp", method="mle")
<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data,     gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth,     lower = lower, upper = upper, ...): non-finite finite-difference value [1]>
Error in fitdist(x41, "exp", method = "mle") : 
  the function mle failed to estimate the parameters, 
                with the error code 100

但是您的数据中有很多数字...也许我们将其按比例缩小...

> fitdist(x41/10000, "exp", method="mle")
Fitting of the distribution ' exp ' by maximum likelihood 
Parameters:
     estimate Std. Error
rate   7.1417   1.683315

这似乎行得通。让我们缩小一点:

> fitdist(x41/1000, "exp", method="mle")
Fitting of the distribution ' exp ' by maximum likelihood 
Parameters:
     estimate Std. Error
rate  0.71417  0.1683312

对。除以一千个作品。让我们继续前进:

> fitdist(x41/100, "exp", method="mle")
Fitting of the distribution ' exp ' by maximum likelihood 
Parameters:
     estimate Std. Error
rate 0.071417 0.01682985

好。

> fitdist(x41/10, "exp", method="mle")
Fitting of the distribution ' exp ' by maximum likelihood 
Parameters:
      estimate  Std. Error
rate 0.0071417 0.001649523

因此将数据按1/10缩放是可行的,您可以看到估算值和SE缩放的方式。让我们再走一步:

> fitdist(x41/1, "exp", method="mle")
<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data,     gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth,     lower = lower, upper = upper, ...): non-finite finite-difference value [1]>
Error in fitdist(x41/1, "exp", method = "mle") : 
  the function mle failed to estimate the parameters, 
                with the error code 100

嘎吱嘎吱。底层算法看起来像一些数值稳定性问题。如果它在任何时候都对您的数据采用指数形式,那么它可能会与无穷大相提并论。喜欢:

> exp(x41)
 [1]           Inf 2.100274e+132           Inf           Inf           Inf
 [6]           Inf 3.757545e+152  5.096228e+47 4.064401e+199  5.776191e+05
[11]  1.033895e+00           Inf           Inf           Inf  9.145540e+40
[16]  3.323969e+06 1.195135e+118 2.638092e+205

但是按比例缩放十倍,数学就可以应付,大约(E + 256 !!!)

> exp(x41/10)
 [1] 2.552833e+121  1.706977e+13 1.032728e+121 1.367817e+256 1.907002e+190
 [6]  1.459597e+51  1.809216e+15  5.898273e+04  9.139021e+19  3.768462e+00
[11]  1.003339e+00  5.727429e+36 4.184491e+160  2.094645e+66  1.247731e+04
[16]  4.489166e+00  6.423056e+11  3.484408e+20