CalcOpenly

t-test and z-test calculator

t-test calculator for one-sample, two-sample (Welch or pooled) and paired tests, plus z-tests for a mean or proportion: p-value, critical value, decision.

Updated Checked against 7 worked examples

For a paired test, the first measurement of each pair.
Try
p-value
p-value: 0.035527
Shown to up to 6 decimal places, half-up
Decision
Reject H₀
Test statistic
−2.395294
Degrees of freedom
11
Critical value
2.201
Estimate
498.641667
Standard error
0.567084

Reject H₀ at α = 0.05. If the true mean were 500, a result at least this extreme would turn up with probability 0.0355. The p-value is not the probability that H₀ is true, and a significant result says nothing about how large or important the effect is.

p-value area under t with 11 df (unlabelled line: t = −2.395)

00.10.20.3-4-2024tDensity−2.2012.201
How it's calculated S
  1. Hypotheses

    H0:μ=500,H1:μ≠500H_0: \mu = 500,\quad H_1: \mu \ne 500
  2. Sample summary

    xˉ=498.641667,s=1.964438,n=12\bar x = 498.641667,\quad s = 1.964438,\quad n = 12
  3. Standard error

    SE=sn=1.96443812=0.567084SE = \frac{s}{\sqrt n} = \frac{1.964438}{\sqrt{12}} = 0.567084
  4. Test statistic

    t=498.641667−5000.567084=−2.395294,ν=n−1=11t = \frac{498.641667 - 500}{0.567084} = -2.395294,\quad \nu = n - 1 = 11
  5. p-value

    p=2 P(t≥∣−2.395294∣)=0.035527177p = 2\,P(t \ge |-2.395294|) = 0.035527177
  6. Decision

    p≤α=0.05⇒reject H0p \le \alpha = 0.05 \Rightarrow \text{reject } H_0

    Equivalently, compare |t| with the critical value 2.201.

About the t-test and z-test calculator

A t-test divides the gap between a sample mean and a hypothesised value, or between two sample means, by its standard error. The ratio follows Student's t distribution with n − 1 degrees of freedom for one sample or for paired differences, n₁ + n₂ − 2 for the pooled two-sample test, and the Welch–Satterthwaite value when the variances may differ. With a known population σ the same ratio is a z statistic; the proportion test compares a sample proportion with p₀ the same way.

Quality checks, A/B tests and before-and-after studies are typical uses. The default data are 12 fill weights tested against a target of 500: the mean is 498.64, t = −2.395 on 11 df and the two-sided p = 0.0355, so the mean differs from 500 at α = 0.05.

The t-tests assume independent observations from roughly normal populations. Larger samples tolerate more skew, because the distribution of the sample mean approaches normal as n grows.

Worked examples

One-sample t on fill weights (defaults)

Test
One-sample t-test
Enter
Raw data
Sample 1
498.2, 501.3, 497.6, 499.1, 495.8, 500.4, 496.9, 498.7, 497.3, 499.8, 502.1, …
Hypothesised mean μ₀
500
Alternative hypothesis
≠ (two-sided)
Significance level α
0.05
Test statistic
-2.395294
Degrees of freedom
11
p-value
0.035527
Decision
Reject H₀
Critical value
2.201

Checked against: Python statistics.mean/stdev for t; p-value from the A&S 26.7.3 closed form for odd ν (pyref.t_cdf_int); t₀.₉₇₅,₁₁ = 2.201 (t table)

Welch t from summary statistics

Test
Two-sample t-test, Welch (unequal variances)
Enter
Summary statistics
Sample 1 mean
20.1
Standard deviation s₁
3.2
Sample size n₁
15
Sample 2 mean
17.4
Standard deviation s₂
4.8
Sample size n₂
12
Hypothesised difference Δ₀
0
Alternative hypothesis
≠ (two-sided)
Significance level α
0.05
Test statistic
1.673611
Degrees of freedom
18.3865
p-value
0.111135

Checked against: Welch–Satterthwaite df in Python fractions; p-value by Gauss–Legendre quadrature of the t density (pyref.t_sf_numeric)

Pooled t on the same summaries

Test
Two-sample t-test, pooled variance
Enter
Summary statistics
Sample 1 mean
20.1
Standard deviation s₁
3.2
Sample size n₁
15
Sample 2 mean
17.4
Standard deviation s₂
4.8
Sample size n₂
12
Hypothesised difference Δ₀
0
Alternative hypothesis
≠ (two-sided)
Significance level α
0.05
Test statistic
1.749856
Degrees of freedom
25
p-value
0.09241

