Derive the sample size $n$ to achieve $P(\text{type 2 error}) = \beta$ for a two-tailed test

hypothesis testingstatistics

Consider testing $H_0 : \mu = \mu_0$ vs $H_a : \mu \neq \mu_0$ at level $\alpha$. We then wish to control for the type II error, that is have $P(\text{type II error} \ | \ \mu = \mu_1) = \beta$ for a predetermined $\beta$

Assume $\bar{X}$ is approximately normal with mean $\mu$ and standard deviation $\sigma / \sqrt{n}$. Base a hypothesis test on the standardized variable $Z = \frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}}$, where $\bar{X} = \frac{1}{n} \sum_{i=1}^n X_i$

Then the power function is

$\gamma(\mu) = P(\text{reject} \ H_0 \ | \ \mu)
= P(\frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}} \geq -z_{\alpha/2} \ \text{or} \ \frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}} \leq z_{\alpha/2} \ | \ \mu)$

$= P(\frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}} \geq -z_{\alpha/2} \ | \ \mu) + P(\frac{\bar{X}-\mu_0}{\sigma/\sqrt{n}} \leq z_{\alpha/2} \ | \ \mu) = 1-\Phi(z_{\alpha/2} + \frac{\mu_0-\mu}{\sigma/\sqrt{n}}) + \Phi(-z_{\alpha/2} + \frac{\mu_0-\mu}{\sigma/\sqrt{n}})$

where we have solved the inequalities for $\bar{X}$ and restandardized with $\mu_1$.

Then, for $\mu_1 \neq \mu_0$,

$P(\text{type II error} \ | \ \mu=\mu_1) = P(\text{don't reject} \ H_0 \ | \ \mu=\mu_1)$
$=1 – P(\text{reject} \ H_0 \ | \ \mu=\mu_1) = 1 – (1-\Phi(z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}}) + \Phi(-z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}}))$
$= \Phi(z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}}) + \Phi(-z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}})$

$ = \beta$

How to solve this for $n$? The answer is supposed to be $n = \bigg(\frac{\sigma (z_{\alpha/2} + z_{\beta})}{\mu_0 – \mu_1}\bigg)^2$ (see Devore & Berk, Modern Mathematical Statistics with Applications, 2012: page 441)

Sidenote: The way I solved it in the one-tailed case was simply by doing

$\Phi(z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}}) = \beta$

$\Phi^{-1}\Phi(z_{\alpha/2} + \frac{\mu_0-\mu_1}{\sigma/\sqrt{n}}) = \Phi^{-1}\beta = -z_\beta$, etc

Best Answer

The approximated solution can be derived as below.

\begin{align*} & {\qquad} 1-\beta = \gamma(\mu) \\ & {\qquad} = 1 + \Phi \left( k-z_{\alpha/2} \right) - \Phi \left( k+z_{\alpha/2} \right), \quad \mbox{where} \quad k := \frac{\mu_0-\mu}{\sigma/\sqrt{n}} \\ & {\qquad} = P(Z \ge z_{\alpha/2}-|k|) + P(Z \ge z_{\alpha/2}+|k|) \\ \Rightarrow & {\qquad} 1-\beta \approx P(Z \ge z_{\alpha/2}-|k|), \quad \mbox{assuming} \quad P(Z \ge z_{\alpha/2}+|k|) \approx 0 \\ \iff & {\qquad} z_{1-\beta} \approx z_{\alpha/2}-|k| \\ \iff & {\quad} -z_{\beta} \approx z_{\alpha/2}-|k| \\ \iff & {\quad} |k| \approx z_{\alpha/2}+z_{\beta}, \end{align*} this gives $$ n \approx \left[ \frac{\sigma(z_{\beta} + z_{\alpha/2})} {\mu_0-\mu} \right]^2, $$ as desired.

Related Question