我尝试进行卡方检验以确定区域之间的疾病比例是否存在显着差异,但我最终在R中出现错误。有关如何纠正此错误的建议吗?
data:
E NE NW SE SW EM WM YH
Cases 11 37 54 30 114 44 31 39
Non.cases 28 73 116 68 211 80 78 92
d=read.csv(file.choose(),header=T)
attach(d)
chisq.test(d)
Error in chisq.test(d) :
all entries of 'x' must be nonnegative and finite
答案 0 :(得分:2)
你的问题必须在卡方测试的上游某处,即数据在读入时会以某种方式被破坏。
d <- read.table(header=TRUE,text="
E NE NW SE SW EM WM YH
Cases 11 37 54 30 114 44 31 39
Non.cases 28 73 116 68 211 80 78 92")
但是,您阅读数据后,结果应如下所示:
str(d)
## 'data.frame': 2 obs. of 8 variables:
## $ E : int 11 28
## $ NE: int 37 73
## ... etc.
chisq.test(d)
## Pearson's Chi-squared test
## data: d
## X-squared = 3.3405, df = 7, p-value = 0.8518
(attach()
没有必要,通常实际上有害/混淆......)