Created
July 7, 2014 03:29
-
-
Save alyssafrazee/98ce52208ec61b28e9db to your computer and use it in GitHub Desktop.
quick binomial power calculations (simulated)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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