# Binomial hypothesis test for $p_1 = p_2 = P$ without normal approximation

I was testing whether the proportion of successes from two populations is the same. It made me realize I only know how to do this with a normal approximation.

In particular, I would like to solve Exercise 9.3 from this set of exercises using a binomial distribution.

I understand that you may not feel like checking out my GitHub, so here's my problem in more general terms: suppose I flip a coin 100 times to test the hypothesis that the coin is unbiased. Instead of comparing the observed number of successes against the expected number of successes under $$H_0$$, I want to compare the observed proportion of successes against the expected proportion of successes. How can I test this without a normal approximation?

I found a post that suggests using Fisher's exact test. This is helpful in that it skips the normal approximation, but can this be done using a binomial test?

You have $$x = 705$$ successes in $$n = 929$$ failures, and you want to test $$H_0: p = 3/4$$ against $$H_a: p \ne 3/4,$$ at the 5% level. If $$H_0$$ is true, you expect about $$627$$ successes in $$929$$ trials. You will reject $$H_0$$ if the number $$x$$ of observed successes is far from $$627$$ in either direction.

Under $$H_0,$$ you have $$X \sim \mathsf{Binom}(n =929, p=3/4).$$ For a test at about the 5% level, you seek critical values $$c_1$$ and $$c_2$$ such that $$P(X \le c_1\,|\, H_0) + P(X \ge c_2 \,|\, H_0) \approx 0.05.$$

From R, where pbinom is a binomial CDF and qbinom is a binomial quantile function (inverse CDF), we have $$P(X \le 670\, |\,H_0) = 0.0243$$ and $$P(X \ge 723\, |\,H_0) = 0.0244,$$ so $$c_1 = 670, c_2 = 723$$ are suitable critical values.

qbinom(c(.025,.975), 929, 3/4)
 671 722
pbinom(670, 929, 3/4)
 0.02433703
1 - pbinom(722, 929, 3/4)
 0.02441926


Therefore, if we observe $$x = 705$$ successes, with $$c_1 = 670 < 705 < 723 = c_2,$$ we do not reject $$H_0.$$ x = 625:775;  PDF = dbinom(x, 929, 3/4)
hdr = "PDF of BINOM(929, 3/4) with Normal Approx."
plot(x, PDF, type = "h", col="blue", main=hdr)
abline(h=0, col="green2")
abline(v=c(670.5, 721.5), col="red")
mu = 929*.75;  sg = sqrt(929*.75*.25)

The approximating normal distribution to $$\mathsf{Binom}(n=929,p=3/4)$$ is $$\mathsf{Norm}(\mu=696.75, \sigma=13.20);$$ it provides a very close fit. With an approximate normal test, we would have used $$c_1=670,c_2=723.$$ which are not substantially different from the critical values of the exact normal test.
qnorm(c(.025,.975), mu, sg)