当我使用fitdist列表执行gofstat() R函数时,出现错误。我不知道这个错误的含义和导致它的原因。
> gofstat(list(fitw, fitg, fitln), fitnames=c("weibull", "gamma", "lnorm"))
Error in names(Chi2$chisqpvalue) <- names(Chi2$chisqdf) <- fitnames[1] :
attempt to set an attribute on NULL我使用的整个代码如下所示。我认为它与prob向量有关,因为相同的脚本和其他数据集提供了结果。
prob <- c(0.004926108, 0.510983890, 0.306590334, 0.048409000, 0.032272667, 0.005378778, 0.005378778, 0.037651445, 0.005378778, 0.037651445, 0.005378778)
fitw <- fitdist(prob, distr = "weibull", method = "mle")
fitg<- fitdist(prob, distr = "gamma", method = "mle")
fitln <- fitdist(prob, distr = "lnorm", method = "mle")
gofstat(list(fitw, fitg, fitln), fitnames=c("weibull", "gamma", "lnorm"))对于我来说,werid部分是gofstat单独工作的部分:
> gofstat(fitw)
Goodness-of-fit statistics
1-mle-weibull
Kolmogorov-Smirnov statistic 0.2354052
Cramer-von Mises statistic 0.1426774
Anderson-Darling statistic 0.8750089
Goodness-of-fit criteria
1-mle-weibull
Akaike's Information Criterion -33.74893
Bayesian Information Criterion -32.95314
> gofstat(fitg)
Goodness-of-fit statistics
1-mle-gamma
Kolmogorov-Smirnov statistic 0.2760907
Cramer-von Mises statistic 0.1983721
Anderson-Darling statistic 1.1044287
Goodness-of-fit criteria
1-mle-gamma
Akaike's Information Criterion -32.26493
Bayesian Information Criterion -31.46914
> gofstat(fitln)
Goodness-of-fit statistics
1-mle-lnorm
Kolmogorov-Smirnov statistic 0.2781579
Cramer-von Mises statistic 0.1279150
Anderson-Darling statistic 0.8426833
Goodness-of-fit criteria
1-mle-lnorm
Akaike's Information Criterion -36.57233
Bayesian Information Criterion -35.77654顺便说一句,你认为哪个分布更适合?
发布于 2020-03-25 01:24:41
这个错误是因为它在定义chisq中断时有问题,如果你看一下你提供的例子,在0.005378778处有一个意外的峰值,这使得它非常有问题,特别是当n很小时:
table(prob)
prob
0.004926108 0.005378778 0.032272667 0.037651445 0.048409 0.306590334
1 4 1 2 1 1
0.51098389
1你可以尝试下面这样的东西,但由于你最可能专注于mle,它应该是可以的:
library(fitdistrplus)
fits = lapply(fitnames,function(i){
fitdist(prob, distr = i, method = "mle")
})
gofstat(fits,chisqbreaks=c(0,0.01,0.1,0.6))
Goodness-of-fit statistics
1-mle-weibull 2-mle-gamma 3-mle-lnorm
Kolmogorov-Smirnov statistic 0.2354052 0.2760907 0.2781579
Cramer-von Mises statistic 0.1426774 0.1983721 0.1279150
Anderson-Darling statistic 0.8750089 1.1044287 0.8426833
Goodness-of-fit criteria
1-mle-weibull 2-mle-gamma 3-mle-lnorm
Akaike's Information Criterion -33.74893 -32.26493 -36.57233
Bayesian Information Criterion -32.95314 -31.46914 -35.77654再说一次,你的观察是有限的,所以chisq估计将是棘手的。你的第二个关于哪个分布更好的问题,很难分辨,因为n很小,有4个重复值。
https://stackoverflow.com/questions/60828400
复制相似问题