# How many rolls to have a 90% chance of reaching average

I'm not a statistician, so not sure if I am wording this correctly, please bear with me.

Given an event, I expect success $X$ times out of $Y$, say $10$ out of a $100$. However, how do I calculate how many observations I need to make to reach the expected chance, say, $95\%$ of the time.

For example, I have a $10$-sided die, and am trying to roll a $1$. $1$ in $10$ times I expect to get $1$, but I won't necessarily get it exactly once in my first $10$ rolls. Or exactly twice in $20$ rolls. How do I calculate how many rolls it takes to reach the expected $10\%$, $95\%$ of the time? $99\%$ of the time?

• You want some number of rolls in which the proportion of 1s is exactly 10%? – gung - Reinstate Monica Jul 3 '16 at 16:21
• In your example, $\infty$ (and not even then). You need a hair cut below the expected value. – Mark L. Stone Jul 3 '16 at 16:21
• @gung, that's what I wanted, but now that I think about it, I guess practically you can only settle for within X% of ? – Kindread Jul 3 '16 at 16:26

## 3 Answers

You're looking for the binomial distribution, which has two parameters: n and p. The first is the number of rolls, the second is the probability that the desired event happens. So we have p locked to 0.1 (10%) and we can vary n.

The mean is np and the variance is np(1-p), and the standard deviation is the square root of the variance.

So there are two conflicting influences: as we increase the number of rolls, it becomes less and less likely that we'll get 10% exactly, because there are more and more possibilities. 1 out of 10 (39%) is more likely than 2 out of 20 (29%), which is likelier than 10 out of 100 (13%).

But as we increase the number of rolls, the square root (as a fraction of the mean) gets lower, so percentage of successes gets closer and closer to 95%; that is, if you build an interval around the mean that 95% of sample means will fall into, the lower and upper bound of that interval get closer and closer to 10%.

So get it exactly, the best shot you have is rolling 10 dice, and you're capped at 39%; if you want to get close, the more dice you roll the closer you'll get. (If you want to get at most a particular distance from the proportion with some probability, you can calculate how many dice you need to roll using the cumulative distribution function.)

Matthew Graves has done a nice job of addressing the question of getting an exact match between the sample mean and population mean. In his last sentence, he notes that if you only want an approximate match, you can use the binomial CDF. Here's an algorithm in Python:

from math import ceil, floor
from scipy.stats import binom

def how_many(theta, delta, confidence):
n = 1
while True:
x1, x2 = ceil(n*(theta - delta)), floor(n*(theta + delta))
if x1 <= x2:
p = binom.cdf(x2, n, theta) - binom.cdf(x1 - 1, n, theta)
if p >= confidence:
break
n += 1
return (n, p)

how_many(theta, delta, confidence) tells you how many trials you would need when the population chance of success is theta and you want the sample mean to be within delta units of theta with probability confidence. For example, how_many(theta = .1, delta = .05, confidence = .9) returns 80, so when the true probability of success is .1, 80 trials are needed for a 90% probability of the sample mean to land inside [.05, .15].

This question is only marginally related to statistics, but is really a mathematical problem, a variation of a one-dimensional random walk.

If an event happens with a probability of exactly 10%, then the expected number of successes in 10 observation is exactly 1, so after 10, 20, 30 etc. observations it is possible that the number of successes matches the expected number of successes exactly. If the probability were for example exactly 10.03%, then an exact match would only be possible for the first time after 10,000 observations with exactly 1,003 successes. If the probability were π percent, then an exact match would be impossible.

If I understand you correctly: If you rolled a 10 sided dice for example 100 times, you would have ten opportunities that the number of successes matches the expected number exactly, after 10, 20, 30, ..., 100 dice rolls, and you are asking for the probability that this happened at least once.

Using the binomial distribution formula, you can calculate the probability that in ten rolls you have 0 successes (34.8678%), 1 success (38.7420%), 2 successes (19.3710%), 3 successes (5.7396%), 4 sucesses (1.1160%), 5 successes (0.1488%), 6 successes (0.0138%), 7 successes (0.0009%) or more (< 0.0001%).

Using the binomial distribution formula, you could also calculate quite easily the probability that after 10, 20, 30 ... rolls you have exactly the expected number of success, but that's not what you are asking for. You are asking for example for the probability that after 100 rolls, you have the exact right number of rolls at least once.

There's no simple formula for that. You can calculate that your chance is 38.7420% for an exact match after 10 rolls, 13.5085% for the first exact match after 20 rolls (either 0 success followed by 2 successes, or the other way round), 7.3269% for the first exact match after 30 rolls ((0,0,3) or (0,1,2) or (0,3,0) or (2,1,0) successes) and so on; a spreadsheet program will find the numbers that you want.

The name "random walk" comes from the fact that after every ten throws, the difference (expected number of success minus actual number of success) will randomly change. From memory, I believe in the one dimensional case you will always eventually get an exact match, but the expected number of throws for that is not limited. In the two dimensional case (that is if you had two dice and waited until they both simultaneously give an exact match) the probability that this happens eventually is less than once; again from memory the proof requires some rather hairy application of Fourier analysis.

The reason why it may take very long to get an exact match: Assume you rolled dice for some rather long time and you have 100 successes more than expected, which will happen sometimes. Now you continue rolling dice until the number of successes compared to the expected number changes by 100 again. Your chances are equal that the number is now exactly right, or that you have 200 successes more than expected. In the latter case it will take a lot more rolls to change that number either to 0 or 400, and so on.

• I've accepted Matthew Graves answer, but this was a very well written explanation as well. – Kindread Jul 4 '16 at 9:52