RFenxi 发表于 2014-6-1 01:54 
试过了,可行!只是需要把x变成我的数据集名称s:
by(s,profc,function(s) chisq.test(s$nth, s$intru,correct=F))
非常感谢!
接下来又有个新问题:
不分组的卡方检验,如
> a <- chisq.test(intru, nth)
> a
Pearson's Chi-squared test with Yates' continuity correction
data: intru and nth
X-squared = 166.3201, df = 1, p-value < 2.2e-16
> names(a)
[1] "statistic" "parameter" "p.value" "method" "data.name"
[6] "observed" "expected" "residuals" "stdres"
> a$expected
nth
intru 0 1
1 1871.768 166.2325
2 1810.232 160.7675
我可以通过这种方法找到理论频数,以确定我的卡方检验是否需要用连续性校正,甚至只能用fisher精确概率法。
但是,我用by分组计算后,然后就不知道怎么找到理论频数了,请高手指教!谢谢!