2017-01-21 27 views
3

私はちょうどYates補正であっても、セルの周波数が低い2 x 2テーブルの場合、Rはchi^2統計を間違って計算しているようです。Rはセル数の少ない2x2テーブルのカイ二乗統計量を誤って計算していますか?

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ことを考えるに誤って計算され、そして0.185を生じる第二の方法は、より正確であること?あるいは、小さな細胞数は、すべてのベットがオフであることを意味しますか?

更新:

イェーツの連続性補正なしで正常に動作するように見えるん:

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 
+0

を使用する小さな細胞計数のためにカイ二乗の上に[フィッシャーの正確確率検定](https://www.google.com/#q=fisher+exact+test+vs+chi+square)に見て。 – Parfait

答えて

4

ヘルプファイル/ manページ状態

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 

少なくとも、これは文書化された動作のようです。

サイドノート:疑いで、あなたは明らかにシミュレーション

この場合には、途中でどこかにカイ二乗を発見し、警告を取り除く、
> 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 

で見つかったp値を使用することができれば。またはfisher.test ...

+0

FWIWこれは訂正なしのカイ二乗統計量です –

関連する問題