Fisher's test on 2x10 contingency (expected value <6 in >20% of cell) - 解决 R 工作区错误,或建议替代统计测试?
Fisher's test on 2x10 contingency (expected value <6 in >20% of cell) - Solve R workspace error, OR suggest alternative statistical test?
我有 2x10 的应急费用。不幸的是,6 个单元格的预期值小于 5,因此我无法使用 Pearson Chi sq 检验。
我尝试在 R 中使用 Fisher 检验(fisher.test()
,如果我理解正确,它会自动执行 Freeman-Halton 扩展),但我认为我的计算机无法处理计算量。
这是我会得到的错误:
Error in fisher.test(x$size, y$gender, workspace = 2e+08) :
FEXACT error 7(location). LDSTP=18716400 is too small for this problem,
(pastp=328.023, ipn_0:=ipoin[itp=120337]=176553, stp[ipn_0]=318.699).
Increase workspace or consider using 'simulate.p.value=TRUE'
试图将工作区增加到 2e9,但出现此错误:
Error: cannot allocate vector of size 7.5 Gb
带有 Yates 修正的卡方检验可以解决这个问题吗?即便如此,出于某种原因,我似乎也无法强迫 R 对我的计算进行 Yates 校正 - chisq.test(x$size, y$gender, correct=T)
。相反,correct=F
有效。
有什么建议的解决方案吗?或者我可以使用替代测试?
谢谢!
让我们试试这个例子:
set.seed(111)
value = rnbinom(1000,mu=69,size=1)
size = cut(value,10)
gender = rep(c("M","F"),each=500)
table(gender,size)
gender (-0.466,46.6] (46.6,93.2] (93.2,140] (140,186] (186,233] (233,280]
F 244 107 67 42 17 11
M 255 127 64 28 11 8
size
gender (280,326] (326,373] (373,419] (419,466]
F 7 4 0 1
M 4 2 1 0
fisher.test(gender, size)
Error in fisher.test(gender, size) :
FEXACT error 7(location). LDSTP=18480 is too small for this problem,
(pastp=81.1067, ipn_0:=ipoin[itp=68]=79, stp[ipn_0]=80.6036).
Increase workspace or consider using 'simulate.p.value=TRUE'
就像你说的,chisq 修正测试:
chisq.test(gender,size)$p.value
[1] 0.3452619
chisq.test(gender,size,correct=TRUE)$p.value
[1] 0.3452619
还有一个很好的理由:
correct: a logical indicating whether to apply continuity correction
when computing the test statistic for 2 by 2 tables
您可以像 Dave2e
指出的那样使用 simulate.p.value = TRUE
,在这种情况下它或多或少是可以的,因为我在 null 下模拟,组之间没有区别:
Fisher's Exact Test for Count Data with simulated p-value (based on
2000 replicates)
data: gender and size
p-value = 0.3393
alternative hypothesis: two.sided
这基本上类似于具有分布模拟的卡方检验:
library(coin)
chisq_test(table(gender,size),distribution = approximate(nresample = 10000))
Approximative Pearson Chi-Squared Test
data: size by gender (F, M)
chi-squared = 10.065, p-value = 0.3263
如果您的类别是有序的,您可以尝试线性关联,查看更多 here。
我有 2x10 的应急费用。不幸的是,6 个单元格的预期值小于 5,因此我无法使用 Pearson Chi sq 检验。
我尝试在 R 中使用 Fisher 检验(fisher.test()
,如果我理解正确,它会自动执行 Freeman-Halton 扩展),但我认为我的计算机无法处理计算量。
这是我会得到的错误:
Error in fisher.test(x$size, y$gender, workspace = 2e+08) :
FEXACT error 7(location). LDSTP=18716400 is too small for this problem,
(pastp=328.023, ipn_0:=ipoin[itp=120337]=176553, stp[ipn_0]=318.699).
Increase workspace or consider using 'simulate.p.value=TRUE'
试图将工作区增加到 2e9,但出现此错误:
Error: cannot allocate vector of size 7.5 Gb
带有 Yates 修正的卡方检验可以解决这个问题吗?即便如此,出于某种原因,我似乎也无法强迫 R 对我的计算进行 Yates 校正 - chisq.test(x$size, y$gender, correct=T)
。相反,correct=F
有效。
有什么建议的解决方案吗?或者我可以使用替代测试?
谢谢!
让我们试试这个例子:
set.seed(111)
value = rnbinom(1000,mu=69,size=1)
size = cut(value,10)
gender = rep(c("M","F"),each=500)
table(gender,size)
gender (-0.466,46.6] (46.6,93.2] (93.2,140] (140,186] (186,233] (233,280]
F 244 107 67 42 17 11
M 255 127 64 28 11 8
size
gender (280,326] (326,373] (373,419] (419,466]
F 7 4 0 1
M 4 2 1 0
fisher.test(gender, size)
Error in fisher.test(gender, size) :
FEXACT error 7(location). LDSTP=18480 is too small for this problem,
(pastp=81.1067, ipn_0:=ipoin[itp=68]=79, stp[ipn_0]=80.6036).
Increase workspace or consider using 'simulate.p.value=TRUE'
就像你说的,chisq 修正测试:
chisq.test(gender,size)$p.value
[1] 0.3452619
chisq.test(gender,size,correct=TRUE)$p.value
[1] 0.3452619
还有一个很好的理由:
correct: a logical indicating whether to apply continuity correction when computing the test statistic for 2 by 2 tables
您可以像 Dave2e
指出的那样使用 simulate.p.value = TRUE
,在这种情况下它或多或少是可以的,因为我在 null 下模拟,组之间没有区别:
Fisher's Exact Test for Count Data with simulated p-value (based on
2000 replicates)
data: gender and size
p-value = 0.3393
alternative hypothesis: two.sided
这基本上类似于具有分布模拟的卡方检验:
library(coin)
chisq_test(table(gender,size),distribution = approximate(nresample = 10000))
Approximative Pearson Chi-Squared Test
data: size by gender (F, M)
chi-squared = 10.065, p-value = 0.3263
如果您的类别是有序的,您可以尝试线性关联,查看更多 here。