Skip to content

Instantly share code, notes, and snippets.

@alyssafrazee
Created July 7, 2014 03:29
Show Gist options
  • Save alyssafrazee/98ce52208ec61b28e9db to your computer and use it in GitHub Desktop.
Save alyssafrazee/98ce52208ec61b28e9db to your computer and use it in GitHub Desktop.
quick binomial power calculations (simulated)
# power calculation examples
get_power = function(truep, p0, n, alpha=0.05) {
num_rejections = 0
for(i in 1:10000){
dat = rbinom(n, size=1, prob=truep)
pv = 2*(1-pbinom(sum(dat), size=n, prob=p0))
if(pv < alpha) num_rejections = num_rejections + 1
}
return(num_rejections / 10000)
}
get_power(0.7, 0.5, 10)
get_power(0.7, 0.5, 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment