Two independent samples t-tests: Formula & Examples

independent samples t-test representation

As a data scientist, you may often come across scenarios where you need to compare the means of two independent samples. In such cases, a two independent samples t-test, also known as unpaired two samples t-test, is an essential statistical tool that can help you draw meaningful conclusions from your data. This test allows you to determine whether the difference between the means of two independent samples is statistically significant or due to chance.

In this blog, we will cover the concept of two independent samples t-tests, its formula, and real-world examples of its applications. We will begin with an overview of what a two independent samples t-test is, followed by an explanation of its formula and assumptions. Then we will explore some examples to help you understand how to apply the test in practice. 

What is independent-samples or unpaired two samples T-test?

The independent samples T-test is defined as statistical hypothesis testing technique in which the samples from two independent groups are compared to determine if the means of the associated populations are significantly different. The test compares the means of two groups, such as a control group and a treatment group, to determine if the difference between the groups’ means is statistically significant or due to random chance. For example, lets say that we have two independent groups of marketing professionals having similar qualification and we want to compare their income to determine whether their income is significantly different.

Independent samples t-test is also called unpaired two-samples t-test because the test is performed with only two groups that are independent or unpaired or unrelated. The picture below shows the representation of two independent samples and the aspect of their means. 

independent samples t-test representation

The picture below represents represents the need to compare the means of mathematics marks between two independent group (male and female). Independent samples t-test could be performed.

independent samples t-test data example 1

The independent samples T-test is used when the two samples are independent and have normal distributions.

  • The mandatory requirement is that you need to have two independent samples. The independent samples mean that the two samples cannot be from the same group of people and they cannot be related in any way.
  • Another assumption for independent samples t-test is homogeneity of variance of the two groups.
  • The two-sample T-test is used when the standard deviations of the populations to be compared are unknown and the sample size is small.
  • The size of sample 30 or less is considered as small sample. That said, the size of the sample is not a strict condition for using T-test.

The two-sample T-test can also be used for pairwise comparisons when the “two” samples represent the same items tested in different scenarios. The pairwise samples t-test will be dealt with in different blog.

Let’s say you want to know if two different brands of batteries have the same average life. You could take a battery from each brand, use them until they die, and record the results. This would be an extremely time-consuming process, and it’s not very likely that you’d get a large enough sample size to draw any conclusions. Another option is to use a independent-samples T-test. This test allows you to compare the averages of two groups without having to measure the batteries’ life spans yourself.

The following are a few real-life examples where two-sample T-test for independent samples can be used:

  • Business and finance
    • Comparing the sales performance of two products
    • Analyzing the effectiveness of two marketing strategies
  • Healthcare and medicine
    • Examining the effects of two treatments on patient outcomes
    • Comparing the mean blood pressure levels of two patient groups
  • Social sciences
    • Analyzing the differences in academic performance between two schools
    • Comparing the mean levels of happiness among two age groups

Assumptions related to Independent Samples T-test

The following are some assumptions related to independent samples t-test:

  • Assumes that the two samples are independent from each other. The samples in no way should be related to each other.
  • Assumes that the two populations have normal distributions. This assumption is crucial, especially when the sample size is small. A normal distribution allows us to use the t-distribution, which is the basis of the t-test.
  • Assumes the homogeneity of variance between the two groups. The variance of the data in each sample should be equal. If this assumption is violated, it can lead to biased results.
  • Assumes that measurements made on the same group of objects are statistically independent of each other.
  • Assumes that all observations within each sample are randomly selected and independently distributed. Random sampling helps to ensure that the sample is representative of the population, reducing the likelihood of sampling bias.
  • Assumes that there is an equal or nearly equal sample size between the two groups being tested.

T-statistics when homogeneity of variances does not hold good (variances not equal)

The formula for T-statistics is different based on whether the variance within the two different groups are same / equal or different (statistically). When the variances of populations are not equal, the following formula is used to calculate the T-statistics and degrees of freedom.

t-statistics given the population standard deviations are unequal

Where X̄1 is mean of first sample, X̄2 is mean of second sample, μ1 is the mean of first population, μ2 is the mean of second population, s1 is the standard deviation of first sample, s2 is the standard deviation of second sample, n1 is the size of the first sample, n2 is the size of the second sample.

The degrees of freedom can be calculated as the sum of two sample sizes minus two.

