21.2 比例检验的功效

power.prop.test() 计算两样本比例检验的功效

usage(power.prop.test)
power.prop.test(n = NULL, p1 = NULL, p2 = NULL, sig.level = 0.05, power = NULL,
    alternative = c("two.sided", "one.sided"), strict = FALSE,
    tol = .Machine$double.eps^0.25)

功效可以用来计算实验所需要的样本量,检验统计量的功效越大/高,检验方法越好,实验所需要的样本量越少

# p1 >= p2 的检验 单边和双边检验
power.prop.test(
  p1 = .65, p2 = 0.6, sig.level = .05,
  power = 0.90, alternative = "one.sided"
)
## 
##      Two-sample comparison of proportions power calculation 
## 
##               n = 1603.846
##              p1 = 0.65
##              p2 = 0.6
##       sig.level = 0.05
##           power = 0.9
##     alternative = one.sided
## 
## NOTE: n is number in *each* group
power.prop.test(
  p1 = .65, p2 = 0.6, sig.level = .05,
  power = 0.90, alternative = "two.sided"
)
## 
##      Two-sample comparison of proportions power calculation 
## 
##               n = 1968.064
##              p1 = 0.65
##              p2 = 0.6
##       sig.level = 0.05
##           power = 0.9
##     alternative = two.sided
## 
## NOTE: n is number in *each* group

pwrpwr.2p.test() 函数提供了类似 power.prop.test() 函数的功能

library(pwr)
# 明确 p1 > p2 的检验
# 单边检验拆分更加明细,分为大于和小于
pwr.2p.test(
  h = ES.h(p1 = 0.65, p2 = 0.6),
  sig.level = 0.05, power = 0.9, alternative = "greater"
)
## 
##      Difference of proportion power calculation for binomial distribution (arcsine transformation) 
## 
##               h = 0.1033347
##               n = 1604.007
##       sig.level = 0.05
##           power = 0.9
##     alternative = greater
## 
## NOTE: same sample sizes

已知两样本的样本量不等,检验 H0: \(p_1 = p_2\) H1: \(p_1 \neq p_2\) 的功效

library(pwr)
pwr.2p2n.test(
  h = 0.30, n1 = 80, n2 = 245,
  sig.level = 0.05, alternative = "greater"
)
## 
##      difference of proportion power calculation for binomial distribution (arcsine transformation) 
## 
##               h = 0.3
##              n1 = 80
##              n2 = 245
##       sig.level = 0.05
##           power = 0.7532924
##     alternative = greater
## 
## NOTE: different sample sizes

h 表示两个样本的差异,计算得到的功效是 0.75