我正在尝试测试计数数据向量与二项式的拟合优度。为此,我正在使用包goodfit()
中的函数vcd
。但是,当我运行该函数时,它会返回NaN
卡方检验的 p 值。在我的设置中,我有一个包含 75 个元素的计数数据向量。
> library(vcd)
> counts <- c(32, 35, 44, 35, 41, 33, 42, 49, 36, 41, 42, 45, 38, 43, 36,
35, 40, 40, 43, 34, 39, 31, 40, 39, 36, 37, 37, 37, 32, 48, 41,
32, 37, 36, 49, 37, 41, 36, 34, 37, 41, 32, 36, 36, 30, 33, 33,
42, 39, 36, 36, 29, 31, 41, 36, 39, 40, 37, 39, 39, 31, 39, 37,
40, 33, 41, 34, 46, 35, 41, 44, 38, 44, 34, 42)
> test.gof <- goodfit(counts, type="binomial",
+ par=list(size=length(counts), prob=0.5))
一切正常,但是当我检查goodfit()
对象时,我得到以下信息:
> summary(test.gof)
Goodness-of-fit test for binomial distribution
X^2 df P(> X^2)
Pearson NaN 75 NaN
Likelihood Ratio 21.48322 19 0.3107244
Warning message:
In summary.goodfit(test.gof) : Chi-squared approximation may be incorrect
起初我怀疑这是一个小样本量问题,但我也有一个包含 50 个观察值的数据集,没有返回NaN
p 值。我还尝试将方法切换goodfit()
到 ML,结果相似。
为什么在这种情况下会产生这个功能NaN
?是否有替代函数来计算计数数据的 GOF?