【发布时间】:2010-12-02 06:32:35
【问题描述】:
我使用模型拟合将负二项式分布拟合到我的离散数据。作为最后一步,我似乎需要执行 Kolmogrov-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)
一切正常。有什么建议吗?
【问题讨论】:
-
plot(gf) 在这里工作(R 2.12.0,vcd 版本 1.2-9)。使用 options(warn=2,error=recover) 将警告转换为错误,然后在警告/错误时启动浏览器。在拟合过程中的某个时刻,R 试图使 NB 'prob' 参数为负 ... f
标签: r statistics