Free tool aStat · Agriculture Statistics

t-Test Calculator: Two-Sample, Welch, Paired and One-Sample

Paste two groups, or type their means, standard deviations and sample sizes. The calculator returns t, degrees of freedom, a two-sided p-value and a 95% confidence interval. Student's two-sample test, Welch's test, a paired test and a one-sample test are all here.

  • Free, no sign-up
  • Your data stay on your computer
  • Realtime R in your browser
  • R script included
Which t-test?
How will you enter the numbers?

Two lines (one group each), or two columns. The example is five pigs on diet A and five on diet B, ADG in kg/day.

Usually 0, unless you are testing against a specific value.

t statistic

-0.117

Degrees of freedom

1.276

Two-sided p-value

0.923

95% CI

-3.359 to 3.259

For the mean difference.

t = -0.05 / 0.4272 = -0.117, df = 1.276, p = 0.923

At α = 0.05, the two-sided test does not reject the null hypothesis. The critical |t| at this df is 7.745.

Quick answers

Which t-test should I use?
Use a paired test when the same unit is measured twice, or when observations come in matched pairs. For two independent groups, Welch's test is the usual choice because it does not assume equal variances. Student's two-sample test is reasonable when the SDs are similar and the sample sizes are close. Use a one-sample test to compare one set of numbers with a fixed value.
Can I enter means and SDs instead of the raw data?
Yes. Choose “Mean, SD and sample size.” That matches a common search for a t-test from the mean and standard deviation, when the original records are not at hand.
Is this a two-sided test?
Yes. The p-value is two-sided, and the confidence interval is a 95% interval for the mean or the mean difference.
When is p below 0.05 meaningful?
It means that, if the true difference were the value in the null (usually zero), a result at least this extreme would be uncommon. It does not measure how large or useful the difference is. Look at the confidence interval as well.
On this page
  1. Quick answers
  2. The formulas the calculator uses
  3. A worked example from a pig feeding trial
  4. Assumptions, and what to do when they fail
  5. How many animals or plots you need
  6. Questions people ask
  7. Sources

The formulas the calculator uses

For a one-sample test of mean μ against a value μ0, t = (x̄ − μ0) / (s / √n) with n − 1 degrees of freedom. A paired test is the same calculation on the differences. Student's two-sample test uses a pooled variance and n1 + n2 − 2 degrees of freedom. Welch's test uses separate variances and the Welch–Satterthwaite degrees of freedom (Snedecor and Cochran, 1989, ch. 6).

Welch df = (s₁²/n₁ + s₂²/n₂)² / [(s₁²/n₁)²/(n₁−1) + (s₂²/n₂)²/(n₂−1)]

The p-value comes from the Student t distribution with that many degrees of freedom. The 95% interval is the mean (or mean difference) plus or minus t0.975, df times the standard error. There is a full walkthrough, with rank-test alternatives, in the t-test chapter.

A worked example from a pig feeding trial

Five pigs on diet A gained 2.4, 2.7, 2.5, 2.8 and 2.6 kg/day. Five pigs on diet B gained 2.1, 1.9, 2.2, 2.0 and 2.3 kg/day. These are illustrative numbers, of the same kind as the pig trial in the guide. The means are 2.60 and 2.10 kg/day; both sample SDs are 0.158 kg/day. Welch's t is 4.99 on 8 degrees of freedom, p = 0.001, and the 95% interval for the difference (A − B) is about 0.27 to 0.73 kg/day. The same figures go into the boxes if you prefer to enter the means and SDs.

Assumptions, and what to do when they fail

Independent observations, a simple random sample or a properly randomized experiment, and a roughly normal distribution of the means (or of the differences, in a paired test). With small samples, a skewed trait can mislead the p-value. Check the shape with the Shapiro-Wilk tool, or read the t-test chapter for the Wilcoxon and Mann–Whitney alternatives. For more than two groups, use the ANOVA calculator rather than a stack of t-tests.

How many animals or plots you need

A significant result in a tiny trial can still be too imprecise to use, and a real difference can be missed if the sample is small. Plan the number of replicates before you start. This site has a and a fuller planner, including ANOVA, under Plan a study. The power chapter explains the ideas.

Questions people ask

What is Welch's t-test?

A two-sample t-test that does not assume the two groups share a variance. The standard error uses each group's own SD, and the degrees of freedom are fractional. It is a good default for independent groups.

Student's t-test or Welch's?

If the SDs are clearly different, use Welch. If they are similar and the sample sizes are close, the two tests almost agree. Welch is the safer default when you are unsure.

Can I use this for a one-tailed test?

The reported p-value is two-sided. For a pre-planned one-sided test in the observed direction, halve that p-value. Do not switch to one-sided after seeing the data.

Does the calculator send my data to a server?

No. The arithmetic runs in your browser. Nothing is uploaded.

Sources

  • Snedecor, G. W., and Cochran, W. G. (1989). Statistical Methods (8th ed.). Iowa State University Press, ch. 6.
  • Welch, B. L. (1947). The generalization of “Student's” problem when several different population variances are involved. Biometrika, 34, 28–35.
  • Satterthwaite, F. E. (1946). An approximate distribution of estimates of variance components. Biometrics Bulletin, 2, 110–114.