Skip to main content
v2026.11,858 entries · CC-BY 4.0

Test Statistic Formula: Definition, Examples and How to Calculate

What a test statistic is, the formula for t and other common statistics, a worked example with arithmetic, how to read and report it, and code in Excel, R and Python.

Written and maintained by CASRAI Editorial Board

Last updated

A test statistic is a single number computed from your sample data that measures how far the data sit from what the null hypothesis predicts. You compare it with a critical value, or convert it to a p-value, to decide whether the data are surprising enough to reject the null hypothesis. This guide gives the formula for the most common case (the t statistic), a worked example with every step of the arithmetic, how to read the result, common mistakes, and how to calculate it in Excel, R and Python. Formulas and the worked example follow the NIST/SEMATECH e-Handbook of Statistical Methods, checked on 2026-10-28.

What is a test statistic?

NIST puts it this way: critical values for a test of hypothesis “depend upon a test statistic, which is specific to the type of test.” The null hypothesis is rejected if the test statistic lies in the rejection region, the range of values the statistic is unlikely to take when the null hypothesis is true. Different tests use different statistics, so “the test statistic formula” depends on which test you are running. The statistic compresses the whole sample into one number, which makes a decision rule possible. For the wider idea of a test, see the CASRAI entry on statistical test, and for how the statistic maps to a probability, p-value.

Test statistic formula for the one-sample t-test

When you compare a sample mean with a hypothesised value and the population standard deviation must be estimated from the data (the more typical case), NIST gives:

t = (Ybar - mu0) / (s / sqrt(N))
  • Ybar is the sample mean.
  • mu0 is the value of the mean stated in the null hypothesis, H0: mu = mu0.
  • s is the sample standard deviation, computed with N – 1 in the denominator.
  • N is the sample size. The statistic has N – 1 degrees of freedom.

The numerator measures the distance between what you observed and what the null hypothesis says. The denominator, s divided by the square root of N, is the standard error of the mean, so the statistic is a distance measured in standard errors.

Test statistic formula for the two-sample t-test

For two independent samples with unequal variances, NIST gives:

T = (Y1bar - Y2bar) / sqrt(s1^2 / N1 + s2^2 / N2)

Here N1 and N2 are the sample sizes, Y1bar and Y2bar the sample means, and s1^2 and s2^2 the sample variances. The null hypothesis is that the two means are equal, and NIST rejects it if |T| exceeds the critical value t(1 – alpha/2, nu), where nu is the degrees of freedom.

Test statistic examples with the arithmetic shown

Example 1: one-sample t-test (NIST wafer example)

NIST tests whether the process average for wafer particle counts, historically 50 counts per wafer, still holds in a sample of 10 silicon wafers. The counts are 50, 48, 44, 56, 61, 52, 53, 55, 67 and 51. The test is two-sided at alpha = 0.05.

  1. Sample mean: the counts sum to 537, so Ybar = 537 / 10 = 53.7.
  2. Sample standard deviation: s = 6.567 (NIST reports 6.567 counts).
  3. Standard error: 6.567 / sqrt(10) = 6.567 / 3.1623 = 2.077.
  4. Test statistic: t = (53.7 – 50) / 2.077 = 3.7 / 2.077 = 1.782.
  5. Critical value with 9 degrees of freedom: t(0.975, 9) = 2.262.
  6. Decision: |1.782| is less than 2.262, so the test statistic is outside the rejection region and the null hypothesis is not rejected. NIST concludes that “we cannot reject the null hypothesis and, therefore, we may continue to assume the process mean is 50 counts.”

Example 2: two-sample t-test (small illustrative data)

These numbers are invented for illustration. Group A: 12, 15, 14, 10, 13, 16. Group B: 9, 11, 10, 8, 12, 10.

  1. Means: Y1bar = 80 / 6 = 13.333 and Y2bar = 60 / 6 = 10.
  2. Sample variances (N – 1 denominator): s1^2 = 4.667 and s2^2 = 2.
  3. Standard error: sqrt(4.667 / 6 + 2 / 6) = sqrt(0.7778 + 0.3333) = sqrt(1.1111) = 1.054.
  4. Test statistic: T = (13.333 – 10) / 1.054 = 3.162.

Run as a Welch test in software, this gives about 8.6 degrees of freedom and p of about 0.012.

