Smallest number of consecutive heads to infer the coin is not fair, with $p$-value less than $x$?

What is the smallest number $$k$$ of consecutive heads needed in order to infer that a given coin is not fair, with $$p$$-value less than $$x$$?

Null hypothesis: The coin is fair; ie. heads has probability $$0.5$$, tails has probability $$0.5$$.

Now, for any positive integer $$k$$, $$k$$ consecutive heads are as rare as $$k$$ consecutive tails, so, if our $$p$$-value is $$x$$, then $$x$$ needs to satisfy (assuming a 2-sided test):

$$0.5^k < x/2.$$

Solving for $$k$$, this yields:

$$k = {\log(x / 2) \over \log(0.5)}$$

Example.

• You need at least $${\log(0.05 / 2) \over \log(0.5)}$$, which is ~$$5.32$$ consecutive heads (or tails), in order to infer that the coin is not fair with a 2-sided $$p$$-value of $$0.05$$.
• You need at least $${\log(0.01 / 2) \over \log(0.5)}$$, which is ~$$7.64$$ consecutive heads (or tails), in order to infer that the coin is not fair with a 2-sided $$p$$-value of $$0.01$$.

Questions.

• Is this correct?

• Why must the null hyphothesis be the coin is fair? Why can't it be the coin is not fair? More generally, for every possible null hypothesis, is it equivalent to take its negation as the null hypothesis instead?

your reasoning is correct. To obtain a pvalue less than 5% you need at least $$5.32\approx 6$$ consecutive successes

You can visualize your result drawing a binomial distribution like the following

As you can see in the picture in the left, a Binomial $$Bin\left(5;\frac{1}{2}\right)$$ 5 consecutive successes are not enough to have a p-value of 5%; The p-value is the sum of the yellow bars, 6.25%.

In the right picture, a Binomial $$Bin\left(6;\frac{1}{2}\right)$$, 6 successes are enough giving a pvalue of about 3.13%

Why must the null hyphothesis be the coin is fair? Why can't it be the coin is not fair?

Because when calculating the pvalue you are solving the following probablity (S is the rejection region)

$$\mathbb{P}[\mathbf{x}\in S|H_0]=\alpha$$

thus if you set the null hypothesis as: the coin is fair you can substitute $$p=0.5$$ in your binomial; if you set the null hypothesis as: the coin is not fair which value of $$p$$ you use in a $$Bin(n;p)$$?

As you can see in the previous example there is no way to get exactly a p.value of 5%. If you want this you must apply a randomized test.