我使用模型擬合來將負二項式分佈擬合到我的離散數據中。作爲最後一步,我需要執行Kolmogrov-Smirnov測試來確定模型是否適合數據。我可以找到的所有參考文獻談到使用測試正常分佈連續數據。有人能告訴我這是否可以在R中完成不正常分佈和離散的數據? (即使是卡方檢驗應該做的我猜,但請糾正我,如果我錯了。)Kolmogorov-Smirnov或卡方測試的分佈?
UPDATE:
所以我發現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)
一切工作正常。有什麼建議麼?
屬於http://stats.stackexchange.com/ – MSalters 2010-12-02 08:19:58