How to interpret a test statistic

What you see What it means
Statistic near 0 The sample is close to what the null hypothesis predicts.
Statistic far from 0 (large absolute value) The sample is far from the null prediction, measured in standard errors.
Statistic beyond the critical value It lies in the rejection region, so the null hypothesis is rejected at that alpha.
Statistic inside the critical values The null hypothesis is not rejected. This is not proof that it is true.

The p-value is the other route to the same decision. NIST defines it as the probability of the test statistic being at least as extreme as the one observed, given that the null hypothesis is true; the null hypothesis is rejected if the p-value is smaller than alpha. NIST also notes that alpha = 0.05 “implies that the null hypothesis is rejected 5 % of the time when it is in fact true.”

For a one-sided test, NIST rejects with Ha: mu > mu0 if T > t(1 – alpha, nu), and with Ha: mu < mu0 if T < t(alpha, nu). A two-sided test splits alpha between the two tails.

Assumptions and common mistakes

  • Using the wrong statistic for the design. The one-sample, two-sample and other formulas answer different questions. Pick the test first, then the statistic.
  • Confusing a sample standard deviation with a standard error. The denominator of the t statistic is s / sqrt(N), not s.
  • Forgetting the degrees of freedom. The critical value depends on them (N – 1 in the one-sample case).
  • Treating “not rejected” as “proved”. Failing to reject means the data are compatible with the null hypothesis, not that it is established.
  • Ignoring the model assumptions. t-tests assume the data are suitably close to normally distributed or the sample is large enough; see the Shapiro-Wilk test in R for one normality check, and the Kruskal-Wallis test in R for a rank-based alternative when comparing groups.
  • Mixing tails. Using a one-sided critical value for a two-sided hypothesis changes the error rate.

How to report a test statistic

Reporting conventions differ between style guides, so check the one your journal or institution requires. A typical pattern gives the statistic, its degrees of freedom, and the exact p-value, for example: t(9) = 1.78, p = .108 for Example 1 (the p-value is computed in the code below). Add the sample means and standard deviations, and an effect size or confidence interval if your style asks for them.

How to calculate a test statistic in Excel, R or Python

Excel

With the counts in cells A2:A11 and the hypothesised mean of 50:

=(AVERAGE(A2:A11)-50)/(STDEV.S(A2:A11)/SQRT(COUNT(A2:A11)))
=T.INV.2T(0.05, 9)

The first formula returns 1.782 and the second the two-sided critical value, 2.262.

R

x <- c(50, 48, 44, 56, 61, 52, 53, 55, 67, 51)
t.test(x, mu = 50)

Python

from scipy import stats

x = [50, 48, 44, 56, 61, 52, 53, 55, 67, 51]
result = stats.ttest_1samp(x, popmean=50)
print(result.statistic, result.pvalue)  # about 1.7818 and 0.1085

a = [12, 15, 14, 10, 13, 16]
b = [9, 11, 10, 8, 12, 10]
print(stats.ttest_ind(a, b, equal_var=False))  # statistic about 3.162

Frequently asked questions

What is a test statistic?

A number calculated from sample data that summarises how far the sample is from the null hypothesis. It is compared with critical values, or turned into a p-value, to decide whether to reject the null hypothesis.

What is the test statistic formula?

It depends on the test. For a one-sample t-test it is t = (Ybar – mu0) / (s / sqrt(N)); for a two-sample t-test with unequal variances it is T = (Y1bar – Y2bar) / sqrt(s1^2/N1 + s2^2/N2).

How do I know whether to reject the null hypothesis?

Reject it if the test statistic falls in the rejection region, meaning it is beyond the critical value, or equivalently if the p-value is smaller than alpha.

What is the difference between a test statistic and a p-value?

The test statistic is the distance measure computed from the data. The p-value is the probability of a statistic at least as extreme as the one observed if the null hypothesis is true.

Can a test statistic be negative?

Yes. For the t statistics above the sign shows which mean is larger. NIST’s two-sample example reports T = -12.62059. For a two-sided test, the absolute value is compared with the critical value.

Where can I read the basics of statistics first?

See what is statistics for an overview, and z-scores in SPSS for a related standardised score.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Test Statistic Formula: Definition, Examples and How to Calculate

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.