[Math] P-value of a test of binomial success probability

hypothesis testingstatistics

How do I get the $p$-value for tossing a coin 100 times with the result 30 Tails and 70 Heads for the null hypotheses $H_0=0.5$?
At best, a command in Matlab should be given to obtain this number, with a brief explanation of its derivation. Together with the result, i.e. whether we reject $H_0$.

Moreover, what is the power (= the parameter $\beta$) of the test?

Best Answer

Formulation of hypothesis and alternative. Your desired test is not completely specified until you state both the null and alternative hypotheses. It seems you have $n = 100$ independent tosses of a coin with $P(\text{Head}) = \theta.$ Perhaps your null hypothesis is $H_0: \theta = 1/2$ (fair coin), to be tested against the alternative $H_a: \theta > 1/2$ (biased in favor of Heads).

If the null hypothesis is true, then the expected number of heads in 100 tosses is 50, but you have observed 70. The question is whether 70 is so extremely greater than 50 that the null hypothesis should be rejected.

Exact P-value. The P-value in this this case is the probability of seeing a result as extreme or more extreme than the 70 Heads actually. This probability is computed under the the assumption that $H_0$ is true (fair coin).

The exact probability that $P(X \ge 70),$ where $X \sim Binom(100, 1/2),$ can be found by software. In R, the computation can be done as follows:

 1 - pbinom(69, 100, .5)
 ## 3.92507e-05

Thus the P-value is very small: 0.000039. One ordinarily rejects the null hypothesis $H_0$ against $H_a$ if the P-value is smaller than 0.05. Essentially, you have a choice of what to believe: either (a) the coin is fair and something very unlikely happened when you tossed it 100 times, or (b) the coin is not fair and that explains the extremely large number 70 of heads observed. The usual statistical judgment is the believe (b).

Normal approximation of P-value. Because $n = 100$ is a 'large' number of tosses, one could use a normal approximation to get the P-value, as follows: For $X \sim Binom(100, 1/2),$ we have $m = E(X) = 50$ and $\sigma^2 = V(X) = 25$ so that $\sigma = SD(X) = 5.$ Then

$$P(X \ge 70) \approx P\{Z = (X - 50)/5 \ge (70 - 50)/5 = 4\},$$

where $Z \sim Norm(0,1)$. From normal tables one can see that $P(X \ge 70) \approx P(Z \ge 4) \approx 0.\;$ So the P-value is again found to be extremely small, and $H_0$ is rejected in favor of the alternative $H_a.$

Required for power. You also ask about the power of this test. That requires you to select a particular alternative value $\theta_a.$ Perhaps you want to know the probability of rejecting $H_0,$ given that $P(\text{Heads}) = \theta_a = 0.60.$ In turn, that requires you to specify the significance level of your test, so that we know for which values of $X$ we will reject $H_0.$ If you supply the significance level $\alpha$ (perhaps 5%) and the alternative value $\theta_a$ you have in mind, then I (or someone else) can answer your question about the power of the test.

Addendum on power. You say you want the significance level to be $\alpha = 0.05.$ However, because the binomial distribution is discrete it is not possible to have exactly $\alpha = 0.05.$ $P(X \ge 59|\theta=1/2) = 0.0443$ and $P(X \ge 58|\theta=1/2) = 0.0666,$ so the closest we can get to $\alpha = 0.05$ is to use $\{X \ge 59\}$ as the rejection region and have $\alpha = 0.443.$

 1 - pbinom(58, 100, .5)
 ## 0.04431304
 1 - pbinom(57, 100, .5)
 ## 0.06660531
 sum(dbinom(59:100, 100, .5))
 ## 0.04431304
 sum(dbinom(58:100, 100, .5))
 ## 0.06660531

Then the 'power function' for various values of $\theta_a$ is found by evaluating $P(X \ge 59 | \theta_a)$ for various values of $\theta_a$. For example, the power against alternative $\theta_a = .60$ is $$P(\text{Reject } H_0 |\theta_a = .6) = P(X \ge 59 | \theta_a = .6) = 0.623.$$ This is computed in R using the binomial CDF 'pbinom'.

 1 - pbinom(58, 100, .60)
 ## 0.6225327

The left-hand panel of the figure below shows the null distribution (fair coin) with the critical value 59 cutting off $\alpha=4.43\%$ of the probability from the upper tail, and the right-hand panel shows power values against various values of $\theta_a,$ where the power against the specific alternative $\theta_a = 0.6$ is emphasized by a dotted line. The power against alternative values increases as the alternative values get farther from the null value $\theta_0 = 1/2.$

enter image description here

Related Question