Interview Q&A / Data Science

IntermediateQuick answer1 min readUpdated 3 Oct 2026

How does a two-sample t-test work? Walk through a small example.

SHORT ANSWER

It tests whether two group means differ by more than chance would explain. The t statistic is the difference in means divided by its standard error; a large |t| gives a small p-value and evidence against equal means.

Explain it simply

You want to know if students who used a new revision app score higher than those who did not. The groups will differ a bit by luck anyway. The t-test asks: is the gap large compared with the natural noise?

t = (mean1 - mean2) / standard error of the difference

Hypotheses: H0 says the true means are equal, H1 says they are different.

Example

Test scores: app group 72, 75, 78, 80, 82 (mean 77.4); no-app group 68, 70, 72, 74, 71 (mean 71.0).

python
from scipy import stats
a = [72, 75, 78, 80, 82]
b = [68, 70, 72, 74, 71]
t, p = stats.ttest_ind(a, b)
print(round(t, 2), round(p, 4))  # 3.14 0.0138

t = 3.14 with 8 degrees of freedom and p = 0.0138, below 0.05, so we reject H0: the data is unlikely if the two means were really equal.

If the groups may have unequal variances, use Welch's version: ttest_ind(a, b, equal_var=False). It gives the same t here, with p about 0.0189.

What to say in the interview

"A two-sample t-test compares means of two independent groups. I check independence, rough normality or a decent sample size, and use Welch's test if the variances look unequal. I report the effect size and a confidence interval along with the p-value, not only whether it is below 0.05."

Common mistakes

  • Using it for the same people measured twice. That needs a paired test.

#t-test#hypothesis-testing#inference

Related questions

Practise more Data Science questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Data Science quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.