CompoundPage

Test Statistic Calculator

The test statistic calculator gives the statistic, its p-value both ways, the critical value and the interval. It also says what a p-value does not tell you, which is most of what people read into it.

Every field is shown; each one's help says which tests read it.

Set before looking at the data, not after.

All three p-values are shown; this picks the one the decision uses. A chi-square test of fit or independence is upper-tailed whichever you pick.

One-sample z and t tests, group 1 of the two-sample test, and the mean in z score mode.

The sample SD for a t test; the known population SD for a z test; the SD in z score mode. Group 1 in the two-sample test.

One-sample tests, and group 1 of the two-sample test.

One-sample tests: the value the null hypothesis says the mean is.

Two-sample test only.

Two-sample test only.

Two-sample test only.

Paired test only: the average of (after - before), one difference per pair.

Paired test only. The SD of the differences, not of either set of measurements.

Paired test only.

Two-sample and paired tests. Almost always 0: no difference.

z score mode: scored against the mean and standard deviation above.

p-value mode: the z, t or chi-square value you already have.

p-value mode only.

p-value mode, for t and chi-square. A Welch df with decimals is fine.

t statistic-2.295

t statistic (497.2 - 500) / (6.1 / sqrt 25) = -2.8 / 1.22. The denominator is the standard error: how much a sample mean of this size wobbles from sample to sample.
-2.295
Degrees of freedom n - 1. One is used up estimating the mean the spread is measured around.
24
p-value, two-tailed For an alternative of not equal: a result at least 2.295 standard errors from 500 in either direction.
0.0308
p-value, one-tailed (greater) P(t >= -2.295), for an alternative of greater than 500.
0.9846
p-value, one-tailed (less) P(t <= -2.295), for an alternative of less than 500.
0.0154
Critical value at alpha = 0.05 Reject when |t| exceeds it: the rejection region is split between both tails.
+/-2.064
Decision at alpha = 0.05 p = 0.0308 is below 0.05. If the true mean were 500, a result this far out in either direction would turn up 3.08% of the time by chance. That is rare enough to clear the bar you set. It does not say how large or how important the difference is.
Reject the null
95% confidence interval for the mean 497.2 +/- 2.064 x 1.22. It excludes 500, which is the same verdict as the test. Its width is the honest summary of how much the sample pins down.
494.68 to 499.72
Effect size (Cohen's d) The difference in standard deviations of the data, not of the mean. Unlike the statistic, it does not grow with the sample. Cohen's rough labels are 0.2 small, 0.5 medium, 0.8 large; these are conventions, not rules.
-0.459
Critical values of t on 24 degrees of freedom
AlphaOne-tailedTwo-tailedYour -2.295
0.20.857+/-1.318beyond both
0.11.318+/-1.711beyond both
0.051.711+/-2.064beyond both
0.022.172+/-2.492one-tailed only
0.012.492+/-2.797inside both
0.0013.467+/-3.745inside both
  • The p-value is the probability of a result at least this extreme IF the null hypothesis were true. It is not the probability that the null is true, and 1 minus it is not the probability your hypothesis is right.
  • Statistical significance is not practical significance. With a large enough sample a difference too small to matter is significant; the confidence interval and the effect size say whether it is big enough to care about.
  • Not rejecting the null is not evidence that it is true. It means this sample could not tell the difference from noise.
  • Pick the alternative and alpha before you look at the data. Switching to one-tailed after seeing the direction halves the p-value without any new evidence.
  • The t test assumes independent observations and a roughly normal population, or a sample large enough for the mean to be close to normal anyway. Mild skew does it little harm; outliers do.

How the Test Statistic Calculator works

A test statistic measures how far a sample result sits from what the null hypothesis predicts, in units of the result's own uncertainty. For a mean that is one line: the difference between the sample mean and the hypothesized mean, divided by the standard error. Everything else this calculator reports follows from that number and the distribution it is read against.

Take the default. A filling machine is meant to put 500 g in each pack; a sample of 25 packs averages 497.2 g with a standard deviation of 6.1 g. The standard error is 6.1 divided by the square root of 25, which is 1.22 g: how much a mean of 25 packs moves from sample to sample. The shortfall of 2.8 g is 2.8 / 1.22 = 2.295 standard errors, so t = -2.295. Read against Student's t distribution on 24 degrees of freedom, a result that far from 500 in either direction turns up about 3.1% of the time if the machine is in fact right. That is below 0.05, so at that level the null is rejected.

z or t. A z test reads the statistic against the normal distribution and is right only when the population standard deviation is known in advance. Outside textbooks and a few calibrated processes, it is not. When the SD is estimated from the same sample, the estimate itself wobbles, and Student's t distribution accounts for that with fatter tails. The difference is real at small n: the two-tailed 5% critical value is 2.064 for t on 24 df against 1.960 for z. By about a thousand observations the two agree to two decimals, so using t whenever the SD came from the data is never wrong.

Degrees of freedom are the sample size less the number of quantities estimated before the spread could be measured. A one-sample or paired test spends one on the mean, so df = n - 1.

Two samples. Comparing two group means, the standard error combines both groups' variances. Welch's test lets each group keep its own variance and computes a fractional df from the Welch-Satterthwaite formula. The older Student version pools the two variances into one, assuming they are equal. When the groups have different spreads and different sizes, the pooled test can be badly wrong in either direction, while Welch's loses almost nothing when the variances do happen to match. That is why it is the default in R's t.test. This calculator shows both. On the default two-sample inputs they disagree: pooled gives p = 0.042 and clears 0.05, Welch gives p = 0.055 and does not, because the smaller group has the larger spread and pooling understates the uncertainty that brings.

Paired data (the same people before and after, or two measurements on each unit) is not two samples. Subtract within each pair and run a one-sample t test on the differences. Pairing removes the person-to-person variation, which is usually most of it, so a paired test on the same data is far more sensitive than a two-sample one. It needs the standard deviation of the differences, not of either set of measurements.

One tail or two. A two-tailed test counts a result in either direction as evidence. A one-tailed test puts all of alpha in one tail, so it rejects with a smaller statistic and is blind to an effect in the other direction. It is legitimate only when that direction was decided before the data were seen and an effect the other way would lead to the same action as no effect.

What the p-value is not. It is the probability of data at least this extreme if the null were true. It is not the probability that the null is true, not the probability the result is a fluke, and not a measure of how large or important the effect is. A big sample makes trivial differences significant; a small one leaves real differences undetected. That is why the page also gives the confidence interval (the range of values the data are consistent with) and an effect size, which measures the difference in standard deviations of the data and does not grow with n. A result can be statistically significant and practically meaningless, and a non-significant result is not evidence that there is no effect.

The other modes cover the neighboring questions. A z score places a single value against a mean and SD, with its percentile under a normal curve. The p-value mode reads any z, t or chi-square statistic you already have; chi-square tests of fit and independence are upper-tailed by construction. For a difference between two conversion rates or other proportions, use the A/B test calculator, which runs the two-proportion z test.

The distributions are computed directly rather than looked up: the normal by Hart's rational approximation and a continued fraction in the tail, t through the regularized incomplete beta function, and chi-square through the incomplete gamma function. Each tail is computed as itself rather than as one minus the other, so a p-value of 1e-12 is reported as that and not as zero.

Test Statistic Calculator FAQ

How do you calculate a test statistic?

Subtract the value the null hypothesis predicts from the sample result, then divide by the standard error. For a one-sample mean that is (sample mean - hypothesized mean) / (SD / square root of n). The result is a z statistic if the SD is the known population value and a t statistic, on n - 1 degrees of freedom, if it was estimated from the sample.

When should I use a z test instead of a t test?

Only when the population standard deviation is known before you collect the data. If the SD comes from the sample, use the t test. At large sample sizes the two give nearly the same answer, so the t test is never the wrong choice when the SD was estimated.

What is the difference between Welch's t test and Student's t test?

Student's two-sample test pools both groups' variances into one, assuming they are equal. Welch's keeps them separate and adjusts the degrees of freedom. When the variances or the group sizes differ, the pooled test can give misleading p-values; Welch's is accurate either way, which is why it is the usual default.

Does a p-value of 0.03 mean there is a 3% chance the null hypothesis is true?

No. It means that if the null were true, a result at least this extreme would occur 3% of the time. The probability that the null is true depends on how plausible it was before the data, which a p-value does not use.

How do I find a critical value?

It is the point of the reference distribution beyond which the tail area equals alpha (one-tailed) or alpha / 2 in each tail (two-tailed). For z at 0.05 that is 1.645 one-tailed and 1.960 two-tailed; for t it depends on the degrees of freedom and is larger at small samples. The table above lists them at the usual alphas for your df.

Related calculators

Embed this calculator
<div id="compoundpage-test-statistic-calculator"></div>
<script src="https://compoundpage.com/embed/test-statistic-calculator.js" async></script>

The same calculation as JSON