拟合 beta 分布时出错:函数 mle 无法估计参数,错误代码为 100

Error when fitting a beta distribution: the function mle failed to estimate the parameters with error code 100

我正在尝试使用 fitdistrplus 包中的 fitdist () 函数来使我的数据适应不同的分布。假设我的数据如下所示:

x = c (1.300000, 1.220000, 1.160000, 1.300000, 1.380000, 1.240000,
1.150000, 1.180000, 1.350000, 1.290000, 1.150000, 1.240000,
1.150000, 1.120000, 1.260000, 1.120000, 1.460000, 1.310000,
1.270000, 1.260000, 1.270000, 1.180000, 1.290000, 1.120000,
1.310000, 1.120000, 1.220000, 1.160000, 1.460000, 1.410000,
1.250000, 1.200000, 1.180000, 1.830000, 1.670000, 1.130000,
1.150000, 1.170000, 1.190000, 1.380000, 1.160000, 1.120000,
1.280000, 1.180000, 1.170000, 1.410000, 1.550000, 1.170000,
1.298701, 1.123595, 1.098901, 1.123595, 1.110000, 1.420000,
1.360000, 1.290000, 1.230000, 1.270000, 1.190000, 1.180000,
1.298701, 1.136364, 1.098901, 1.123595, 1.316900, 1.281800,
1.239400, 1.216989, 1.785077, 1.250800, 1.370000)

接下来,如果我 运行 fitdist (x, "gamma") 一切正常,但如果我使用 fitdist (x, "beta") 代替,我会收到以下错误:

Error in start.arg.default(data10, distr = distname) : 
  values must be in [0-1] to fit a beta distribution

好的,所以我不是英语母语,但据我了解,此方法要求数据在 [0,1] 范围内,因此我使用 x_scaled = (x-min(x))/max(x) 对其进行缩放。这给了我一个向量,其值在该范围内,与原始向量 x.

完全相关

因为x_scaled属于class matrix,所以我使用as.numeric()转换成一个数值向量。然后用 fitdist(x_scale,"beta").

拟合模型

这次我得到以下错误:

Error in fitdist(x_scale, "beta") : 
  the function mle failed to estimate the parameters, with the error code 100

所以在那之后我一直在做一些搜索引擎查询,但我没有找到任何有用的东西。有人知道这里出了什么问题吗?谢谢

通过阅读源码可以发现,fitdist默认的估计方式是mle,会从同一个包中调用mledist,会构造您选择的分布的负对数似然,并使用 optimconstrOptim 在数值上最小化它。如果数值优化过程有任何问题,您会收到错误消息。

好像是因为当x_scaled包含0或1时,在计算β分布的负对数似然时会出现一些问题,所以数值优化方法就会崩溃。一个肮脏的技巧是让 x_scaled <- (x - min(x) + 0.001) / (max(x) - min(x) + 0.002),所以 x_scaled 中没有 0 和 1,fitdist 将起作用。