Checked against: Pooled variance in Python fractions; p-value from the A&S 26.7.3 closed form with ν = 25

Paired t, right-tailed

Test
Paired t-test
Enter
Raw data
Sample 1
142 138 150 145 160 155 139 148
Sample 2
136 135 146 144 150 149 138 141
Hypothesised difference Δ₀
0
Alternative hypothesis
> (right-tailed)
Significance level α
0.05
Test statistic
4.32649
Degrees of freedom
7
p-value
0.001726
Estimate
4.75

Checked against: Differences' mean and stdev in Python statistics; p-value from the A&S closed form with ν = 7

Questions

What does a p-value tell you?

It is the probability of a test statistic at least as extreme as the one observed, assuming the null hypothesis is true. For the default data p = 0.0355: if the true mean were 500, samples at least this far from 500 would turn up about 3.6% of the time. It is not the probability that H₀ is true and it does not measure effect size, as the American Statistical Association's 2016 statement on p-values stresses.

Should I use Welch's t-test or the pooled t-test?

Use Welch's test unless you have good reason to believe the variances are equal. It drops the equal-variance assumption and loses little power when the variances do match, while the pooled test's false-positive rate drifts from α when variances and group sizes both differ. On the worked example (s = 3.2 and 4.8, n = 15 and 12) Welch gives p = 0.111 on 18.4 df and the pooled test p = 0.092 on 25 df.

When should I use a paired t-test?

When each value in one sample is matched to one in the other: the same patients before and after treatment, or two instruments measuring the same parts. The test is a one-sample t-test on the differences, which removes the variation between subjects. In the paired worked example eight pairs differ by 4.75 on average, giving t = 4.33 on 7 df and a one-sided p of 0.0017.

What is the difference between a t-test and a z-test?

A z-test uses a known population standard deviation σ and the standard normal distribution; a t-test estimates σ from the sample and uses Student's t, whose heavier tails allow for that extra uncertainty. The two-sided 5% critical value is 1.960 for z, 2.201 for t with 11 df and 2.042 with 30 df. σ is rarely known in practice, so the t-test is the usual choice for means.

Should I use a one-tailed or two-tailed test?

Use a two-tailed test unless the direction was fixed before seeing the data and an effect in the other direction would be treated the same as no effect. A one-tailed test puts all of α in one tail, so its p-value is half the two-tailed one when the effect goes the predicted way: t = −2.395 on 11 df gives 0.0355 two-tailed and 0.0178 left-tailed. Picking the tail after looking doubles the real false-positive rate.

How accurate is the t-test and z-test calculator?

Accuracy depends on your inputs and the method's assumptions. Decimal arithmetic uses 50 significant digits, but estimates, numerical methods and source data can be less precise; the displayed rounding does not remove those limits. It is checked against 7 worked examples whose answers come from independent sources; for example, “One-sample t on fill weights (defaults)” is checked against Python statistics.mean/stdev for t; p-value from the A&S 26.7.3 closed form for odd ν (pyref.t_cdf_int); t₀.₉₇₅,₁₁ = 2.201 (t table).

Where does the method come from?

NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-sample t-test for equal means; NIST/SEMATECH e-Handbook, §7.2.2 Are the data consistent with the assumed process mean?; Welch, B. L. (1947). The generalization of Student's problem when several different population variances are involved. Biometrika 34, 28–35.

About this calculator

t=xˉ−μ0s/n,tWelch=xˉ1−xˉ2−Δ0s12/n1+s22/n2,z=p^−p0p0(1−p0)/nt = \frac{\bar x - \mu_0}{s/\sqrt n},\qquad t_{\text{Welch}} = \frac{\bar x_1 - \bar x_2 - \Delta_0}{\sqrt{s_1^2/n_1 + s_2^2/n_2}},\qquad z = \frac{\hat p - p_0}{\sqrt{p_0(1-p_0)/n}}

Sources

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-sample t-test for equal means
  2. NIST/SEMATECH e-Handbook, §7.2.2 Are the data consistent with the assumed process mean?
  3. Welch, B. L. (1947). The generalization of Student's problem when several different population variances are involved. Biometrika 34, 28–35

Checked against references

7 worked examples with independently sourced answers ship with this calculator. They run in the test suite; you can run them here too.

Related calculators

Allow optional Google Analytics to measure page visits? Calculators work either way. Privacy and choices

Optional analytics: off.