我使用模型拟合来将负二项式分布拟合到我的离散数据中。作为最后一步,看起来我需要执行 Kolmogorov-Smirnov 检验来确定模型是否适合数据。我找到的所有参考资料都是关于如何针对正态分布的连续数据使用此检验。请问在 R 中是否可以对非正态分布的离散数据进行此操作?(我猜测即使使用卡方检验也可以,但如果我错了,请指出。)
更新:
因此,我发现
更新:
因此,我发现
vcd
包包含一个名为 goodfit
的函数,可按以下方式用于此目的:library(vcd)
# Define the data
data <- c(67, 81, 93, 65, 18, 44, 31, 103, 64, 19, 27, 57, 63, 25, 22, 150,
31, 58, 93, 6, 86, 43, 17, 9, 78, 23, 75, 28, 37, 23, 108, 14, 137,
69, 58, 81, 62, 25, 54, 57, 65, 72, 17, 22, 170, 95, 38, 33, 34, 68,
38, 117, 28, 17, 19, 25, 24, 15, 103, 31, 33, 77, 38, 8, 48, 32, 48,
26, 63, 16, 70, 87, 31, 36, 31, 38, 91, 117, 16, 40, 7, 26, 15, 89,
67, 7, 39, 33, 58)
gf <- goodfit(data, type = "nbinomial", method = "MinChisq")
plot(gf)
但在 gf <- ...
步骤之后,R 报错如下:
Warning messages:
1: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
2: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
3: In pnbinom(q, size, prob, lower.tail, log.p) : NaNs produced
我说“plot”,它就会抱怨:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
我不确定正在发生什么,因为如果我将data
设置为以下内容:
data <- <- rnbinom(200, size = 1.5, prob = 0.8)
一切正常运行。有什么建议吗?