Quick answers
- What is a t-test?
- A test of whether a mean differs from a value, or two means differ, relative to the noise in the data. t = difference ÷ its standard error, compared with the t distribution.
- Which t-test should I use?
- One mean vs a target: one-sample. Two separate groups: two-sample (Welch if variances differ). The same or matched units measured twice: paired. Three or more groups: ANOVA instead.
- What is the difference between paired and independent t-tests?
- Paired tests compare two measurements on the same or matched units (before and after, littermates) by analyzing the differences. Independent tests compare separate groups.
- What is Welch's t-test?
- A two-sample t-test that does not assume equal variances. It adjusts the degrees of freedom and is a safe default when group SDs or sizes differ.
- What are the assumptions of a t-test?
- Independent observations, roughly normal data within groups (or normal differences for a paired test), and equal variances for the classic two-sample test.
- What is the non-parametric alternative to the t-test?
- The Mann-Whitney U test (Wilcoxon rank-sum) for two independent groups, and the Wilcoxon signed-rank test for paired data.
On this page
One-sample t-test
Compares one mean with a fixed value: a breed standard, a label claim, a target yield.
t = (x̄ − μ₀) / (s / √n), with n − 1 degrees of freedom
In designed experiments, one-sample tests are rare: you usually compare treatments with each other, not with a fixed number.
Two-sample (independent) t-test
Compares the means of two separate groups. The classic version pools the two variances:
t = (x̄₁ − x̄₂) / [sₚ √(1/n₁ + 1/n₂)], with sₚ² = [(n₁ − 1)s₁² + (n₂ − 1)s₂²] / (n₁ + n₂ − 2)
Assumptions: independent units, roughly normal data in each group, equal variances. With equal group sizes the test tolerates unequal variances well, up to about a threefold ratio. With unequal sizes it does not, and Welch's test is safer.
Welch's t-test (unequal variances)
Welch's test uses each group's own variance, SE = √(s₁²/n₁ + s₂²/n₂), and the Satterthwaite approximation for the degrees of freedom. When variances are equal it gives almost the same answer as the pooled test, so many statisticians use it by default.
Testing variances first (with an F test or Levene's test) and then choosing the t-test is no longer recommended: the preliminary test has little power in small samples. Decide in advance, or simply use Welch.
Paired t-test
When the two measurements come in natural pairs (the same cow before and after treatment, two halves of a leaf, two pigs from the same litter), analyze the differences within pairs with a one-sample t-test against zero. Pairing removes the variation between pairs.
t = d̄ / (s_d / √n), with n − 1 degrees of freedom, where d = difference within each pair
Here pairing gives a similar p value to the independent test because one litter (litter 1) went against the trend and only 5 df remain. Pairing pays off when pairs differ a lot from one another, which with four diets is better handled by blocking in an ANOVA of the whole randomized block design. Never analyze paired data with an independent test, or independent data with a paired test: the test must match the design.
Rank tests: Mann-Whitney and Wilcoxon signed-rank
Non-parametric tests replace the values with their ranks, so they do not assume normality and resist outliers. They answer a slightly different question: whether one group tends to have larger values.
- Mann-Whitney U test (Wilcoxon rank-sum test): two independent groups. Control vs C: W = 4, p = 0.030.
- Wilcoxon signed-rank test: paired data. On the six litter differences: V = 20, p = 0.063. With n = 6 the smallest possible exact p value is 0.031, so rank tests have little power in very small samples.
Use rank tests for scores and ordinal ratings, or clearly non-normal data that a transformation cannot fix. With counts or proportions, a generalized linear model is usually a better choice.
Why not many t-tests for many groups?
With four diets there are six pairs to compare. Six t-tests at α = 0.05 each give about a 26% chance of at least one false positive if no diet works (1 − 0.95⁶). Each test also uses only two groups' data to estimate the error. ANOVA tests all groups at once with the pooled error, and post hoc tests then compare pairs with the error rate controlled.
In R
dd <- subset(dat, diet %in% c("Control", "C"))
t.test(adg ~ diet, data = dd, var.equal = TRUE) # pooled two-sample
t.test(adg ~ diet, data = dd) # Welch
ctl <- dat$adg[dat$diet == "Control"]; c_ <- dat$adg[dat$diet == "C"]
t.test(c_, ctl, paired = TRUE) # paired by litter (data sorted by litter)
t.test(ctl, mu = 0.75) # one-sample
wilcox.test(adg ~ diet, data = dd) # Mann-WhitneyIn SAS
proc ttest data=pigs;
where diet in ("Control", "C");
class diet;
var adg; /* gives pooled and Satterthwaite (Welch) */
run;
proc npar1way data=pigs wilcoxon;
where diet in ("Control", "C");
class diet;
var adg;
run;Key takeaways
- One mean vs a value: one-sample t-test. Two separate groups: two-sample, or Welch when variances or sizes differ.
- Matched or repeated pairs: paired t-test on the differences. Match the test to the design.
- Mann-Whitney and Wilcoxon signed-rank are rank alternatives with little power in very small samples.
- Report the difference with its 95% confidence interval, t, df and p.
- For three or more groups use ANOVA, not repeated t-tests.
Questions people ask
What sample size do I need for a t-test?
Enough for adequate power; see the statistical power chapter. There is no minimum for the calculation itself, but with 2 or 3 per group only very large differences can be detected.
Can I use a t-test on percentages?
If they are averages of many observations and lie between about 20% and 80%, often yes. For proportions of a known number of trials, logistic regression is better.
What does a negative t value mean?
Only that the first group's mean is smaller than the second's. The sign depends on the order of the groups; the p value for a two-tailed test does not.
Is the z-test the same as the t-test?
The z-test assumes the population SD is known, which it almost never is. The t-test estimates it from the data, and the two converge for large samples.
Sources
- Kaps, M., and Lamberson, W. R. (2017). Biostatistics for Animal Science (3rd ed.), chapter on hypothesis testing. CABI.
- Welch, B. L. (1947). The generalization of "Student's" problem when several different population variances are involved. Biometrika, 34, 28–35.
- Ruxton, G. D. (2006). The unequal variance t-test is an underused alternative to Student's t-test and the Mann–Whitney U test. Behavioral Ecology, 17(4), 688–690.