A **two sample t-test** is used to test whether or not the means of two populations are equal.

This tutorial explains the following:

- The motivation for performing a two sample t-test.
- The formula to perform a two sample t-test.
- The assumptions that should be met to perform a two sample t-test.
- An example of how to perform a two sample t-test.

**Two Sample t-test: Motivation**

Suppose we want to know whether or not the mean weight between two different species of turtles is equal. Since there are thousands of turtles in each population, it would be too time-consuming and costly to go around and weigh each individual turtle.

Instead, we might take a simple random sample of 15 turtles from each population and use the mean weight in each sample to determine if the mean weight is equal between the two populations:

However, it’s virtually guaranteed that the mean weight between the two samples will be at least a little different. **The question is whether or not this difference is statistically significant**. Fortunately, a two sample t-test allows us to answer this question.

**Two Sample t-test:**** Formula**

A two-sample t-test always uses the following null hypothesis:

**H**μ_{0}:_{1}= μ_{2}(the two population means are equal)

The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:

**H**μ_{1}(two-tailed):≠ μ_{1}_{2}(the two population means are not equal)**H**μ_{1}(left-tailed):_{1}< μ_{2}(population 1 mean is less than population 2 mean)**H**μ_{1}(right-tailed):> μ_{1}_{2}(population 1 mean is greater than population 2 mean)

We use the following formula to calculate the test statistic t:

**Test statistic:** (x_{1} – x_{2}) / s_{p}(√1/n_{1} + 1/n_{2})

where x_{1} and x_{2} are the sample means, n_{1 }and n_{2 }are the sample sizes, and where s_{p} is calculated as:

**s _{p}** = √ (n

_{1}-1)s

_{1}

^{2}+ (n

_{2}-1)s

_{2}

^{2}/ (n

_{1}+n

_{2}-2)

where s_{1}^{2} and s_{2}^{2} are the sample variances.

If the p-value that corresponds to the test statistic t with (n_{1}+n_{2}-1) degrees of freedom is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.

**Two Sample t-test: Assumptions**

For the results of a two sample t-test to be valid, the following assumptions should be met:

- The observations in one sample should be independent of the observations in the other sample.
- The data should be approximately normally distributed.
- The two samples should have approximately the same variance. If this assumption is not met, you should instead perform Welch’s t-test.
- The data in both samples was obtained using a random sampling method.

**Two Sample t-test****: Example**

Suppose we want to know whether or not the mean weight between two different species of turtles is equal. To test this, will perform a two sample t-test at significance level α = 0.05 using the following steps:

**Step 1: Gather the sample data.**

Suppose we collect a random sample of turtles from each population with the following information:

**Sample 1:**

- Sample size n
_{1}= 40 - Sample mean weight x
_{1}= 300 - Sample standard deviation s
_{1}= 18.5

**Sample 2:**

- Sample size n
_{2}= 38 - Sample mean weight x
_{2}= 305 - Sample standard deviation s
_{2}= 16.7

**Step 2: Define the hypotheses.**

We will perform the two sample t-test with the following hypotheses:

**H**μ_{0}:_{1}= μ_{2}(the two population means are equal)**H**μ_{1}:_{1}≠ μ_{2}(the two population means are not equal)

**Step 3: Calculate the test statistic t.**

First, we will calculate the pooled standard deviation s_{p}:

**s _{p}** = √ (n

_{1}-1)s

_{1}

^{2}+ (n

_{2}-1)s

_{2}

^{2}/ (n

_{1}+n

_{2}-2) = √ (40-1)18.5

^{2}+ (38-1)16.7

^{2}/ (40+38-2) =

**17.647**

Next, we will calculate the test statistic *t*:

**t** = (x_{1} – x_{2}) / s_{p}(√1/n_{1} + 1/n_{2}) = (300-305) / 17.647(√1/40 + 1/38) = **-1.2508**

**Step 4: Calculate the p-value of the test statistic t.**

According to the T Score to P Value Calculator, the p-value associated with t = -1.2508 and degrees of freedom = n_{1}+n_{2}-2 = 40+38-2 = 76 is **0.21484**.

**Step 5: Draw a conclusion.**

Since this p-value is not less than our significance level α = 0.05, we fail to reject the null hypothesis. We do not have sufficient evidence to say that the mean weight of turtles between these two populations is different.

**Note: **You can also perform this entire two sample t-test by simply using the Two Sample t-test Calculator.

**Additional Resources**

The following tutorials explain how to perform a two-sample t-test using different statistical programs:

How to Perform a Two Sample t-test in Excel

How to Perform a Two Sample t-test in SPSS

How to Perform a Two Sample t-test in Stata

How to Perform a Two Sample t-test in Python

How to Perform a Two Sample t-test on a TI-84 Calculator