Deriving LRT for comparing two sample proportions I have two sample proportions, and want to test:
$$
H_0: p_1 = p_2 \quad \text{vs.} \quad H_a: p_1 \neq p_2
$$
i.e., that they really come from distributions with the same common probability $p$.
My goal is to show that a test can be based on the statistic
$$
T = \frac{\hat p_1 - \hat p_2}{\sqrt{(\frac{1}{n_1}+\frac{1}{n_2})\hat p(1-\hat p)}}
$$
where $\hat p_1$, $\hat p_2$, and $\hat p$ are the observed sample proportions for the first sample, second sample, and entire sample, respectively. I am trying to approach this using a likelihood ratio test, as follows.
Let $\mathbf x$ be the $n$ observations from sample 1 and $\mathbf y$ be the $m$ observations from sample 2. Then the LRT statistic is
\begin{align}
\lambda(\mathbf x,\mathbf y) &= \frac{\prod_i\hat p^{x_i}(1-\hat p)^{x_i}\prod_j\hat p^{x_j}(1-\hat p)^{x_j}}{\prod_i\hat p_1^{x_i}(1-\hat p_1)^{x_i}\prod_j\hat p_2^{x_j}(1-\hat p_2)^{x_j}} \\
&= \frac{\hat p^{\sum_i x_i + \sum_j y_j}(1-\hat p)^{n+m-\sum_i x_i-\sum_j y_j}}{\hat p_1^{\sum_i x_i}(1-\hat p_1)^{n-\sum_i x_i}\hat p_2^{\sum_j y_j}(1-\hat p_2)^{m-\sum_j y_j}}
\end{align}
Here I use the facts that $\hat p$ is the MLE for $p$ under $H_0$ and $\hat p_1, \hat p_2$ are the unrestricted MLEs for $p_1, p_2$ respectively.
However, now I am stuck, and I don't see any way to move forward to get something remotely close to the statistic $T$ above. Any help would be greatly appreciated!
 A: A test can be based on that statistic, but that statistic is based on a Normal approximation to the Binomial distribution.  The way to reach it is through the Normal, not the Binomial, distribution.
If we have two samples $y$ and $z$, and we hypothesize that the two are drawn from the same $N(\mu, \sigma)$ distribution, then it is well-known that the statistic:
$${\bar{y}-\bar{z} \over \sqrt{\left({1\over n_y} + {1 \over n_z}\right)s^2_{yz}}}$$
has a t-distribution with degrees of freedom $n_y + n_z - 1$.  ($s^2_{yz}$ is the sample variance of the joint sample.)  The resulting test is a likelihood ratio test for a difference between two means of Normally-distributed random samples with the same variance; a detailed derivation of this fact takes about six pages on the linked document:
 http://webpages.cs.luc.edu/~jdg/w3teaching/stat_305/sp11/twosamplelrtestsnormal.pdf, so I won't try to create even an abbreviated version here.
In this case, we can calculate $s^2_{yz}$ using the maximum likelihood estimator for the population variance of a binomial distribution: $\hat{p}(1-\hat{p})$.  This will give the same answer as calculating the sample variance with denominator $1/n$, but why calculate the sample variance if you don't have to?  Substituting $\hat{p}(1-\hat{p})$ for $s^2_{yz}$ gives the formula for the statistic in your question.
If you want a likelihood ratio test specifically for the Binomial distribution, working out its exact finite sample distribution seems pretty difficult.  You'll be simplifying the problem by using the asymptotic version, which is based on the fact that, asymptotically, $-2\ln L \sim \chi^2(1)$. where $L$ is the likelihood ratio with the null hypothesis likelihood in the denominator (the inverse of your $\lambda(x,y)$) and the "$1$" for the $\chi^2$ degrees of freedom is because the alternative hypothesis has one more parameter than the null hypothesis.
Which one of these tests is better in practice?  They are both approximations that get better as the sample size goes to $\infty$; the Normal approximation version is generally believed not to work well if either of the two samples has an expected number of successes $< 5$ or so, but that is just a heuristic.  Writing some code and running simulations seems like something that might be useful, but then again, if your sample sizes are reasonably large the test based on the Normal approximation will work just fine.
