Skip to content

Instantly share code, notes, and snippets.

@davharris
Created February 13, 2015 21:21
Show Gist options
  • Save davharris/99652949393224803709 to your computer and use it in GitHub Desktop.
Save davharris/99652949393224803709 to your computer and use it in GitHub Desktop.
n = 10
delta = 0.1
sd = 1
# Calculate power with n and delta
power.t.test(n = n, delta = delta, sd = 1, type = "one.sample") # ~5% power
# Run 10,000 t.tests
p = replicate(1E4, t.test(rnorm(n, mean = delta, sd = 1))$p.value)
mean(p < .025 | p > .975) # reject ~5.2% of the time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment