# 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.

Interactive version: https://www.calcopenly.com/statistics/t-test-calculator
Subject: Statistics and probability calculators

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.

## Inputs

- **Test** (options: One-sample t-test, One-sample z-test (σ known), Two-sample t-test, Welch (unequal variances), Two-sample t-test, pooled variance, Paired t-test, One-proportion z-test)
- **Enter** (options: Raw data, Summary statistics)
- **Sample 1**: For a paired test, the first measurement of each pair.
- **Sample 2**: For a paired test, the second measurement, in the same order.
- **Sample 1 mean**: For a paired test, the mean of the differences.
- **Standard deviation s₁**: For a paired test, the SD of the differences.
- **Sample size n₁**
- **Sample 2 mean**
- **Standard deviation s₂**
- **Sample size n₂**
- **Known population σ**
- **Hypothesised mean μ₀**
- **Hypothesised difference Δ₀**: Mean of sample 1 minus sample 2 under H₀ (usually 0).
- **Successes x**
- **Sample size n**
- **Hypothesised proportion p₀**
- **Alternative hypothesis** (options: ≠ (two-sided), < (left-tailed), > (right-tailed))
- **Significance level α**

## Results

- p-value — main result
- Decision
- Test statistic
- Degrees of freedom
- Critical value
- Estimate
- Standard error

## Formula

$$
t = \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}}
$$

## 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

### One-proportion z, 540 of 1000 vs 0.5

- Test: One-proportion z-test
- Successes x: 540
- Sample size n: 1000
- Hypothesised proportion p₀: 0.5
- Alternative hypothesis: ≠ (two-sided)
- Significance level α: 0.05
- **Test statistic: 2.529822**
- **p-value: 0.011412**
- **Decision: Reject H₀**
- Checked against: z = 0.04/√(0.25/1000); p = erfc(z/√2) in Python

### One-sample z, right-tailed

- Test: One-sample z-test (σ known)
- Enter: Summary statistics
- Sample 1 mean: 103
- Sample size n₁: 36
- Known population σ: 15
- Hypothesised mean μ₀: 100
- Alternative hypothesis: > (right-tailed)
- Significance level α: 0.05
- **Test statistic: 1.2**
- **p-value: 0.11507**
- **Critical value: 1.6449**
- Checked against: z table: 1 − Φ(1.20) = 0.1151; Python 0.5·erfc(1.2/√2) = 0.1150697; z₀.₉₅ = 1.644854

## 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.

## Sources

- [NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.5.3 Two-sample t-test for equal means](https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm)
- [NIST/SEMATECH e-Handbook, §7.2.2 Are the data consistent with the assumed process mean?](https://www.itl.nist.gov/div898/handbook/prc/section2/prc22.htm)
- Welch, B. L. (1947). The generalization of Student's problem when several different population variances are involved. Biometrika 34, 28–35
