📢
Admissions Open for August 2026 Batch | Free Career Counselling | Limited Scholarships
Register Now →

Learning Guides

Hypothesis Testing Using T-Test: Complete Guide

Quick answer: Learn the t-test for hypothesis testing, including one-sample, two-sample and paired t-tests, when to use each, and how to interpret results in Python.

What is a T-Test?

A t-test is a statistical hypothesis test used to determine whether the means of one or two groups differ significantly, when the population standard deviation is unknown and must be estimated from the sample itself. This is the most commonly used hypothesis test in practical data analysis.

Three Types of T-Tests

TypeUsed when
One-sample t-testComparing a sample mean to a known or hypothesised value
Independent two-sample t-testComparing means of two separate, unrelated groups
Paired t-testComparing two related measurements, such as before and after values for the same subjects

One-Sample T-Test Example

from scipy import stats

scores = [78, 82, 85, 90, 76, 88, 79, 84]
hypothesized_mean = 80

t_stat, p_value = stats.ttest_1samp(scores, hypothesized_mean)
print(f"t-statistic: {t_stat:.2f}, p-value: {p_value:.4f}")

Independent Two-Sample T-Test Example

group_a = [78, 82, 85, 90, 76]
group_b = [65, 70, 72, 68, 74]

t_stat, p_value = stats.ttest_ind(group_a, group_b)
print(f"t-statistic: {t_stat:.2f}, p-value: {p_value:.4f}")

Paired T-Test Example

before = [70, 75, 68, 80, 72]
after  = [78, 82, 74, 85, 79]

t_stat, p_value = stats.ttest_rel(before, after)
print(f"t-statistic: {t_stat:.2f}, p-value: {p_value:.4f}")

A paired test is used here because each before and after value belongs to the same subject, which the independent two-sample test would incorrectly ignore.

Interpreting the P-Value

If the p-value falls below the chosen significance level, typically 0.05, the difference is considered statistically significant, meaning it is unlikely to be due to random chance alone under the null hypothesis of no real difference.

Assumptions of the T-Test

  • Data is approximately normally distributed, particularly important for small sample sizes

  • Observations are independent (except in the paired test, which specifically handles related measurements)

  • For the independent two-sample test, variances between the two groups are roughly equal, unless using Welch's correction, which relaxes this assumption

T-Test vs ANOVA

A t-test compares exactly two groups. When comparing three or more groups, ANOVA is the correct choice instead, since running multiple t-tests would inflate the overall false positive rate.

Common Interview Questions

When would you use a paired t-test instead of an independent two-sample t-test?

When the two sets of measurements come from the same subjects, such as before and after a treatment, since the paired test accounts for the natural correlation between each subject's own two measurements.

What do you do if the equal variance assumption is violated in a two-sample t-test?

Use Welch's t-test instead, a variant that does not assume equal variances between the two groups, available in most statistical software as an alternative option.

FAQ

Frequently Asked Questions

What is a t-test used for?

It tests whether the means of one or two groups differ significantly, when the population standard deviation is unknown and must be estimated from the sample.

What is the difference between an independent and a paired t-test?

An independent t-test compares two separate, unrelated groups. A paired t-test compares two related measurements from the same subjects, such as before and after values.

When should you use ANOVA instead of a t-test?

When comparing three or more groups. Running multiple t-tests instead would inflate the overall chance of a false positive across the comparisons.

What assumption does a t-test make about the data?

It assumes the data is approximately normally distributed, particularly important for small samples, and that observations are independent unless using the paired variant.

Want This Mapped to Your Own Background?

A free counselling session will tell you which path fits, and will tell you honestly if none of ours does.

Book Free Career Counselling

Keep Reading

Related Articles