Aim:to compute the power of a study which aims to show a difference in means between group 1 (n=12) and group 2 (n=12) assuming that the magnitude of the difference is 0.3 units and the standard deviation is 0.28 units.

power.t.test(n=12,delta=0.3,sd=0.28,type="paired")
## 
##      Paired t test power calculation 
## 
##               n = 12
##           delta = 0.3
##              sd = 0.28
##       sig.level = 0.05
##           power = 0.9210877
##     alternative = two.sided
## 
## NOTE: n is number of *pairs*, sd is std.dev. of *differences* within pairs

Below plot shows how the sample size for fixed power ==80% (or power for fixed sample size) varies as a function of the difference between groups.

Coding Note: The functions power.prop.test and power.t.test can unfortunately not deal with a sequence of differences. Therefore use a loop (sapply).

Also, to show the effect of the hypothesized standard deviation we also show the required sample size when the standard deviation is only 0.3 instead of 0.8.

differences <- seq(from=0.1,to=2,by=0.1)
samplesize.sd04 <- sapply(differences,
                          function(d){power.t.test(power=0.8,
                                                   delta=d,
                                                   sd=0.7,
                                                   type="paired")$n})
samplesize.sd03 <- sapply(differences,
                          function(d){power.t.test(power=0.8,
                                                   delta=d,
                                                   sd=0.3,
                                                   type="paired")$n})
plot(differences,
     samplesize.sd04,
     xlim=c(0,2),
     xlab="Expected difference between groups",
     ylab="Required sample size",
     ylim=c(0,35),
     type="b",
     col="darkblue",
     lwd=5,axes=FALSE)
lines(differences, samplesize.sd03,col="turquoise",lwd=5,type="b")
axis(1,at=c(0,0.2,0.5,1,1.5,2))
axis(2,at=c(35,25,15,5,0))
legend(x="topright",lwd=5,bty="n",legend=c("SD=0.7","SD=0.3"),col=c("darkblue","turquoise"))