Hypothesis Testing
Published in Winter, 2025
There are two types of errors: Type one error is when $\mathcal{H}_0$ is rejected when $\mathcal{H}_0$ is indeed true; Type two error is $\mathcal{H}_0$ is not rejected when $\mathcal{H}_1$ is indeed true.
Example: Suppose we have a random sample $X_1,\cdots,X_n \sim N(\mu,1)$, and $\mu = { 0,1}$. So we would like to test that $\mathcal{H}_0 : \mu = 0$ and $\mathcal{H}_1: \mu=1$.
To use NP lemma, we first construct the ratio:
\[\begin{align*} \frac{p(\vec x, \mu=1)}{p(\vec x,\mu=0)} = \frac{\left(\frac{1}{\sqrt{2\pi}}\right)^n \exp \left\{ -\frac{1}{2} \sum(x_i-1)^2\right\}}{\left(\frac{1}{\sqrt{2\pi}}\right)^n \exp \left\{ -\frac{1}{2} \sum(x_i)^2\right\}} = e^{-\frac{1}{2}\sum(x_i-1)^2+\frac{1}{2}\sum x_i^2} = e^{n\overline{X}_n - n/2} \end{align*}\]Then the NP lemma says that we will reject $\mathcal{H}_0$ if $\displaystyle{\frac{p(\vec x,\mu=1)}{p(\vec x,\mu=0)}} > k$ for some $k$, so we solve for $e^{n\overline{X}_n - n/2}>k$, and we get $\overline{x}_n >k^* = \frac{\ln k}{n} +\frac{1}{2}$, and this is the rejection region. Now given significance level $\alpha$, the type one error is given by
\[P(\text{Reject $\mathcal{H}_0$ when it is true}) = P(\overline{x}_n >k \big\vert \mu=0) = \alpha.\]Then we use the fact that $\displaystyle{\overline{X}_n \sim N\left(0,\frac{1}{n} \right)}$ (the case when $\mathcal{H}_0$ is true), and we have
\[P\left(\frac{\sqrt{n} (\overline{X}_n - 0)}{1} > \sqrt{n} k^* \right) = \alpha\]and then we can refer to the normal table to solve for $k^*$. The same idea applies for type two error, where in this case we have
\[P(\text{Not rejecting $\mathcal{H}_0$ when it is false)} = P(\overline{x}_n < k^* \big\vert \mu=1).\]Also, we have a general formula to solve for hypothesis testing. We list some cases here:
- Testing the Mean in a (Asymptotically) Normal Sample with Known Variance
Suppose we know the random sample takes the form $N(\mu,\sigma^2)$ where $\sigma^2$ is known, and we wish to test:
\[\mathcal{H}_0 : \mu = \mu_0 , \mathcal{H}_1: \mu \neq \mu_0 (\mu >\mu_0) (\mu <\mu_0)\]and we first compute the value under the null hypothesis:
\[z=\frac{\sqrt{n}(\overline{x}_n - \mu_0)}{\sigma} \hspace{0.2cm} \text{In a large sample we may replace $(\sigma$ by $s_n$)}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if:
\[\vert z\vert > z_{\alpha/2} (z>z_{\alpha})(z<-z_{\alpha}).\]- Testing the Mean in a Normal Sample with Unknown Variance
Suppose we know the random sample takes the form $N(\mu,\sigma^2)$ where $\sigma^2$ is unknown, and we wish to test:
\[\mathcal{H}_0 : \mu = \mu_0 , \mathcal{H}_1: \mu \neq \mu_0 (\mu >\mu_0) (\mu <\mu_0)\]and we first compute the value under the null hypothesis:
\[t=\frac{\sqrt{n}(\overline{x}_n - \mu_0)}{s_n} \hspace{0.2cm}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if:
\[\vert t\vert > t_{\alpha/2,n-1} (t>t_{\alpha,n-1})(t<-t_{\alpha,n-1}).\]- Testing the Variance in a Normal Sample with Unknown Mean and Variance
Suppose we know the random sample takes the form $N(\mu,\sigma^2)$ where $\mu,\sigma^2$ is unknown, and we wish to test:
\[\mathcal{H}_0 : \sigma^2 = \sigma_0^2 , \mathcal{H}_1: \sigma^2 \neq \sigma_0^2 (\sigma^2 >\sigma_0^2) (\sigma^2 <\sigma^2_0)\]and we first compute the value under the null hypothesis:
\[\chi=\frac{(n-1)s^2}{\sigma_0^2} \hspace{0.2cm}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if:
\[\chi^2 > \chi^2_{\alpha/2,n-1} \text{or} <\chi^2_{1-\alpha/2,n-1} (\chi^2 > \chi^2_{\alpha,n-1})(\chi^2<\chi^2_{1-\alpha,n-1})\]- Testing the Ratio in a Bernoulli Sample
Suppose we know the random sample takes the form $Bernoulli(\theta)$ where $\theta$ is unknown, and we wish to test:
\[\mathcal{H}_0 : \theta=\theta_0 , \mathcal{H}_1:\theta \neq \theta_0 (\theta>\theta_0)(\theta<\theta_0)\]and we first compute the value under the null hypothesis:
\[z = \frac{\hat\theta -\theta_0}{\displaystyle{\sqrt{\frac{\theta_0(1-\theta_0)}{n}}}}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if:
\[\vert z\vert > z_{\alpha/2} (z>z_{\alpha})(z<-z_{\alpha}).\]- Testing the Difference in Mean of Two Bernoulli Samples
Suppose we have two mutually independent large random samples $(\geq25)$ $X_1,\cdots,X_m \sim Bernoulli(\theta_1)$ and $Y_1,\cdots,Y_n \sim Bernoulli(\theta_2)$, and we wish to test
\[\mathcal{H}_0: \theta_1-\theta_2=D_0 ; \mathcal{H}_1: \theta_1-\theta_2 \neq D_0(\theta_1-\theta_2 > D_0)(\theta_1-\theta_2<D_0)\]and we first compute the value under the null hypothesis:
If $D_0 = 0$, then
\[z = \frac{\hat\theta_1-\hat\theta_2}{\displaystyle{\sqrt{\frac{\hat\theta(1-\hat\theta)}{m}+\frac{\hat\theta(1-\hat\theta)}{n}}}}, \hat\theta=\frac{x+y}{m+n}, \text{where $x/m = \hat\theta_1, y/n = \hat\theta_2$}\]If $D_0 \neq 0$, then
\[z = \frac{\hat\theta_1-\hat\theta_2-D_0}{\displaystyle{\sqrt{\frac{\hat\theta_1(1-\hat\theta_1)}{m}+\frac{\hat\theta_2(1-\hat\theta_2)}{n}}}}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if
\[\vert z\vert > z_{\alpha/2} (z>z_{\alpha})(z<z_{\alpha}).\]- Testing the Difference in Mean of Two Normal Samples with Known Variance
Suppose we have two mutually independent large samples $(>25)$ $X_1,\cdots,X_m \sim N(\mu_1,\sigma_1^2)$ and $Y_1,\cdots,Y_n \sim N(\mu,\sigma_2^2)$ where $\sigma_1,\sigma_2$ are known. We wish to test
\[\mathcal{H}_0: \mu_1-\mu_2 = D_0 ; \mathcal{H}_1 : \mu_1-\mu_2 \neq D_0 (\mu_1-\mu_2 > D_0)(\mu_1-\mu_2 < D_0)\]We first compute the value under the null hypothesis:
\[z = \frac{\overline{x}_m - \overline{y}_n - D_0}{\displaystyle{\sqrt{\frac{\sigma_1^2}{m}+\frac{\sigma_2^2}{n}}}}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if
\[\vert z\vert > z_{\alpha/2} (z>z_{\alpha})(z<-z_{\alpha})\]- Testing the Difference in Mean of Two Normal Samples with Unknown Variance
Suppose we have two mutually independent large samples $(>25)$ $X_1,\cdots,X_m \sim N(\mu_1,\sigma_1^2)$ and $Y_1,\cdots,Y_n \sim N(\mu,\sigma_2^2)$ where $\sigma_1,\sigma_2$ are unknown, but we have $\sigma_1^2 = \sigma_2^2$. We wish to test
\[\mathcal{H}_0: \mu_1-\mu_2 = D_0 ; \mathcal{H}_1 : \mu_1-\mu_2 \neq D_0 (\mu_1-\mu_2 > D_0)(\mu_1-\mu_2 < D_0)\]We first compute the value under the null hypothesis:
\[t = \frac{\overline{x}_m - \overline{y}_n - D_0}{s_p\displaystyle{\sqrt{\frac{1}{m}+\frac{1}{n}}}}, s_p^2 = \frac{(m-1)s_m^2+(n-1)s_n^2}{m+n-2}\]and we will reject $\mathcal{H}_0$ at significance level $\alpha$ if
\[\vert t\vert > t_{\alpha/2,m+n-2} (t>t_{\alpha,m+n-2})(t<-t_{\alpha,m+n-2})\]Now I have listed a bunch of exercises, do it carefully, and identify which of the above $7$ cases! The values of $z,t,\chi$ can all be found in the standard table.
A general approach is that, we always make null hypothesis to be simple, i.e it is equal to something. So $\mathcal{H}_0 : \mu=550$. Also we want to see if its the weight has been reduced, so we make the alternative hypothesis to be $\mathcal{H}_1 : \mu<550$. Then according to the table, here both $\mu,\sigma$ unknown, we compute the value under the null hypothesis $\mathcal{H}_0$ first:
\[t = \frac{\overline{x} - \mu_0}{s/\sqrt{12}} = \frac{535.7-550}{37.8/\sqrt{12}} = -1.310493468\]now, in order to reject $\mathcal{H}0$ under level $\alpha$, we need $t < -t_{\alpha, n-1}$, which according to the $t$-table we have $t_{0.05,11} = 1.796$, where we have $-1.31049 > -1.796$, hence we do not reject $\mathcal{H}_0$, so at significance level $\alpha=0.05$, we do not see any evidence that the mean weight is less than $550$ pounds.
Here, we have a similar case as the previous exercise: We’re in a normal random sample with both $\mu$, $\sigma^2$ unknown. So let $\mathcal{H}_0 : \mu = 1000$ and $\mathcal{H}_1 := \mu \neq 1000$. So again we compute the value under $\mathcal{H}_0$, we have
\[t = \frac{\overline{x} - \mu_0}{s/\sqrt{21}} = \frac{927.43-1000}{154.45/\sqrt{21}} = -2.153\]now in order to reject $\mathcal{H}0$ under level $\alpha$, we need $\vert t\vert > t_{\alpha/2.n-1} $ and from the $t$-table we have $t_{\alpha/2 , n-1} = t_{0.025,20} = 2.086$, and since we do have $\vert t\vert = 2.153 > 2.086$, we will hence reject $\mathcal{H}_0$ and in favor of $\mathcal{H}_1$, that is, there is evidence that the mean water usage is different from $1$ million liter per day.
In this example, we have two mutually independent random samples, and we design $\mathcal{H}_0 : \mu_1 -\mu_2 = 0$ while $\mathcal{H}_1 : \mu_1-\mu_2 \neq 0$, and in this two samples we have $\sigma_1^2=\sigma_2^2$ unknown, so we first compute the value under the null hypothesis, which is
\[t = \frac{\overline{x}_n - \overline{y}_m - 0}{s_p \cdot \sqrt{\frac{1}{n}+\frac{1}{m}}} , s_p^2 = \frac{(n-1)s_n^2+(m-1)s_m^2}{n+m-2}\]where we compute $\displaystyle{s_p = \sqrt{\frac{9\times0.017^2 + 12\times 0.006^2}{10+13-2}} = 0.012}$, and we have
\[t = \frac{0.041-0.026}{0.012\times\sqrt{\frac{1}{10}+\frac{1}{13}}} = 2.97178\]while we will reject $\mathcal{H}0$ if $\vert t\vert >t_{\alpha/2, n+m-2} = t_{0.025,21 } = 2.08$, which we see that clearly we should reject $\mathcal{H}_0$, meaning that the amount of DDT in juveniles and nestlings are not the same.
In this example, we will first compute the value under the null hypothesis $\mathcal{H}_0$:
\[\chi^2 = \frac{(n-1)s^2}{\sigma_0^2} = \frac{9\times0.0003}{0.0002} = 13.5\]In this case we will reject $\mathcal{H}0$ if we have $\chi^2 > \chi^2{\alpha,n-1} = \chi^2{0.05,9} = 16.918$, where we see that we do not satisfy this condition, and hence we will not reject $\mathcal{H}0$, and we conclude that at significance level $\alpha=0.05$, we do not have much information that $\sigma^2>0.0002$.
In this example, we will test $\mathcal{H}_0 : \sigma^2 = 4$ and $\mathcal{H}_1:\sigma^2\neq 4$. Note that standard deviation is $\sigma$!!!. In this normal sample with both mean and variance unknown, we first compute the value under the null hypothesis $\mathcal{H}_0$:
\[\chi^2 = \frac{(n-1)s^2}{\sigma_0^2} = \frac{15\times6.1}{4} = 22.875\]Under this condition we will reject $\mathcal{H}0$ if
\[\chi^2 > \chi^2_{\alpha/2,n-1}\]or
\[\chi^2 <\chi^2_{1-\alpha/2,n-1}\]Here we have $\alpha=0.05, n-1=15$, and $\chi{0.025,15}^2 = 27.48839$ and $\chi{0.975,15}^2=6.26214$, and we see that $\chi^2$ do not satisfy any of these two conditions, so we will not reject $\mathcal{H}0$, at significance level $0.05$.
Here since we have a large sample so we could use a normal approximation for this sample. We will test $\mathcal{H}_0 : \mu = 15$ and $\mathcal{H}_1 : \mu>15$. We first compute the value under the null hypothesis:
\[t = \frac{\overline{x} - \mu_0}{s/\sqrt{n}} = \frac{19.3-15}{11.9/\sqrt{46}} = 2.4507\]We will reject $\mathcal{H}0$ if $t > t_{\alpha,n-1} = t_{0.01,45} = 2.326$, where we will reject $\mathcal{H}_0$ under this case, at a significance level $\alpha=0.01$.
This one is similiar to the one in exercise $26$.
Here, we have a Bernoulli random sample, and we test $\mathcal{H}_0 : p = 0.1$ and $\mathcal{H}_1:p>0.1$. We first compute the value under the null hypothesis:
\[z = \frac{\hat{p} - p_0}{\sqrt{\frac{p_0(1-p_0)}{n}}} = \frac{0.15-0.1}{\sqrt{0.1\times 0.9 / 100}} = 1.66667\]and we will reject $\mathcal{H}0$ if $z > z_{\alpha} = z_{0.005} = 1.645$, which means we will reject $\mathcal{H}_0$ under significance level $\alpha=0.05$.
Here, we have two Bernoulli random samples, let $X_i$ be the sample treated with Lipitor and $Y_j$ be the sample treated with placebo. We have $X_1,\cdots,X_{94} \sim Bernoulli(\theta_1)$, $\theta_1 = 0.074468$ and $Y_1,\cdots,Y_{270} \sim Bernoulli(\theta_2), \theta_2 = 0.1$, we test $\mathcal{H}_0:\mu_1-\mu_2=0$, and $\mathcal{H}_1: \mu_1-\mu_2\neq 0$. We first compute the value under the null hypothesis:
\[z = \frac{\hat\theta_1 - \hat\theta_2 }{\sqrt{\displaystyle{\frac{\hat{p}(1-\hat{p})}{n_1} + \frac{\hat{p}(1-\hat{p})}{n_2}}}}, \hat{p} = \frac{x_1+x_2}{n_1+n_2} = \frac{7+27}{94+270}=0.09341\]and we get
\[z = \frac{0.074468-0.1}{\displaystyle{\sqrt{0.09341(1-0.09341)/94+0.09341(1-0.09341)/270}}} = -0.73262\]We will reject $\mathcal{H}0$ if $\vert z\vert > z_{\alpha/2} = z_{0.025} = 1.96$, and hence we do not reject $\mathcal{H}_0$, under the significance level $\alpha=0.05$.
Recommended citation: Jiajun Zhang, (2025) Hypothesis Testing
