Fisher确切检验

R 中的 A/B 测试

Lauryn Burleigh

Data Scientist

规范

  • 分类数据的非参数方法
    • 是否会再次食用干酪或意大利辣香肠披萨
  • 样本 < 1000
  • 至少20%单元频数 < 5
  • 用Fisher确切检验求精确p值
  • 2×2列联表

超几何分布

  • 列联表的似然
table(Pizza$Topping, Pizza$EatAgain)
              No Yes
  Cheese     140 360
  Pepperoni   80 420
R 中的 A/B 测试

假设

  • 原假设:再次食用与配料组无关

多只手拿起披萨切片的照片。

R 中的 A/B 测试

样本

library(pwr)
pwr.chisq.test(w = 0.1, df = 2, 
               power = 0.80, 
               sig.level = 0.05)
     Chi squared power calculation 
              w = 0.1
              N = 963.4689
             df = 2
      sig.level = 0.05
          power = 0.8
NOTE: N is the number of observations
table(Pizza$Topping, Pizza$EatAgain)
              No Yes
  Cheese     140 360
  Pepperoni   80 420
R 中的 A/B 测试

检验

freqtbl <- table(Pizza$Topping, 
                 Pizza$Time)
fisher.test(freqtbl) 
    Fisher's Exact Test for Count Data
data:  freqtbl
p-value = 0.001809
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
 0.4569013 0.8417208
sample estimates:
odds ratio 
 0.6209987 
R 中的 A/B 测试

效应量

freqtbl <- table(Pizza$Topping, 
                 Pizza$Time)
fisher.test(freqtbl) 
  • 小:1.5
  • 中:2.5
  • 大:4
  • 意大利辣香肠披萨相对干酪披萨的比值比≈0.62
Fisher's Exact Test for Count Data
data:  freqtbl
p-value = 0.001809
alternative hypothesis: true odds 
ratio is not equal to 1
95 percent confidence interval:
 0.4569013 0.8417208
sample estimates:
odds ratio 
 0.6209987  
R 中的 A/B 测试

检验功效

library(pwr)
pwr.2p.test(h = 0.62, n = 500, 
            sig.level = 0.002) 
    Difference of proportion power 
 calculation for binomial distribution

              h = 0.62
              n = 500
      sig.level = 0.002
          power = 1
    alternative = two.sided

NOTE: same sample sizes
R 中的 A/B 测试

Passons à la pratique !

R 中的 A/B 测试

Preparing Video For Download...