Skip to content

Instantly share code, notes, and snippets.

@cth
Created November 26, 2015 23:42
Show Gist options
  • Save cth/8db14aff7c354541c6f0 to your computer and use it in GitHub Desktop.
Save cth/8db14aff7c354541c6f0 to your computer and use it in GitHub Desktop.
## Very simple power calculation
## assuming a true odds ratio of 3.1
pick_eater_obese <- function(n) table(runif(n) < 109/(330+109))
pick_eater_control <- function(n) table(runif(n) < 37/(37+38))
#controls <- data.frame(pheno = rep(1000,"case"), runif(
p.values <- replicate(1000, fisher.test( matrix(c(pick_eater_obese(50),pick_eater_control(50)),2) )$p )
significance <- c(5e-1, 5e-2, 5e-3, 5e-4, 5e-5)
powers <- data.frame(significance, power = sapply(significance,function(x) mean(p.values < x)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment