Home Â» Two Sample t-test: Definition, Formula, and Example

# Two Sample t-test: Definition, Formula, and Example

A two sample t-test is used to determine whether or not two population means 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:

• H0: Î¼1Â =Â Î¼2 (the two population means are equal)

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

• H1 (two-tailed): Î¼1Â â‰  Î¼2 (the two population means are not equal)
• H1 (left-tailed): Î¼1Â 2Â (population 1 mean is less than population 2 mean)
• H1 (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:Â (x1Â â€“Â x2)Â  /Â  sp(âˆš1/n1Â + 1/n2)

whereÂ x1Â andÂ x2 are the sample means,Â n1 and n2Â are the sample sizes, and whereÂ sp is calculated as:

sp =Â âˆšÂ (n1-1)s12Â +Â Â (n2-1)s22Â /Â  (n1+n2-2)

where s12Â and s22Â are the sample variances.

If the p-value that corresponds to the test statistic t with (n1+n2-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Â n1 = 40
• Sample mean weightÂ x1Â = 300
• Sample standard deviationÂ s1 = 18.5

Sample 2:

• Sample sizeÂ n2 = 38
• Sample mean weightÂ x2Â = 305
• Sample standard deviationÂ s2 = 16.7

Step 2: Define the hypotheses.

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

• H0:Â Î¼1Â = Î¼2 (the two population means are equal)
• H1:Â Î¼1Â â‰  Î¼2 (the two population means are not equal)

Step 3: Calculate the test statisticÂ t.

First, we will calculate the pooled standard deviation sp:

sp =Â âˆšÂ (n1-1)s12Â +Â Â (n2-1)s22Â /Â  (n1+n2-2)Â =Â âˆšÂ (40-1)18.52Â +Â Â (38-1)16.72Â /Â  (40+38-2)Â = 17.647

Next, we will calculate the test statisticÂ t:

t =Â (x1Â â€“Â x2)Â  /Â  sp(âˆš1/n1Â + 1/n2) =Â  (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 = n1+n2-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.