R: Confidence Intervals - Proportions
m = 50; n=20; p = .5;
phat = rbinom(m,n,p)/n
SE = sqrt(phat*(1-phat)/n)
alpha = 0.10
zstar = qnorm(1-alpha/2)
matplot(rbind(phat - zstar*SE, phat + zstar*SE), rbind(1:m,1:m),type="l",lty=1)
abline(v=p) # draw line for p=0.5
#Notice, in particular, we get the 95% confidence interval (0.32, 0.52) by default. If we want a 90% confidence interval we need to ask for it:
x=prop.test(42,100,conf.level=0.90)
names(x)
prop.test(x, n, p = NULL, alternative = c("two.sided", "less", "greater"), conf.level = 0.95, correct = TRUE)
Arguments
n Number of observations (per group)
p1 probability in one group
p2 probability in other group
sig.level Significance level (Type I error probability)
power Power of test (1 minus Type II error probability)
alternative One- or two-sided test
strict Use strict interpretation in two-sided case
power.prop.test(n = 50, p1 = .50, p2 = .75)
power.prop.test(p1 = .50, p2 = .75, power = .90)
power.prop.test(n = 50, p1 = .5, power = .90)
functions: prop.test /