我试图通过使用来自fitdist包的fitdistrplus函数将我的数据与瑞利分布相匹配。
x <- c(19.000000,23.000000,26.000000,45.000000,8.050000,46.900000,1.268333,30.000000,
1.466667,3.733333,1.683333,4.000000,3.950000,1.850000,42.000000,1.333333,
1.550000,1.000000,2.066667,1.566667,1.216667,1.850000,1.400000,8.366667,
19.000000,29.000000,17.000000,42.000000,19.000000,10.000000,53.000000,2.550000,
15.483333,1.533333,1.216667,1.550000,32.000000,6.583333,6.516667,5.750000,
9.283333,46.000000,2.016667,2.133333,4.516667,46.950000,1.600000,1.433333,
3.166667,4.416667,17.016667,2.433333,2.713333,8.633333,3.150000,1.183333,
14.000000,10.706667,7.026944,31.000000,35.000000,21.000000,14.000000,2.200000,
26.000000,3.316667,51.000000,13.000000,34.000000,11.650000,49.000000,12.000000,
26.000000,20.000000,22.000000,6.483333,24.000000,5.333333,4.833333,8.750000,
6.216667,17.000000,1.083333,19.000000,48.000000,15.000000,1.266667,54.000000,
32.000000,3.616667,6.666667,1.600000,2.083333,6.933333,33.033333,1.883333,
1.000000,3.072222,49.000000,1.400000)
dat <- data.frame(x)
# Generate gamma rvs
den <- density(x)
orig <- data.frame(x = den$x, y = den$y)
fit.params.2 <- fitdistrplus::fitdist(dat$x, "rayleigh", start = list(sigma = 1))然后出现一个错误:
Error in fitdistrplus::fitdist(dat$x, "rayleigh", start = list(sigma = 1)) :
the function mle failed to estimate the parameters,
with the error code 1这个问题有什么解决办法吗?谢谢你的帮助。
发布于 2021-01-27 12:13:12
有两个问题。(1)瑞利分布似乎不适合数据(见下面的图输出),(2)您需要一个更好的起始值。由于sigma与瑞利分布的平均值成正比(请参阅维基百科),请尝试:
library(fitdistrplus)
library(extraDistr)
fit <- fitdist(dat$x, "rayleigh", start = list(sigma = mean(dat$x)))
fit
## Fitting of the distribution ' rayleigh ' by maximum likelihood
## Parameters:
## estimate Std. Error
## sigma 15.00063 0.749935
plot(fit)

https://stackoverflow.com/questions/65918603
复制相似问题