Statistical t test calculator: formula, steps & examples
- Degrees of freedom (Welch)
- Result
- Mean of sample 1
- 5
- You entered
- SD of sample 1
- 2
- You entered
A statistical t test calculator works out the t-statistic and p-value for a Student’s t test from your sample data. You enter the sample means, standard deviations, and sizes (or raw data), and it returns the t value, degrees of freedom, and a p-value so you can decide whether the difference between groups is statistically significant.
Formula
The calculator uses the two-sample Welch’s t test formula, which does not assume equal variances:
t = (x̄₁ − x̄₂) / √(s₁²/n₁ + s₂²/n₂)
where:
- x̄₁ and x̄₂ are the sample means (unit depends on your data, e.g., kg, cm, score)
- s₁² and s₂² are the sample variances (standard deviation squared, same unit squared)
- n₁ and n₂ are the sample sizes (counts, unitless)
The degrees of freedom for Welch’s t test are calculated with the Welch–Satterthwaite equation:
df = (s₁²/n₁ + s₂²/n₂)² / [ (s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1) ]
This df is usually not a whole number; you round it down to be conservative when looking up critical values.
Worked Example
Using the default values from the calculator: sample 1 mean = 5, SD = 2, n = 30; sample 2 mean = 4.5, SD = 2, n = 30.
- Compute the variances: s₁² = 2² = 4, s₂² = 4.
- Divide by sample sizes: 4/30 = 0.1333, 4/30 = 0.1333.
- Sum: 0.1333 + 0.1333 = 0.2667.
- Take the square root: √0.2667 = 0.5164.
- Difference of means: 5 − 4.5 = 0.5.
- t = 0.5 / 0.5164 = 0.968.
- Degrees of freedom: since both variances and sample sizes are equal, df = 30 + 30 − 2 = 58 (the Welch formula gives exactly 58 in this case).
The calculator returns t = 0.968 and df = 58.0. For a two-tailed test at α = 0.05, the critical t value is about 2.002, so this result is not significant; you would not reject the null hypothesis.
When to Use a t Test
A t test is used to compare the means of two groups when the sample size is small (typically n < 30) and the population standard deviation is unknown. It assumes the data are approximately normally distributed and that the samples are independent (unless you are using a paired t test).
Common situations:
- Comparing test scores between two classes
- Measuring the effect of a drug vs. placebo
- Comparing product weights from two production lines
- Checking if a new teaching method changes exam results
If your sample size is large (n > 30), the t test and z test give very similar results because the t distribution approaches the normal distribution.
How to Choose the Right t Test
There are three main types of t tests, and using the wrong one will give misleading results:
- Independent two-sample t test (unpaired): compares two separate groups. Use the Welch version (this calculator) when the variances are not equal, or the Student version when they are equal.
- Paired t test: compares two measurements from the same subjects (before/after). Use it when the data are paired; it reduces variability by looking at differences within each pair.
- One-sample t test: compares a sample mean to a known population mean (e.g., testing if a sample mean differs from 100).
To decide between Welch and Student, check the ratio of the larger variance to the smaller variance. If the ratio is greater than 2, use Welch’s; otherwise, the standard Student’s t test is fine. Many statisticians recommend always using Welch’s because it works well even when variances are equal.
Common Mistakes and Pitfalls
Even with a calculator, people often make these errors:
- Using the wrong standard deviation: The formula requires the sample standard deviation (SD), not the standard error (SE). SE = SD/√n; do not enter SE.
- Mixing up one-tailed and two-tailed tests: A two-tailed test checks for any difference (greater or smaller); a one-tailed test checks for a difference in a specific direction. The p-value for a two-tailed test is double the one-tailed p-value.
- Ignoring the assumptions: If your data are heavily skewed or have outliers, the t test may not be valid. Consider a non-parametric test like the Mann-Whitney U test instead.
- Rounding too early: Round only the final t value and p-value, not intermediate steps, to avoid errors.
- Confusing n with degrees of freedom: For a two-sample test, df is roughly n₁ + n₂ − 2 (when variances are equal), not n₁ + n₂.
Interpreting the Results
The calculator gives you two main numbers: the t statistic and the degrees of freedom. To make a decision, you need a p-value or a critical t value.
If you have a p-value:
- If p < 0.05 (or your chosen α), the difference is statistically significant: you reject the null hypothesis that the means are equal.
- If p ≥ 0.05, you do not have enough evidence to reject the null hypothesis. The difference could be due to chance.
If you only have the t statistic, you can compare it to a critical value from a t table using your degrees of freedom. If |t| > critical value, the result is significant.
Remember: statistical significance does not mean practical importance. A very large sample can make a tiny difference significant. Always look at the actual difference between means (effect size) to judge if it matters in the real world.
Limitations of the t Test
The t test is powerful but has limits:
- It only compares two groups; for three or more groups, use ANOVA.
- It assumes independence: if your samples are related (e.g., twins, repeated measures), use a paired t test or mixed-effects model.
- It is sensitive to outliers, which can inflate the standard deviation and reduce the t value.
- It assumes the data are continuous and roughly normally distributed. For ordinal data or clear non-normality, use a non-parametric alternative.
- It does not control for confounding variables; a significant difference does not prove causation.
For a one-sample t test, the formula changes slightly: t = (x̄ − μ) / (s/√n), where μ is the hypothesized population mean. This calculator handles the two-sample case; for one-sample, you can use a separate tool or adapt the formula manually.
Frequently Asked Questions
What is the difference between a t test and a z test?
A t test is used when the population standard deviation is unknown and the sample size is small (usually n < 30). The t distribution has heavier tails, which accounts for the extra uncertainty. A z test is used when the population standard deviation is known or the sample size is large (n > 30), because the sample mean then follows a normal distribution.
Can I use a t test with unequal sample sizes?
Yes. The Welch’s t test (used in this calculator) does not require equal sample sizes or equal variances. It adjusts the degrees of freedom to account for the imbalance. Even with very different group sizes, the test remains valid as long as the data meet the other assumptions.
How do I find the p-value from the t statistic?
You can use a t distribution table, a statistical software package, or an online p-value calculator. You need the t value, the degrees of freedom, and whether you want a one-tailed or two-tailed test. Many calculators, including this one, can provide the p-value directly if you add that output; here, we provide the t and df so you can look up the p-value.
What does a negative t value mean?
A negative t value simply means that the first sample mean is smaller than the second. The sign is arbitrary and depends on which group you label as 1 and 2. For a two-tailed test, the absolute value matters; for a one-tailed test, the sign tells you the direction of the difference.
Is the t test robust to violations of normality?
The t test is fairly robust to mild deviations from normality, especially with sample sizes above 15–20 per group. However, if the data are heavily skewed or have extreme outliers, the test can give misleading results. In such cases, consider a non-parametric test like the Mann-Whitney U test or use a transformation.
What is the difference between a one-tailed and two-tailed test?
A two-tailed test checks whether the means are different in any direction (greater or smaller). A one-tailed test checks whether one mean is specifically greater (or smaller) than the other. One-tailed tests have more power to detect a difference in the specified direction but require a strong prior justification. The p-value for a one-tailed test is half the two-tailed p-value.
Related
Formula used
in m1 | Mean of sample 1 | - | 5 | 0 in s1 | SD of sample 1 | - | 2 | 0 in n1 | Sample size 1 | - | 30 | 2 in m2 | Mean of sample 2 | - | 4.5 | 0 in s2 | SD of sample 2 | - | 2 | 0 in n2 | Sample size 2 | - | 30 | 2 out t | t statistic | - | (m1 - m2) / sqrt( (s1^2/n1) + (s2^2/n2) ) | 3 out df | Degrees of freedom (Welch) | - | ( (s1^2/n1 + s2^2/n2)^2 ) / ( (s1^2/n1)^2/(n1-1) + (s2^2/n2)^2/(n2-1) ) | 1
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.