# When can the level of the test be exactly $\alpha ?$ in non randomized test. And how to use CLT to find the critical value.

Let $$X_{1}, \ldots, X_{n}$$ be a sample from the Bernoulli distribution with parameter $$p$$ Consider testing $$H_{0}: p=p_{0}$$ versus $$H_{1}: p=p_{1}$$ where $$p_{0} are known numbers.
(a) Using the Neyman-Pearson lemma, find the most powerful test (Non-Randomized) among tests with level at most $$\alpha$$. When can the level of the test be exactly $$\alpha ?$$
(b) Use the CLT to find a critical value such that the level of the test is approximately (asymptotically for large $$n$$ ) $$\alpha$$.

To use Neyman Peason lemma I calculate $$r$$ as : $$r= \frac{f_1}{f_0} = \frac{p_1^{\Sigma x_i}(1-p_1)^{n-\Sigma x_i}}{p_0^{\Sigma x_i}(1-p_0)^{n-\Sigma x_i}}$$ For $$p_1>p_0$$ we have non randomized test is $$\phi(x) =$$ Reject $$H_0$$ for $$\Sigma x_i \geq k$$.
For given at most level $$\alpha$$ : $$\alpha \geq E_{p_0} \phi(x) = P_{p_0}\{\Sigma x_i \geq k\} = \Sigma_{r=k+1}^n (n_{C_r}) p_{0}^r (1-p_{0})^{n-r}$$

(a) I don't know how to proceed after this and what to say about When can the level of the test be exactly $$\alpha ?$$

(b) How to use CLT to find the critical value which satisfies the given condition.

I will get you started with couple of particular numerical examples that illustrate the main issues involved in a general answer.

Example 1. Let $$n = 10, p_0 = .5, p_1 = .7, \alpha = 0.5.$$ Then NP says to reject when $$T = \sum_{i=1}^{10}X_i \ge k.$$

The issue is to find $$k$$ so that $$\alpha \le 0.05.$$ Under $$H_0,$$ $$T \sim \mathsf{Binom}(n=10, p=.5).$$ Then using $$k = 8$$ would give $$\alpha = 0.0547 > 0.05,$$ so use $$k = 9$$ to get $$\alpha=0.0107 < 0.05.$$ Computations in R,

qbinom(.95, 10,.5)
 8
sum(dbinom(8:10, 10, .5))
 0.0546875
sum(dbinom(9:10, 10, .5))
 0.01074219


Thus, there is no nonrandomized test exactly at level $$\alpha = 0.05.$$

Under $$H_0,$$ we have $$E(T) = np = 5,$$ $$SD(T) = \sqrt{np(1-p)} = \sqrt{2.5} = 1.581.$$

So $$T\stackrel{aprx}{\sim}\mathsf{\mu=5, \sigma=\sqrt{2.5}}.$$ So an approximate value of $$k = 7.6.$$ This is not a good approximation for $$n$$ as small as $$n=10,$$ but this kind of approximation is useful for large $$n.$$

qnorm(.95, 5, sqrt(2.5))
 7.600742 t = 0:10;  pdf = dbinom(t, 10, .5)
plot(t, pdf, type="h", lwd = 3, col="blue")
abline(h=0, col="green2"); abline(v=0, col="green2")
abline(v = 8.5, lwd=2, lty="dotted")


Example 2. Now suppose $$n=100,$$ keeping the other parameters the same. Then we have $$T\sim\mathsf{Binom}(100, .5)$$ under $$H_0$$ and $$k = 59$$ gives a test at level $$\alpha = 0.044$$ and the normal approximation says to use $$k = 58.22.$$

qbinom(.95, 100, .5)
 58
sum(dbinom(58:100, 100, .5))
 0.06660531
sum(dbinom(59:100, 100, .5))
 0.04431304
qnorm(.95, 50, 5)
 58.22427 t = 0:100;  pdf = dbinom(t, 100, .5)
plot(t, pdf, type="h", col="blue")
abline(h=0, col="green2"); abline(v=0, col="green2")
abline(v = 58.5, lwd=2, lty="dotted")