#>
#> Two-sample t test power calculation
#>
#> n = 100
#> delta = 2.2
#> sd = 1
#> sig.level = 0.05
#> power = 1
#> alternative = two.sided
#>
#> NOTE: n is number in *each* group
# 前面 t 检验的等价功效计算library(pwr)pwr.t.test(d =2.2/6.4,n =100,sig.level =0.05,type ="two.sample",alternative ="two.sided")
#>
#> Two-sample t test power calculation
#>
#> n = 100
#> d = 0.34375
#> sig.level = 0.05
#> power = 0.6768572
#> alternative = two.sided
#>
#> NOTE: n is number in *each* group
sleep 数据集为例,计算功效
# 分组计算均值aggregate(data = sleep, extra ~ group, FUN = mean)
#> group extra
#> 1 1 0.75
#> 2 2 2.33
# 分组计算标准差aggregate(data = sleep, extra ~ group, FUN = sd)
#>
#> Two-sample t test power calculation
#>
#> n = 38.39795
#> delta = 1.58
#> sd = 1.89563
#> sig.level = 0.05
#> power = 0.95
#> alternative = two.sided
#>
#> NOTE: n is number in *each* group
经检验,上面取两组的平均方差代替共同方差和下面精确计算的结果差不多。各组至少需要 39 个样本。MKpower 包精确计算 Welch t 检验的功效
#>
#> 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
#>
#> 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
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
#>
#> Balanced one-way analysis of variance power calculation
#>
#> groups = 4
#> n = 18.18245
#> between.var = 1
#> within.var = 3
#> sig.level = 0.05
#> power = 0.95
#>
#> NOTE: n is number in each group
#>
#> Balanced one-way analysis of variance power calculation
#>
#> k = 4
#> n = 18.18244
#> f = 0.5
#> sig.level = 0.05
#> power = 0.95
#>
#> NOTE: n is number in each group