File: power.R

package info (click to toggle)
r-cran-statmod 1.4.20-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 332 kB
  • ctags: 13
  • sloc: fortran: 75; makefile: 3
file content (13 lines) | stat: -rw-r--r-- 482 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
power.fisher.test <- function(p1,p2,n1,n2,alpha=0.05,nsim=100,alternative="two.sided") {
#	Calculation of power for Fisher's exact test for
#	comparing two proportions
#	Gordon smyth
#	3 June 2003.  Revised 19 Nov 2011.

	y1 <- rbinom(nsim,size=n1,prob=p1)
	y2 <- rbinom(nsim,size=n2,prob=p2)
	y <- cbind(y1,n1-y1,y2,n2-y2)
	p.value <- rep(0,nsim)
	for (i in 1:nsim) p.value[i] <- fisher.test(matrix(y[i,],2,2),alternative=alternative)$p.value
	mean(p.value < alpha)
}