Skip to content

Instantly share code, notes, and snippets.

@richarddmorey
Created March 29, 2015 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddmorey/4f808b875ab370cfd243 to your computer and use it in GitHub Desktop.
Save richarddmorey/4f808b875ab370cfd243 to your computer and use it in GitHub Desktop.
M = 10000 # Number of sims
power = .5 # power
## Binomial (fixed N)
N1 = rpois(M,2) + 1 ## random choice for N
X1 = rbinom(M,N1,power) ## Perform studies
mean(X1 / N1)
sd(X1 / N1)
## Notice above that, as expected, expected prop.
## of significant studies is power
## Geometric (stop with single nonsig. result)
X2 = rgeom(M,1-power)
N2 = X2 + 1
# show power
sum(X2) / sum(N2)
# However, expected proportion sig. is < .5 !
mean(X2 / N2)
sd(X2 / N2)
## Interestingly, the expected proportion of sig.
## studies is *less than* the power!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment