以两组随机对照试验为例:

delta:预计干预后干预与对照的差值
sigma:预计的标准差
d:预计的效应量effect size
n:样本量

公式:

$$n=\frac{4(Z_\alpha+Z_\beta)^2\sigma^2}{\Delta^2}$$

library('pwr')

delta <- 3
sigma <- 5
d <- delta/sigma
pwr.t.test(d=d, sig.level=.05, power = .90, type = 'two.sample')

输出结果:


     Two-sample t test power calculation 

              n = 59.35155
              d = 0.6
      sig.level = 0.05
          power = 0.9
    alternative = two.sided

NOTE: n is number in *each* group

参考文献:https://www.r-bloggers.com/calculating-required-sample-size-in-r-and-sas/