Let $X_{1},\ldots ,X_{n}$ be i.i.d. $N(\mu_{1},{\sigma}_{1}^{2})$ and let $Y_{1},\ldots ,Y_{m}$ be i.i.d. $N(\mu_{2},{\sigma}_{2}^{2})$. We shall consider the following hypothesis testing problems.
This kind of problem arises in many situations in comparing two different populations or the effect of two different treatments etc. Actual data sets of such questions can be found in the homework.
We take a random sample of $n+m$ patients and break them into two groups of $n$ and of $m$ patients. The first group is administered the new drug while the second group is administered the old drug. Let $X_{1},\ldots ,X_{n}$ be the decrease in blood pressures in the first group. Let $Y_{1},\ldots ,Y_{m}$ be the decrease in blood pressures in the second group. The claim is that one average $X_{i}$s are larger than $Y_{i}$s.
Note that it does not make sense to subtract $X_{i}-Y_{i}$ and reduce to a one sample test as in the previous section (here $X_{i}$ is a measurement on one person and $Y_{i}$ is a measurement on a completely different person! Even the number of persons in the two groups may differ). This is an example of a two-sample test as formulated above.
BIG ASSUMPTION: We shall assume that ${\sigma}_{1}^{2}={\sigma}_{2}^{2}={\sigma}^{2}$ (yet unknown). This assumption is not made because it is natural or because it is often observed, but because it leads to mathematical simplification. Without this assumption, no exact level-$\alpha$ test has been found!
The test : Let $\bar{X},\bar{Y}$ denote the sample means of $X$ and $Y$ and let $s_{X}, s_{Y}$ denote the corresponding sample standard deviations. Since ${\sigma}^{2}$ is the assumed to be the same for both populations, $s_{X}^{2}$ and $s_{Y}^{2}$ can be combined to define $$ S^{2}:=\frac{(n-1)s_{X}^{2}+(m-1)s_{Y}^{2} }{m+n-2} $$ which is a better estimate for ${\sigma}^{2}$ than just $s_{X}^{2}$ or $s_{Y}^{2}$ (this $S^{2}$ is better than simply taking $(s_{X}^{2}+s_{Y}^{2})/2$ because it gives greater weight to the larger sample).
Now define $\mathcal T =\sqrt{\frac{1}{n}+\frac{1}{m} }\left(\frac{\bar{X}-\bar{Y} }{S}\right)$. The following tests hav significance level $\alpha$.
The rationale behind the tests : If $\bar{X}$ is much larger than $\bar{Y}$ then the greater is the evidence that the true mean $\mu_{1}$ is greater than $\mu_{2}$. But again we need to standardize by dividing this by an estimate of ${\sigma}$, namely $S$. The resulting statistic $\mathcal T$ has a $t_{m+n-2}$ distribution as explained below.
The significance level is $\alpha$ : The question is where to draw the threshold. From the facts we know, $$\begin{align*} \bar{X}&\sim N(\mu_{1},{\sigma}_{1}^{2}/n), \\ \bar{Y}&\sim N(\mu_{2},{\sigma}_{2}^{2}/m), \\ \frac{(n-1)}{{\sigma}^{2} }s_{X}^{2}&\sim \chi_{n-1}^{2}, \\ \frac{(m-1)}{{\sigma}^{2} }s_{Y}^{2}&\sim \chi_{m-1}^{2} \end{align*}$$ and the four random variables are independent. From this, it follows that $(m+n-2)S^{2}$ has $\chi_{n+m-2}^{2}$ distribution. Under the null hypothesis $\frac{1}{{\sigma}}\sqrt{\frac{1}{n}+\frac{1}{m} }(\bar{X}-\bar{Y})$ has $N(0,1)$ distribution and is independent of $S$. Taking ratios, we see that $\mathcal T$ has $t_{m+n-2}$ distribution (under the null hypothesis).