# Testing the difference of two means with unknown variances

Let $$X\sim N(\mu_1,\sigma_1^2)$$ and $$Y\sim N(\mu_2,\sigma_2^2)$$ be two populations with unknown means and variances.

Suppose $$X_1,...,X_n$$ and $$Y_1,...,Y_m$$ are iid samples from $$X$$ and $$Y$$ respectively.

How can I test the hypothesis that $$\mu_1=\mu_2$$?

Can I use the t-test with the static

$$t=\frac{\bar X-\bar Y}{[\frac{S_1^2}{n-1}+\frac{S_2^2}{m-1}]^\frac{1}{2} }$$ to use t-test?

If so, which number should I use for the degree of freedom. What would be the mathematical justification?

If not, how may I test the hypothesis?

I am stuck with this for hours. Any hint would be a great help. Thanks!

Since both $X$ and $Y$ are normal distributed, they are as well $i.i.d.$ and you can use the t-test to test the difference in mean. If they would be dependent on each other, you could not use the formula provided because the standard error $SE(\bar{X}-\bar{Y})$ would depend on the covariance of $\bar{Y}$ and $\bar{X}$.
For $X$ and $Y$ you are using data to estimate the random variables $\bar{X}$ and $\bar{Y}$. This means you are losing one degree of freedom as stated in your formula. In some textbooks, only the large sample formula is provided without adjusting for $dof$. The small and large sample formulas should come close to one another when $n,m$ are each larger than $90$. Then, the Central limit theorem should ensure that your sample averages follow a normal distribution.
As for the critical value from the t-distribution, you should use $t_{n+m-2,1-\alpha/2}$ for two-sided tests and $t_{n+m-2,1-\alpha}$ for one-sided tests, where $\alpha$ is your significance level.
• This is close to the right answer, but the setup of this problem allows the distributions to have different variances, so Welch's t-test would be appropriate. The good news is that Welch's test is the default when you call t.test in R, and this might be the case in other statistical software, too.