T-Test Calculator: One-Sample, Paired, Student and Welch Two-Sample Tests
By FindMySum · Last reviewed
A t-test asks whether a difference in averages is bigger than you would expect from chance alone. It is one of the most used tools in statistics: comparing two treatments, a process before and after a change, or a sample against a target value. This calculator runs all four common versions from raw data or from summary statistics and reports the t statistic, degrees of freedom, p-value, confidence interval and effect size. The opening example is R's classic sleep data: the extra hours of sleep ten patients got from two different drugs.
The idea
Every t-test has the same shape. Take the difference you observed, subtract the difference the null hypothesis says there should be (usually zero), and divide by the standard error, the typical size of that difference from sampling noise alone:
t = (observed difference − μ₀) ÷ standard error
A t near 0 is what chance alone would give. A large positive or negative t is unusual under the null hypothesis. How unusual is measured by the p-value, read from Student's t distribution with the right degrees of freedom. The t distribution looks like the normal curve but with heavier tails, especially for small samples, because the standard error is itself estimated from the data.
One-sample test
Compare one sample's mean with a fixed value μ₀, such as a specification or a published average:
t = (x̄ − μ₀) ÷ (s ÷ √n), df = n − 1
For example, 36 students average 103 on a test whose population mean is 100, with a standard deviation of 15: t = 3 ÷ (15 ÷ 6) = 1.2 with 35 degrees of freedom, p = 0.238. The difference could easily be chance.
Paired test
When each value in one sample is matched with one in the other, the same patient on two drugs, a part measured by two instruments, a store's sales before and after a promotion, work with the differences. The paired test is a one-sample test on the differences against μ₀ = 0.
In the sleep data, the differences between the two drugs for the ten patients have mean −1.58 hours and standard deviation 1.23, so t = −1.58 ÷ (1.23 ÷ √10) = −4.06 with 9 degrees of freedom, p = 0.0028. Pairing removes the large differences between patients, which is why it is so much more sensitive than treating the groups as independent.
Two-sample tests: Student and Welch
For two independent groups, the difference is x̄₁ − x̄₂. The two versions differ in how they estimate its standard error.
Student's pooled test assumes both populations have the same variance and pools the two sample variances:
s_p² = [(n₁ − 1)s₁² + (n₂ − 1)s₂²] ÷ (n₁ + n₂ − 2), SE = s_p √(1/n₁ + 1/n₂), df = n₁ + n₂ − 2
Welch's test keeps the variances separate:
SE = √(s₁²/n₁ + s₂²/n₂)
with the Welch–Satterthwaite degrees of freedom:
df = (s₁²/n₁ + s₂²/n₂)² ÷ [(s₁²/n₁)²/(n₁ − 1) + (s₂²/n₂)²/(n₂ − 1)]
which is usually not a whole number. Welch's test is nearly as powerful as Student's when the variances are equal and much more reliable when they are not, especially with unequal sample sizes, so many statisticians (and R, by default) use it routinely.
Treating the sleep data as two independent groups, Welch's test gives t = −1.861 with 17.78 degrees of freedom and p = 0.0794, matching the example in R's documentation. At α = 0.05 the difference is not significant, even though the paired analysis of the same numbers is highly significant. The design of the study, not the data alone, decides which test is right.
One-sided and two-sided p-values
A two-sided test asks whether the means differ in either direction; its p-value counts both tails of the t distribution. A one-sided test asks about one direction only (is the new process faster?), and its p-value is one tail. Choose the alternative before looking at the data; switching to one-sided after seeing the result halves the p-value and inflates false positives. The calculator shows all three p-values so you can see the relationship.
Confidence interval
The confidence interval for the difference is:
difference ± t(1 − α/2, df) × SE
For the Welch example at 95%, −1.58 ± 2.10 × 0.849 gives −3.37 to 0.21 hours. The interval includes 0, which is the same conclusion as p > 0.05, but it also shows the range of plausible differences, which is often more useful than the yes-or-no decision.
Effect size
A p-value says how surprising the data are, not how big the effect is; with a huge sample a trivial difference becomes significant. Cohen's d expresses the difference in standard-deviation units: the mean difference divided by the pooled standard deviation for two samples, by the standard deviation for one sample, and by the standard deviation of the differences (d_z) for paired data. Cohen's rough benchmarks are 0.2 small, 0.5 medium and 0.8 large; the sleep data's −0.83 is large, though the small sample leaves it uncertain.
Assumptions and alternatives
The t-test assumes independent observations and, for small samples, roughly normal data within each group. It is fairly robust to mild skewness, especially with equal group sizes, and Welch's version removes the equal-variance assumption. With strongly skewed data, outliers or ordinal scores in small samples, consider a non-parametric test: Mann–Whitney for two independent groups, or the Wilcoxon signed-rank test for pairs. For three or more groups, use analysis of variance rather than many t-tests.
More questions
Why is it called Student's t-test?
William Sealy Gosset, a chemist at the Guinness brewery in Dublin, published the t distribution in 1908 under the pen name 'Student', because the brewery did not let staff publish under their own names. He needed a way to draw conclusions from the small samples of barley and hops he worked with.
How large a sample does a t-test need?
There is no minimum beyond two values per group, but small samples have little power: they can only detect large effects. As a rough guide, detecting a medium effect (Cohen's d = 0.5) with 80% power at α = 0.05 in a two-sided two-sample test needs about 64 per group. Plan the sample size before collecting the data.
What is the difference between a t-test and a z-test?
A z-test uses the normal distribution and needs the population standard deviation to be known. A t-test estimates the standard deviation from the sample and accounts for that extra uncertainty with the heavier-tailed t distribution. With large samples the two give almost the same answer.
Can I use a t-test on Likert-scale survey answers?
It is common and usually works reasonably for averages of several Likert items or for 7-point scales with decent sample sizes, because the t-test is robust to moderate departures from normality. For a single 5-point item with few respondents, a Mann–Whitney or Wilcoxon test is the more cautious choice.
What should I report from a t-test?
The test used, the t statistic with its degrees of freedom, the p-value, the mean difference with its confidence interval, and an effect size. For example: Welch's t(17.8) = −1.86, p = 0.079, mean difference −1.58 (95% CI −3.37 to 0.21), d = −0.83.
Sources
- NIST/SEMATECH e-Handbook of Statistical Methods, §7.3.1 Do two processes have the same mean?
- NIST/SEMATECH e-Handbook of Statistical Methods, §7.2.2 Are the data consistent with the assumed process mean?
- R documentation: t.test (Student's t-test), stats package, with the sleep data examples
- B. L. Welch, The generalization of 'Student's' problem when several different population variances are involved, Biometrika 34 (1947)
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.