【问题标题】:Does R incorrectly compute the chi-squared statistic for 2x2 tables with low cell counts?R 是否错误地计算了具有低单元格计数的 2x2 表的卡方统计量?
【发布时间】:2017-01-21 14:53:34
【问题描述】:

我刚刚注意到,对于单元格频率较低的 2 x 2 表,即使进行了 Yates 校正,R 似乎也错误地计算了 chi^2 统计数据。

mat <- matrix(c(3, 2, 14, 10), ncol = 2)
chi <- stats::chisq.test(mat)
## Warning message:
## In stats::chisq.test(mat) : Chi-squared approximation may be incorrect

# from the function
chi$statistic
##    X-squared 
## 1.626059e-31 

# as it should be (with Yates correction)
sum((abs(chi$observed - chi$expected) - 0.5)^2 / chi$expected)
## [1] 0.1851001

我是否认为R 计算不正确,而产生 .185 的第二种方法更准确?还是小细胞计数意味着所有赌注都没有了?

更新:

如果没有 Yates 连续性校正,它似乎确实可以正常工作:

chi <- stats::chisq.test(mat, correct = FALSE)
## Warning message:
## In stats::chisq.test(mat, correct = FALSE) :
##   Chi-squared approximation may be incorrect

chi$statistic
##   X-squared 
## 0.004738562 

sum((abs(chi$observed - chi$expected))^2 / chi$expected)
## [1] 0.004738562

【问题讨论】:

标签: r chi-squared


【解决方案1】:

帮助文件/手册页状态

one half is subtracted from all |O - E| differences; however,
the correction will not be bigger than the differences themselves.

您的示例中的差异都小于 0.5:

> chi$observed - chi$expected
            [,1]        [,2]
[1,]  0.06896552 -0.06896552
[2,] -0.06896552  0.06896552

因此,至少,这似乎是记录在案的行为。

旁注:如果有疑问,您显然可以使用通过模拟找到的 p 值

> chi <- stats::chisq.test(mat, simulate.p.value=TRUE, B=1e6)
> chi

    Pearson's Chi-squared test with simulated p-value (based on 1e+06 replicates)

data:  mat
X-squared = 0.0047386, df = NA, p-value = 1

在这种情况下,它会在中间某处找到一个卡方并消除警告。或者使用fisher.test...

【讨论】:

  • FWIW 这是未经校正的卡方统计量
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-15
  • 2020-07-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-06
相关资源
最近更新 更多