I have a vector of 0s and 1s where a 0 is a failure and 1 is a success. Using a sample of this vector, I want to find the smallest sample such that I determine a probability of a success to be within 0.05 of the true probability. I want to be 95% confident of this, and I want to find the smallest sample size n by trial and error.
N = 30,000
p = 0.1
n is to be minimised such that probability of abs(p-p_estimate) < 0.05 is larger than 95%.
sample(x = c(0, 1), size = N, prob = c(1-p, p), replace = TRUE)
I thought I may be able to use a while loop, but I don't know how to manipulate it such that returns a minimum n. Any help would be appreciated