R:是费希尔';大数字的精确测试仍然准确吗?

R:是费希尔';大数字的精确测试仍然准确吗?,r,R,我有一个像这样的2x2表,我想对它进行Fisher精确测试,以测试两组之间的重叠是否显著 正如你所看到的,我有一个非常大的数字2.2e9,它超过了32位R可以处理的最大数字的限制 yes no yes 127437282 364949163 no 188213539 2200433302 我用bit64包和.integer64()解决了这个问题。然后我运行Fisher精确测试: fisher<-function(n1,n2,n3,n4,fname){ l

我有一个像这样的2x2表,我想对它进行Fisher精确测试,以测试两组之间的重叠是否显著

正如你所看到的,我有一个非常大的数字2.2e9,它超过了32位R可以处理的最大数字的限制

    yes no
yes 127437282   364949163
no  188213539   2200433302
我用bit64包和.integer64()解决了这个问题。然后我运行Fisher精确测试:

    fisher<-function(n1,n2,n3,n4,fname){
    library(bit64)
    n1n<-as.integer(n1)
    n2n<-as.integer(n2)
    n3n<-as.integer(n3)
    n4n<-as.integer64(n4)
    testor=rbind(c(n1n,n2n),c(n3n,n4n))
    x<-fisher.test(testor)
    print("sample name")
    print(fname)
    print("data is")
    print(testor)
    print("fisher's exact test result is")
    x
}
fisher(f1,f2,f3,f4,f5)

fisher我不认为使用pkg:bit64可以提供可靠的计算基础。即使是订单的基本测试也会失败:

这是fisher测试中的测试:

>  any( c(1,1,1, n4n) > .Machine$integer.max)
[1] FALSE
我认为integer64值被隐式强制为
数值
值,然后被不适当地解释为非常小的数值。在本例中,“numeric”或“double”的“a”部分为53位,其余11位的大部分为10的幂。请注意,通过
c()
将数字“1”从整数64强制为数字时会发生什么情况

问题在于,为了让
c.integer64
.integer64
正确处理“integer64”,需要将
integer64
分类对象作为第一项。(这些是在S3方法之后,因此它们仅从第一个参数获取类分派。)

请注意,将1,1位置与2,2位置交换将得到相同的结果

> fisher( 2200433302,   364949163, 188213539, 127437282, "no_op")
Error in fisher.test(testor) : 
  all entries of 'x' must be nonnegative and finite
In addition: Warning message:
In fisher(2200433302, 364949163, 188213539, 127437282, "no_op") :
  NAs introduced by coercion
将值更改为all强制为integer64并不能防止出现问题:

> c(1,1,1, n4n)[4] > .Machine$integer.max
[1] FALSE
>  n4n > .Machine$integer.max
[1] TRUE
 fisher<-function(n1,n2,n3,n4,fname){
     library(bit64)
     n1n<-as.integer64(n1)
     n2n<-as.integer64(n2)
     n3n<-as.integer64(n3)
     n4n<-as.integer64(n4)
     testor=rbind(c(n1n,n2n),c(n3n,n4n))
     x<-fisher.test(testor)
     print("sample name")
     print(fname)
     print("data is")
     print(testor)
     print("fisher's exact test result is")
     x
   }

fisher( 2200433302,   364949163, 188213539, 127437282, "no_op")
# Error in fisher.test(testor) : 'x' has entries too large to be integer

fisher这根本没有解决你的问题,但这是一个有趣的链接,你到底为什么要做一个fisher的精确测试?该测试更适合于小计数。卡方检验不是更合适吗?1.086944e-314实际上是0。@MrFlick我意识到卡方检验更适合Fisher精确检验。。我只是以前不知道。然而,问题仍然存在,2.2e9成为一个非常小的数字。我想这仍然是32位R中的大数字问题。用如此大的数字进行显著性/假设检验是荒谬的。您的优势比为
4.082(95%CI=4.081-4.083)
。如果有人想检查他们是否缺乏口译技能。谢谢你的详细回答。我想对于R中这么大的数字,没有办法做到这一点。我能将所有输入计数除以10,然后进行卡方检验吗?或者有什么方法可以做比例测试?
> c(n4n, 1,1,1, n4n)[5] > .Machine$integer.max
[1] TRUE
> fisher( 2200433302,   364949163, 188213539, 127437282, "no_op")
Error in fisher.test(testor) : 
  all entries of 'x' must be nonnegative and finite
In addition: Warning message:
In fisher(2200433302, 364949163, 188213539, 127437282, "no_op") :
  NAs introduced by coercion
 fisher<-function(n1,n2,n3,n4,fname){
     library(bit64)
     n1n<-as.integer64(n1)
     n2n<-as.integer64(n2)
     n3n<-as.integer64(n3)
     n4n<-as.integer64(n4)
     testor=rbind(c(n1n,n2n),c(n3n,n4n))
     x<-fisher.test(testor)
     print("sample name")
     print(fname)
     print("data is")
     print(testor)
     print("fisher's exact test result is")
     x
   }

fisher( 2200433302,   364949163, 188213539, 127437282, "no_op")
# Error in fisher.test(testor) : 'x' has entries too large to be integer