【发布时间】:2018-06-18 03:26:39
【问题描述】:
我正在尝试使用 R 对一系列观察结果进行泊松拟合优度检验。我正在计算每分钟有多少人在 57 分钟内做了某件事。我从来没有得到任何大于 13 的观察值,我得到了以下数据: (适用于 0 至 13 人以上的情况):
observed = c(3/57, 4/57, 9/57, 7/57, 9/57, 8/57, 2/57, 3/57, 7/57, 2/57, 1/57, 0, 1/57, 1/57, 0)
表示我观察了 3 次 0 人、4 次 1 人、9 次 2 人等等(最后的 0 表示我从未见过 14 人或更多人)。
mn = 4.578947
cases = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
estimated = c()
for (i in cases)(estimated <- c(estimated, dpois(i, lambda = mn)))
estimated <- c(estimated, (1-ppois(13, lambda=mn)))
其中mn 是从数据中获得的平均值。
最后,我跑了
chisq.test(observed, p=estimated)
我得到:
Chi-squared test for given probabilities
data: observed
X-squared = 1.0182, df = 14, p-value = 1
Warning message:
In chisq.test(observed, p = estimated) :
Chi-squared approximation may be incorrect
我在这方面并不精通(既不是统计数据,也不是 R 编程),但我认为我不应该得到正好为 1.0 的 p 值。我究竟做错了什么? (顺便说一句:我的代码很可能不是我想要做的最佳选择,但我几乎不使用 R 并且它不是我现在工作的重点。)
【问题讨论】:
-
除了对观察到的频率使用计数数据外,您还需要为每个 bin/ 出现类别提供
expected frequencies >= 5。在下面我的回答中解释了如何实现这一点。
标签: r statistics chi-squared goodness-of-fit