Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201945

How can I find the smallest possible sample size n to ensure my probability estimate is within 0.05 of the true probability using trial and error?

$
0
0

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


Viewing all articles
Browse latest Browse all 201945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>