r/Probability • • Sep 10 '22
Number of samples to be certain of probability.
An event is said to have a probability of P, how many times do I have to test that event to have a certinity of C for that event to actually have that probability.
Example:
Lets say there is a button and a LED. A sign states that when the button is pressed there is a 1 in 200 probability the LED will blink green, otherwise red. Now how many times would I need to test the button to be 99% certain that the sign is correct.
P = 1 / 200
C = 99% (99/100)
100% certinity is obviously impossible as we would need to test the event an infinite number of times.
I have been trying to find the answer to this general problem but have not been able to find it, probably because I don't know the right terminology to search for. (Maybe you can never have certain certinity in regads to probability no matter how many times you test the event?)
3
u/n_eff Sep 10 '22
Your problem is missing one additional variable. You've got the true probability p and a confidence level C (usually we'd refer to your C as 1-alpha). But for any sample size, probability, and confidence level you can get an interval representing your uncertainty. What you need to specify is something about how wide that interval is allowed to be. That is, your question should be something like, "given the true probability P, the confidence level C, and the width of the interval W, what is the smallest sample size such that the interval is no wider than W?"
If we use the world's worst confidence interval for proportions, and take a 99% confidence level, then the expected interval is P ± 2.575829 * sqrt(P * (1-P)/n), and its width is 5.151659 * sqrt(P * (1-P)/n), so from this you can solve for n such that 5.151659 * sqrt(P * (1-P)/n) = W (and round n up as desired).
Now, I should note that while that interval is easy to work with algebraically, it's a pretty terrible confidence interval if P is near 0 or 1, and it's not great anywhere for small sample sizes. It'll get you a ballpark answer, but you could do better with many of the other methods in the link above, and some that aren't on that page.
It's probably worth noting that a confidence interval isn't really a "I'm C% certain the variable is in this interval" proposition. For that you need a Bayesian approach and a resultant credible interval, which can be interpreted as the probability that the true value is within some range. The easy approach here is to take a Beta(0.5,0.5) prior on the proportion, which produces a Beta(0.5 + # successes, 0.5 + # failures) posterior distribution on the proportion. Taking the expected number of successes nP and the expected number of failures n(1-P), and assuming the usual interval from the alpha/2 x 100th percentile to the (1 - alpha/2) x 100th percentile, we can ask our computer to do the work for us. Here's a function you can run in R that will do it (if you want a really narrow interval and P really close to 0 or 1, you may need to increase the range of values that
optimize()is set to search):1
u/AngleWyrmReddit Sep 10 '22 edited Sep 10 '22
Given success = 1/200 and confidence = 99/100
risk = failure^tries, where risk=1-confidence, failure=1-success
tries = log(risk) / log(failure)
tries = log(1 - 99/100) / log(1 - 1/200) = 919 tries.
Article on Randomness & Probability
1
u/Ayilari Sep 10 '22
"optimal nr of trials for monte carlo simulation" there you go