Solution (source code)

= Solution

Let $f_0,f_1$ be densities or probability mass functions relative to a common measure, describing two simple hypotheses. A randomized <hypothesis test> is a measurable function $0\leq\varphi\leq1$, whose value is the conditional rejection probability. Fix $0<\alpha<1$. The <Neyman-Pearson lemma> states that a test $\varphi_*$ with $\mathbb E_0\varphi_*=\alpha$ is most powerful among tests with size at most $\alpha$ if it rejects where $f_1>cf_0$, accepts where $f_1<cf_0$, and randomizes as necessary on equality, for a threshold $c\geq0$. Sets where $f_0=0<f_1$ are included in rejection. A <likelihood>-ratio quantile and boundary randomization supply such a test.

To prove optimality, let $\varphi$ be any competitor with $\mathbb E_0\varphi\leq\alpha$. Pointwise, the threshold rule makes
$$
(\varphi_*-\varphi)(f_1-cf_0)\geq0.
$$
Integrating and rearranging gives
$$
\mathbb E_1\varphi_*-\mathbb E_1\varphi
\geq c(\mathbb E_0\varphi_*-\mathbb E_0\varphi)\geq0.
$$
Thus no competitor of the permitted size has larger <statistical power>, proving the lemma. Randomization permits exact size when discrete observations cannot supply it with a deterministic rejection region.