美文网首页
Fisher's exact test

Fisher's exact test

作者: 斩毛毛 | 来源:发表于2021-06-23 10:47 被阅读0次

用于分析列联表统计显著性检验方法

例子

探究秃头的人是不是学历高

秃头 浓发 总和
高学历 11 3 14
低学历 1 9 10
总和 12 12 24

原假设:秃头和高学历没得关系

第一步:想知道零假设是否成立,就要看这组数据是不是随机偶然一抽就能抽到,得到这样一组数据的超几何概率

P = (14! * 10! * 12! * 12!)/(11! * 3! 1! * 9! * 24!) = 0.00134

第二步:做完上面这一步还不够。如果行总数与列总数(又叫边际总数)不变,零假设不成立时的极端情况应该是,秃头的人学历高!那么我们可以得到新的列联表

秃头 浓发 总和
高学历 12 2 14
低学历 0 10 10
总和 12 12 24

再次计算P值

P = (14! * 10! * 12! * 12!)/(12! * 2! 0! * 10! * 24!) = 0.00003365

二者相加即为最终的p值
p-value = 0.00134 + 0.00003365 < 0.005

所以拒绝原假设,秃头的人学历高



1、Fisher's exact test

当2x2表格中有数值<5时,通常用Fisher's exact test 代替Chi-square Test。

例如:

Democrat Republican
Female 8 4
Male 4 9

为了检验性别和党派间是否存在显著相关性。

Python进行Fisher‘s exact test

## 给定数据
data = [[8,4], 
        [4,9]]

## 进行检验
import scipy.stats as stats
print(stats.fisher_exact(data))
(4.5, 0.1152)

从上面看到P值为0.1152 (two-tailed p value),而根据假设:

  • H0: 性别和党派间无相关性
  • H1: 性别和党派间存在相关性
    因为 p = 0.1152 > 0.05, 因此,不能拒绝H0假设,即性别和党派间无相关性。

利用R进行计算

data <- matrix(c(8,4,4,9), nrow = 2)
head(data)
[,1] [,2]
[1,]    8    4
[2,]    4    9

## 检验
fisher.test(data, alternative ="two.sided")
## alternative 默认为“two.sided”
Fisher's Exact Test for Count Data

data:  data
p-value = 0.1152
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
  0.6497106 33.5116389
sample estimates:
odds ratio 
  4.212306 

p值同样为0.1152。


reference

相关文章

网友评论

      本文标题:Fisher's exact test

      本文链接:https://www.haomeiwen.com/subject/aptbyltx.html