2

我想做一个卡方检验,将我的数据(“真实”列)与理论正态分布(“理论”列)进行比较,理论正态分布(在 Excel 中)通过大真实样本的参数(处理这个样本的排名 - 是“真实”列)。

RI 中的什么测试应该用于此目的?

一开始我以为应该是chisq.test

但是我将它的结果与 EXCEL 中函数“CHI2TEST”的结果进行比较(应该给出相同的结果),这些结果是完全不同的。它给出 p 值 = 0.2426,Excel 的 CHI2TEST 给出 p 值 0.87。

也许我用chisq.test错了?您能否检查我的脚本或建议我正确测试 R 中的卡方检验?

> real
[1]  2  3 15 22 21 14  2  1
> theor
[1]  1.4  5.7 14.1 21.6 20.2 11.6  4.1  0.9
> chisq.test (real,theor)

        Pearson's Chi-squared test

data:  real and theor
X-squared = 48, df = 42, p-value = 0.2426  

Warning message:
In chisq.test(real, theor) : Chi-squared approximation may be incorrect
4

1 回答 1

5

chisq.test是用于列联表的,这不是你给它的。(注意自由度是 42,所以它认为你的“真实”变量是计数而不是数字测量。看看这个 Pearson 卡方检验的实现:

> chisq <- sum( (real-theor)^2/theor)

> chisq
[1] 3.2159
> pchisq(chisq, length(theor)-1 )   # df = n-1
[1] 0.1356627                          
> 1- pchisq(chisq, length(theor)-1 )
[1] 0.8643373       
             # compare to Excel

有许多不同版本的“卡方”检验。事实上,任何只将他们的分析描述为“使用卡方检验”的人都应该被怀疑无能。上述测试可以描述为测量到理论拟合优度的卡方检验。

于 2014-12-18T21:10:13.923 回答