## Confidence interval for means (variances are unknown and unequal)

Let `$x_1, x_2, \cdots, x_{n_1}$`

be a random sample of size `$n_1$`

from a population with mean `$\mu_1$`

and standard deviation `$\sigma_1$`

.

Let `$y_1, y_2, \cdots, y_{n_2}$`

be a random sample of size `$n_2$`

from a population with mean `$\mu_2$`

and standard deviation `$\sigma_2$`

. And the two sample are independent.

Let $\overline{x} = \frac{1}{n_1}\sum x_i$ and $\overline{y} = \frac{1}{n_2}\sum y_i$ be the sample means of first and second sample respectively.

Let $s_1^2 = \frac{1}{n_1-1}\sum (x_i -\overline{x})^2$ and $s_2^2 = \frac{1}{n_2-1}\sum (y_i -\overline{y})^2$ be the sample variances of first and second sample respectively.

Let $C = 1-\alpha$ be the confidence coefficient. Our objective is to construct $100(1-\alpha)\%$ confidence interval for the difference $\mu_1-\mu_2$.

The margin of error for the difference of means is
```
$$
\begin{aligned}
E = t_{\alpha/2,n_1+n_2-2} \sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}
\end{aligned}
$$
```

where $t_{\alpha/2,n_1+n_2-2}$ is the value from $t$ statistical table for desired confidence coefficient and degrees of freedom.

Then $100(1-\alpha)$% confidence interval estimate for the difference $(\mu_1-\mu_2)$ is
```
$$
\begin{aligned}
(\overline{x} -\overline{y})- E \leq (\mu_1-\mu_2) \leq (\overline{x} -\overline{y}) + E.
\end{aligned}
$$
```

## Assumptions

a. The two samples are independent.

b. Both the samples are simple random sample.

c. The two samples are both large ($n_1 > 30$ and $n_2 >30$) or both the samples comes from population having normal distribution.

d. The two population variances $\sigma^2_1$ and $\sigma^2_2$ are unknown.

## Step by Step Procedure

Step by step procedure to estimate the confidence interval for difference between two population means is as follows:

### Step 1 Specify the confidence level $(1-\alpha)$

### Step 2 Given information

Given that $n_1, n_2$, $\overline{x}$, $\overline{y}$, $s^2_1$, $s^2_2$.

### Step 3 Specify the formula

$100(1-\alpha)$% confidence interval estimate for the difference $(\mu_1-\mu_2)$ is
```
$$
\begin{aligned}
(\overline{x} -\overline{y})- E \leq (\mu_1-\mu_2) \leq (\overline{x} -\overline{y}) + E.
\end{aligned}
$$
```

where `$E = t_{\alpha/2,\nu}\sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}$`

and `$t_{\alpha/2, \nu}$`

is the $t$ value providing an area of $\alpha/2$ in the upper tail of the students’ $t$ distribution with $\nu$ degrees of freedom.

The degrees of freedom $\nu$ can be calculated as
```
$$
\begin{aligned}
\nu &= \frac{\bigg(\dfrac{s_1^2}{n_1}+\dfrac{s_2^2}{n_2}\bigg)^2}{\dfrac{1}{(n_1-1)}\bigg(\dfrac{s_1^2}{n_1}\bigg)^2+\dfrac{1}{(n_2-1)}\bigg(\dfrac{s_2^2}{n_2}\bigg)^2}
\end{aligned}
$$
```

rounded to nearest integer.

### Step 4 Determine the critical value

Determine the critical value $t_{\alpha/2,\nu}$ from the $t$ statistical table for the desired confidence coefficient and degrees of freedom.

### Step 5 Compute the margin of error

The margin of error for the difference of means is
```
$$
\begin{aligned}
E = t_{\alpha/2,\nu} \sqrt{\frac{s_1^2}{n_1}+\frac{s_2^2}{n_2}}
\end{aligned}
$$
```

### Step 6 Determine the confidence interval

Then $100(1-\alpha)$% confidence interval estimate for the difference $(\mu_1-\mu_2)$ is
```
$$
\begin{aligned}
(\overline{x} -\overline{y})- E \leq (\mu_1-\mu_2) \leq (\overline{x} -\overline{y}) + E
\end{aligned}
$$
```

Thus, $100(1-\alpha)$% confidence interval estimate for the difference $(\mu_1-\mu_2)$ is $\big((\overline{x} -\overline{y})- E , (\overline{x} -\overline{y}) + E\big)$.