我一直在使用R,使用stats包中的chisq.test计算计数数据表的卡方值。这为整个表返回了一个卡方值。
W=c(98, 354, 105, 28)
WF=c(13, 108, 34, 6)
FNS=c(108, 438, 138, 24)
F=c(22, 61, 24, 2)
P=c(7, 48, 28, 4)
C=c(15, 68, 30, 4)
D=c(25, 106, 53, 5)
HD=c(39, 277, 122, 29)
Grade=cbind(W, WF, FNS, F, P, C, D, HD)
rownames(Grade)=c("3", "4", "5", "6")
Grade.chi=chisq.test(Grade)
Grade.chi
#Chi-squared approximation may be incorrect
# Pearson's Chi-squared test
#
#data: Grade
#X-squared = 54.274, df = 21, p-value = 9.012e-05
我想计算的是每个单元格的卡方值,这样我就可以用卡方值替换这个表中的计数数据:
W WF FNS F P C D HD
"3" 98 13 108 22 7 15 25 39
"4" 354 108 438 61 48 68 106 277
"5" 105 34 138 24 28 30 53 122
"6" 28 6 24 2 4 4 5 29
有没有预先存在的分数我可以使用,或者我需要"手动"计算每个单元格的分数?
我觉得它可能与这篇文章类似,但不确定如何在r 中调整卡方p值矩阵
感谢所有的帮助-我仍然是R.的初学者
如果将卡方检验保存在变量abc
中,那么您就可以计算值了
(abc$observed-abc$expected)^2/abc$expected