Degrees of freedom, df = n1 + n2 – 2

A confidence interval for the difference between two means specifies a range of values within which the difference between the means of the two populations may lie. The difference between the means of two populations can be estimated based on the following formula:

Difference in population means = Difference in sample means +/- T*standard error

Difference between means of two populations

In above formula, the standard error is the square root term.

T-statistics when population variances or standard deviations are equal

In case, the two populations’ variances or standard deviations are equal, the formula termed as pooled t-statistics is used based on the usage of pooled standard deviations of the two samples. The following is the formula for the pooled t-statistics:

pooled t-statistics

In the above formula, Sp is termed as pooled standard deviation. The formula for pooled variance can be calculated based on the following:

pooled t-statistics standard deviation estimator

The value for the degree of freedom can be calculated as the sum of two sample sizes minus two.

Degrees of freedom, df = n1 + n2 – 2

When independent-samples T-test instead of independent-samples Z-test?

Two independent samples z-test and t-test are both statistical tests used to compare the means of two independent samples. However, the choice between the two tests depends on the characteristics of the data and the assumptions that we can make about the population.

In general, a two independent samples z-test is appropriate when we know the population standard deviation and the sample sizes are large. This is because, when sample sizes are large, the sample means are typically normally distributed, and the z-test assumes normality in the population.

On the other hand, a two independent samples t-test is more appropriate when we do not know the population standard deviation and the sample sizes are small. This is because, when the sample size is small, the sample means may not be normally distributed, and the t-test can provide a more accurate estimate of the population mean. 

Here is the summary of which tests out of z-test or t-test to use in which scenarios:

Two independent samples z-test:

  • Large sample size (typically > 30)
  • Known population standard deviation
  • Normally distributed population

Two independent samples (unpaired) t-test:

  • Small sample size (typically < 30)
  • Unknown population standard deviation
  • Population may not be normally distributed

Two-sample T-test: Examples

Lets say we need to compare the performance of two call centers in terms of average call lengths and find out if the difference is statistically significant or the difference is a chance occurrence. To start with, we will need to formulate the null and alternate hypothesis.

Null hypothesis, H0: There is no difference between the average call length between two call centers.

Alternate hypothesis, Ha: There is a difference between the average call length and hence the performance.

We randomly select 20 calls from each call center and calculate the average call lengths. The two call centers seem to have different average call lengths. Is this difference statistically significant?

First, we need to calculate the two sample means and standard deviations:

Call Center A: Sample mean, X̄1 = 122 seconds, SD, S1 = 15 seconds, n1 = 20

Call Center B: Sample mean, X̄2 = 135 seconds, SD, S2 = 20 seconds, n2 = 20

Next, we use a two-sample t-test to determine if the difference between two sample means is statistically significant. We will use a 95% confidence level and α = 0.05.

The two-sample t-statistic is calculated as the following assuming that the standard deviations of the population is not same and the population mean is same.

t = ((135 – 122) – 0)/SQRT((20*20/20) + ((15*15)/20))

t = 13/SQRT(20 + 11.25)

t = 13/SQRT(31.25)

t = 2.3256

The value of degrees of freedom can be calculated as the following:

Degree of freedom, df = n1 + n2 -2 = 20 + 20 – 2 = 38

The critical value of a two-tailed T-test with degrees of freedom as 38 and level of significance as 0.05 comes out to be 2.0244. Since the current t-value of 2.3256 is greater than the critical value of 2.0244, one can reject the null hypothesis that there is no difference between the performance in terms of the call length time. Thus, based on the given evidence, the alternate hypothesis stands as true.


The two-sample t-test for independent samples is a statistical method for comparing two different populations. The t-test can be used when the population standard deviations are not known and the sample size is smaller (less than 30). The two sample t-statistic calculation depends on given degrees of freedom, df = n1 + n2 – 2. If the value of two samples t-test for independent samples exceeds critical T at alpha level, then you can reject null hypothesis that there is no difference between two data sets (H0). Otherwise if two sample T-statistics is less than or equal to critical T at alpha level, then one cannot reject H0; this means both values could have come from same distribution in which case any observed difference would be due to chance alone. Different formulas are required to be used for performing t-test for two independent samples based on whether the variances of two populations are equal or otherwise.

Ajitesh Kumar
Follow me

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking
Posted in Data Science, statistics. Tagged with , .

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.