我对R真的很陌生,所以请容忍我。我使用了一种x-平方检验来比较给定位置的核苷酸频率,我在两个不同的数据集中计算了A,C,G,T的数目:
x1 <- c(272003,310418,201601,237168)
x2 <- c(239614,316515,182070,198025)我可以想出两种方法来要求两个样本的x-平方测试:
> chisq.test(x1,x2)
Pearson's Chi-squared test
data: x1 and x2
X-squared = 12, df = 9, p-value = 0.2133
Warning message:
In chisq.test(x1, x2) : Chi-squared approximation may be incorrect或
> chisq.test(cbind(x1,x2))
Pearson's Chi-squared test
data: cbind(x1, x2)
X-squared = 2942.065, df = 3, p-value < 2.2e-16我怀疑第二个版本是正确的,因为我也可以这样做:
> chisq.test(x1,x1)
Pearson's Chi-squared test
data: x1 and x1
X-squared = 12, df = 9, p-value = 0.2133
Warning message:
In chisq.test(x1, x1) : Chi-squared approximation may be incorrect结果很明显是不正确的。
在这种情况下,实际计算的是什么?
谢谢!
发布于 2014-01-27 06:15:22
chisq.test(x1,x1)$expected显示了以下内容:
x1
x1 201601 237168 272003 310418
201601 0.25 0.25 0.25 0.25
237168 0.25 0.25 0.25 0.25
272003 0.25 0.25 0.25 0.25
310418 0.25 0.25 0.25 0.25观察计数(chisq.test(x1,x1)$observed):
x1
x1 201601 237168 272003 310418
201601 1 0 0 0
237168 0 1 0 0
272003 0 0 1 0
310418 0 0 0 1就像这样,它假设你提供了所有的对,但是你只提供了相同的数字,因此也就是观察到的计数。然后,期望值实际上是“正确的”(虽然在本例中是愚蠢的)。顺便提一句,chisq.test(cbind(x1,x1))按照您的期望来做(X-squared = 0, df = 3, p-value = 1)。
不过,你的第二个结果看起来不错:
> chisq.test(cbind(x1,x2))$observed
x1 x2
[1,] 272003 239614
[2,] 310418 316515
[3,] 201601 182070
[4,] 237168 198025
> chisq.test(cbind(x1,x2))$expected
x1 x2
[1,] 266912.4 244704.6
[2,] 327073.2 299859.8
[3,] 200162.6 183508.4
[4,] 227041.8 208151.2https://stackoverflow.com/questions/21374081
复制相似问题