错误代码 100 在 r 中使用 fitdist 拟合 exp 分布

Jud*_*y S 7 r

我正在尝试将指数分布拟合到我的数据中,但出现以下错误

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

我试过 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
Run Code Online (Sandbox Code Playgroud)

这是我的代码

ExpMle41 <- fitdist(x41, "exp", method="mle") 
ExpMle41
plot(ExpMle41)
Run Code Online (Sandbox Code Playgroud)

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

Spa*_*man 9

假设这是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
Run Code Online (Sandbox Code Playgroud)

但是你的数据中有一些很大的数字......也许如果我们把它全部缩小一个因子......

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

好吧,这似乎奏效了。让我们缩小一点:

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

对。除以一千件作品。我们继续吧:

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

美好的。

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

因此将数据按 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
Run Code Online (Sandbox Code Playgroud)

紧缩。看起来底层算法存在一些数值稳定性问题。如果它在任何时候都以指数形式计算您的数据,那么它可能会遇到与无穷大无法区分的东西。喜欢:

> 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
Run Code Online (Sandbox Code Playgroud)

但是按 10 缩放,数学可以应付,大约 (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
Run Code Online (Sandbox Code Playgroud)