R data analysis examples
功效分析
power analysis for one-sample t-test单样本t检验
例1.一批电灯泡,标准寿命850小时,标准偏差50,40小时的差值是巨大的,此研究设定效应值d=
(850-810)/50,希望有90%的可能检测到,即功效值为0.9,还希望有95%的把握不误报显著差异,
问需要多少支电灯泡。
H0=850,HA=810
library('pwr')
pwr.t.test(d=(850-810)/50,power=0.9,sig.level=0.05,type="one.sample",alternative = 'two.sided')
One-sample t test power calculation
n = 18.44623
d = 0.8
sig.level = 0.05
power = 0.9
alternative = two.sided
结果说明需要19支灯泡去拒绝H0,并保证在HA下有达到0.9的功效
然后,如果我们只取10支电灯泡,会达到什么程度的功效水平呢?
pwr.t.test(d=(850-810)/50,n=10,sig.level=0.05,type="one.sample",alternative = 'two.sided')
One-sample t test power calculation
n = 10
d = 0.8
sig.level = 0.05
power = 0.6162328
alternative = two.sided
结果功效只有0.616。那麽如果选15支呢?
pwr.t.test(d=(850-810)/50,n=15,sig.level=0.05,type="one.sample",alternative = 'two.sided')
One-sample t test power calculation
n = 15
d = 0.8
sig.level = 0.05
power = 0.8213105
alternative = two.sided
power=0.821,你将有18%的可能错过你要寻找的效应值
取样20支,
pwr.t.test(d=(850-810)/50,n=20,sig.level=0.05,type="one.sample",alternative = 'two.sided')
One-sample t test power calculation
n = 20
d = 0.8
sig.level = 0.05
power = 0.9238988
alternative = two.sided
功效为0.924 大于n=19时的功效0.9
结论,取样n增大,相应功效power也会增大
下面改变标准差
pwr.t.test(d=(850-810)/30,power=0.8,sig.level=0.05,type="one.sample",alternative = 'two.sided')
One-sample t test power calculation
One-sample t test power calculation
n = 6.581121
d = 1.333333
sig.level = 0.05
power = 0.8
alternative = two.sided
所需的取样量减少
下面我们再讨论一下the effect size
pwr.t.test(d=(50-10)/50,power=0.9,sig.level=0.05,type="one.sample",alternative="two.sided")
One-sample t test power calculation
n = 18.44623
d = 0.8
sig.level = 0.05
power = 0.9
alternative = two.sided
n=18.44623
pwr.t.test(d=(1-.2),power=0.9,sig.level=0.05,type="one.sample",alternative="two.sided")
One-sample t test power calculation
n = 18.44623
d = 0.8
sig.level = 0.05
power = 0.9
alternative = two.sided
n=18.44623
可以看到 结果这3个实验的结果n 相等。但是去决定 the true effect size并不简单。一个
正确的the effect size的估值是成功的功效分析的关键。