Background:
A group at work is sampling 1,000 customers to contact and from that point, determining if the effort is worthwhile or not. I wanted to see if this (pretty much) arbitrary sample size value was at all "good enough".
If we assume that the true proportion of successes in a population is 0.016 (1.6%) how large a sample size would I need to take in order to get a confidence interval margin of error "half width") of say 0.005 (0.5%)? Here is my approach in R:
install.packages("Hmisc")
library(Hmisc)
target.halfWidth <- 0.005
sims <- 25000 #number of draws from binomial to perform
p <- 0.016 #true proportion
n <- seq(from=500, to=5000, by=100) #number of samples
#hold results
results <- matrix(numeric(0), length(n),2)
#loop through desired sample size options
for (i in 1: length(n))
{
x <- rbinom(sims, n[i], p) #draws from binomial with p and n
ci <- binconf(x, n[i] ,method="asymptotic", alpha=0.1) #normal theory 90% CI
half_width <- ci[,3]-ci[, 1] #half width of CI
#need the number where the half width is within the target range
prob.halfWidth <- length(half_width[half_width<target.halfWidth])/sims
#store results
results[i, 1] <- n[i]
results[i, 2] <- prob.halfWidth
}
#plot
plot(results[, 2], results[, 1], type="b")
results
This simulation showed that we would need 2,200 samples to be 95% confident that a 90% CI would be at most 0.005.
Questions:
Is this a proper method?
Are there better ways?
What advice can you give is there are finite samples of some sub-populations? Say that we want to know how many samples to take of populations where there are not "a lot" of customers to choose from. Maybe there is only 5,000 of a certain group, should we not be able to take less of them to make a determination compared to a group where there are 50,000 to choose from?
Added after MansT answer:
Would it make sense, under my scenario with the simulation draws to add a step where this line:
prob.halfWidth <- length(half_width[half_width
only increments the numerator when the resulting CI also contains the true p (i.e. 0.016)?
Under your code, would it also be appropriate when dealing with a finite sample to add the finite population corrector FPC to your line:
halfWidth <- qnorm(0.95)sqrt(p.est(1-p.est)/n)
I am not sure the formula for a CI from the hypergeometric, but perhaps I could replace my code line
ci <- binconf(x,n[i],method="asymptotic",alpha=0.1) #normal theory 90% CI
with Sprop function in R?