Power analysis is a part of planning analysis for experimental design. It is usually used to determine the minimum sample size required to detect a specified effect with a power level confidence, simultaneously with no larger than a significant level which wrongly reject and affirm the effect when it actually does not exist. There are four parts connected to a power analysis. They are sample size, effect size, power which is 1 – Type 2 error, and significant level which is Type 1 error in a hypothesis testing process. One of them can be calculated from the known values of the other three.
In R programming, power analysis is usually implemented with functions in pwr package. For a t-test, the power analysis function is pwr.t.test(n=, d=, sig.level=, power=, alternative=), in which
n is sample size, d is effect, sig.level is significant level and power is power, and alternative represents the hypothesis testing is two-sized or one-sized. For a independent sample t-test problem, effect can be calculated as the mean difference between samples divided by the pooled sample standard error.
Next we will show an example of power analysis for t-test in R.
#Say we want to carry out an experiment for testing medicine effect
#between group treated and placebo. Say different of 0.1 is quite important
#and earlier cases show that pooling standard deviation is 1.2. How many sample will
#the experiment require to 90% confidently detect such effect, and simultaneously #95% the probability that will not wrongly say it has such a effect when it actually #has no effect present?
library(pwr)
pwr.t.test(d=.83, sig.level=.05, power=.85, type="two.sample",
alternative="two.sided")
#result
Two-sample t test power calculation
n = 27.06182
d = 0.83
sig.level = 0.05
power = 0.85
alternative = two.sided
NOTE: n is number in *each* group
Results say that you need at least 27 observations in each group (55 in total) to have 85% of the power to detect such effect and not wrongly saying the effect exists when actually it does not.
0 Comments