Skip to content

Instantly share code, notes, and snippets.

@fditraglia
Created November 25, 2013 21:13
Show Gist options
  • Save fditraglia/7649005 to your computer and use it in GitHub Desktop.
Save fditraglia/7649005 to your computer and use it in GitHub Desktop.
R Code for Power Example from Lecture 22
coin.power <- function(a, p, n){
c <- qnorm(1 - a/2)
mu <- sqrt(n) * (2 * p - 1)
sigma <- sqrt(4 * p * (1 - p))
less.than <- pnorm( -c, mean = mu, sd = sigma)
greater.than <- 1 - pnorm(c, mean = mu, sd = sigma)
power <- less.than + greater.than
return(power)
}
coin.power(a = 0.05, p = 0.55, n = 100)
coin.power(a = 0.05, p = 0.55, n = 1000)
coin.power(a = 0.1, p = 0.55, n = 100)
coin.power(a = 0.05, p = 0.6, n = 100)
alternatives <- seq(from = 0, to = 1, by = 0.001)
power <- coin.power(a = 0.05, alternatives, n = 10)
plot(alternatives, power, xlab = 'True p', ylab = 'Power', type = 'l')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment