Two-sample t-test
A two-sample (independent) t-test checks whether two group means differ: t = (x-bar1 - x-bar2) / sqrt(s1^2 / n1 + s2^2 / n2). The Welch version does not assume equal variances and is the safe default; the p-value comes from the t distribution.
Syntax
t = (x-bar1 - x-bar2) / sqrt( s1^2 / n1 + s2^2 / n2 )| Part | What it is |
|---|---|
x-bar1, x-bar2 | the two sample means |
s1, s2 | the two sample standard deviations |
n1, n2 | the two sample sizes |
Examples
Group A: mean 20, s = 5, n = 25. Group B: mean 16, s = 5, n = 25
SE = sqrt(25/25 + 25/25) = sqrt(2) = 1.414
t = (20 - 16) / 1.414Result: t = 2.83, df = 48, two-sided p = 0.007
Excel from raw data, Welch (unequal variances), two-sided
=T.TEST(A1:A25, B1:B25, 2, 3)Result: the p-value directly
Pooled (equal variances) version in Excel
=T.TEST(A1:A25, B1:B25, 2, 2)Result: same p as Welch here because the sds and sizes are equal
Common mistakes
- Using the paired type (1) in T.TEST for two unrelated groups; use 3 (Welch) or 2 (pooled).
- Pooling variances when one group is much more spread than the other; Welch handles that, the pooled test does not.
- Comparing groups that are not independent, such as the same people before and after; that needs a paired t-test.
Practice Two-sample t-test
These drills check your answer on live data, free, no account needed.
- Two-sided t test: p-value and decisionTest H0: μ = 68 against H1: μ ≠ 68 for the average order value (dollars). A random sample of 11 gives x̄ = 69.33 and s = 29.5. Find the p-value of the one-sample t test, then decide at α = 0.05. Round to 4 decimal places.
- Critical t value for an intervalYou will build a 90% confidence interval for a mean from a sample of 5 observations, with the population standard deviation unknown. What critical value t* should you use? Round to 3 decimal places.
Questions
What are the degrees of freedom for a two-sample t-test?
Pooled: n1 + n2 - 2. Welch: a formula based on the two variances that gives a value between the smaller n - 1 and n1 + n2 - 2; software computes it for you.
Should I use Welch or Student's t-test?
Welch. It is equally accurate when variances are equal and much safer when they are not, so most statisticians recommend it as the default.
How large a sample do I need?
Each group of 30 or more is usually fine for moderately non-normal data. For small samples check normality or use the Mann-Whitney test.
Related
- One-sample t-testHow to run a one-sample t-test: compute t = (x-bar - mu0) / (s / sqrt(n)), find the p-value with n - 1 degrees of freedom and decide. Example and Excel.
- Paired t-testHow to run a paired t-test on before and after data: take the differences, compute t = d-bar / (s_d / sqrt(n)) with n - 1 degrees of freedom. Example, Excel.
- Two-proportion z-testHow to test whether two proportions differ with the two-proportion z-test: pooled proportion, standard error, z statistic and p-value, with a worked example.
- p-valueA p-value is the probability of a result at least as extreme as the observed one if the null is true. How to compute it from z and t, and common misreadings.