How many trials of flipping a coin are needed to be confident in getting very close to the same number of H/T

confidence intervalprobabilitystatistical-inferencestatistics

How many times one would need to flip a coin in order to be very confident of getting close to a $1:1$ ratio of Heads/Tails? By "very confident" I mean above $95$% sure, and by "close to a $1:1$ ratio" I'm thinking $55$%-$45$% H/T or T/H.

I'm running of a simulation where two engines are playing a game against each other, and I'm wondering after how many games I should stop the simulation and check their match score (if the score is close to equal after X number of games, I would infer the engines are most likely equal in strength).

I know this is a basic probability/statistics question, but I couldn't find a question addressing this anywhere else.

Best Answer

If you flip $n$ coins, the number of Tails follows a binomial distribution that you can approach with a normal distribution of parameters $\mu=\frac n2$ and $\sigma=\frac{\sqrt{n}}{2}$.

With this approximation, $95\%$ of the time the amount of Tails will fall within $1.96\sigma$ of $\mu$, so in the interval $[\frac {n-1.96\sqrt n}{2},\frac {n+1.96\sqrt n}{2}]$ and in these cases the ratio T/H will be between $\frac {n-1.96\sqrt n}{n+1.96\sqrt n}$ and $\frac {n+1.96\sqrt n}{n-1.96\sqrt n}$.

You want therefore to solve $$\frac {n-1.96\sqrt n}{n+1.96\sqrt n}\geq\frac{45}{55}$$ which is equivalent to $$10n\geq 196\sqrt n$$ and $$\sqrt n \geq 19.6$$ or finally $$n\geq 385$$

If you flip a fair coin at least $385$ times, you are $95\%$ certain to end up with a ratio $T/H$ between $\frac{45}{55}$ and $\frac{55}{45}$.

Related Question