What a Test Statistic Is and Why You Calculate It
A test statistic is a single number you calculate from your data to decide whether a pattern you see is real or just random chance. It measures how far your actual results are from what you would expect if nothing unusual were happening. You use this number to answer questions like "Did this medicine actually work?" or "Is this coin really fair?" rather than guessing.
The test statistic itself is not the final answer—it is the raw material you feed into a statistical test. Once you have it, you compare it to a threshold (called a critical value) or convert it to a probability (called a p-value) to make a decision. Different situations call for different test statistics, and the formula you use depends on what kind of data you have and what question you are asking.
Key Takeaways
- The formula for your test statistic depends on whether you are comparing one group to a known value, two groups to each other, or looking at a relationship between variables.
- A t-statistic compares a sample mean to an expected value and accounts for sample size and variability; a z-statistic does the same thing when your sample is large or the population standard deviation is known.
- Chi-square tests work with categories and counts rather than measurements, comparing what you observed to what you would expect by chance.
- After you calculate your test statistic, you look it up in a table or use software to find the p-value, which tells you how likely your result would be if there were no real effect.
The T-Statistic: Comparing a Sample to a Known Value
The t-statistic is the most common test statistic in practice. Use it when you have a small to medium sample (usually fewer than 100 observations) and you want to know whether your sample mean differs from a known or expected value. The formula is:
t = (sample mean − expected value) / (standard error)
The standard error is your sample standard deviation divided by the square root of your sample size. Here is a concrete example: suppose you measure the weight of 25 bags of flour labeled as 5 pounds. Your sample mean is 4.92 pounds and your sample standard deviation is 0.18 pounds. The expected value is 5 pounds.
First, calculate the standard error: 0.18 ÷ √25 = 0.18 ÷ 5 = 0.036. Then calculate t: (4.92 − 5) / 0.036 = −0.08 / 0.036 = −2.22. Your t-statistic is −2.22. The negative sign just means your sample is below the expected value; what matters for the test is the absolute size of the number.
The T-Statistic: Comparing Two Groups
When you have two separate groups and want to know whether their means differ, you use a slightly different t-statistic formula. This is called a two-sample t-test. The formula is:
t = (mean of group 1 − mean of group 2) / (pooled standard error)
The pooled standard error combines the variability from both groups and accounts for their sizes. If your groups are roughly the same size and have similar spread, you can use the simpler pooled formula. If they differ a lot, use Welch's t-test instead (most statistical software does this automatically).
Example: You test two fertilizers on tomato plants. Group 1 (fertilizer A) has 15 plants with a mean height of 24 inches and standard deviation of 2.1 inches. Group 2 (fertilizer B) has 15 plants with a mean height of 22 inches and standard deviation of 1.9 inches. The pooled standard error works out to about 0.76. Your t-statistic is (24 − 22) / 0.76 = 2 / 0.76 = 2.63.
The Z-Statistic: When Your Sample Is Large
The z-statistic works the same way as the t-statistic but is used when your sample is large (usually 100 or more) or when you already know the population standard deviation. The formula is:
z = (sample mean − expected value) / (standard error)
The calculation is identical to the t-statistic; the only difference is which table you look the result up in afterward. With large samples, the t-distribution and normal distribution become nearly identical, so it does not matter much which one you use. Most software will handle this choice for you automatically.
Use z-statistics also when you are working with proportions (percentages) rather than measurements. For example, if you survey 200 people and find that 68% prefer Brand A, and you want to test whether this differs from a claimed 60%, you would calculate a z-statistic for proportions.
The Chi-Square Statistic: Working with Categories
The chi-square statistic is used when your data are counts in categories rather than measurements. It compares what you actually observed to what you would expect by pure chance. The formula is:
χ² = Σ [(observed − expected)² / expected]
This means: for each category, subtract the expected count from the observed count, square the result, divide by the expected count, then add all these values together. Example: you roll a die 60 times. If it is fair, you expect each face to come up 10 times. You actually get: 1 appears 12 times, 2 appears 8 times, 3 appears 11 times, 4 appears 9 times, 5 appears 10 times, 6 appears 10 times.
For face 1: (12 − 10)² / 10 = 4 / 10 = 0.4. For face 2: (8 − 10)² / 10 = 4 / 10 = 0.4. Continue for all six faces and add them up. Your chi-square statistic is about 1.2. A larger chi-square means the observed counts are further from what you would expect by chance.
Looking Up Your Test Statistic and Finding the P-Value
Once you have calculated your test statistic, you need to convert it to a p-value to make a decision. The p-value is the probability that you would see a result this extreme (or more extreme) if there were actually no real effect. You look up your test statistic in a table or use software to find this probability.
For a t-statistic, you use a t-table and look up your calculated value using the degrees of freedom (usually your sample size minus 1, or sample size minus 2 if you have two groups). For a z-statistic, you use a standard normal table. For chi-square, you use a chi-square table. Most statistical software (Excel, R, Python, SPSS) will calculate the p-value for you automatically once you enter your data and choose the test.
The standard threshold is p = 0.05. If your p-value is smaller than 0.05, you conclude that the pattern in your data is unlikely to be due to chance alone. If it is larger than 0.05, you do not have enough evidence to reject the idea that the pattern happened randomly. This threshold is a convention, not a law—some fields use 0.01 or 0.10 depending on the stakes.
Common Mistakes When Computing Test Statistics
One frequent error is using the wrong formula for your situation. If you have two groups, do not use a one-sample t-test; if your data are counts, do not use a t-test at all. Always check what type of data you have and what question you are asking before you pick a formula.
Another mistake is forgetting to account for sample size. A difference of 2 pounds in average weight is huge if you measured 1,000 bags but trivial if you measured 5 bags. The test statistic automatically scales for sample size, so a larger sample makes the test statistic larger even if the difference stays the same. This is correct behavior—larger samples give you more confidence in small differences.
A third error is confusing the test statistic with the p-value. The test statistic is the raw number you calculate; the p-value is what you look it up to find. They are not the same thing, and you need both to make a decision. Also, do not round your test statistic too early in the calculation—keep at least three decimal places until the end to avoid rounding errors that can change your p-value.
Frequently Asked Questions
Can I calculate a test statistic by hand or do I need software?
You can calculate by hand for small samples, but it is tedious and error-prone. For a single t-statistic with 20 observations, hand calculation takes 10 minutes. For chi-square with 8 categories, it takes 15 minutes. For anything larger or more complex, use Excel, Google Sheets, R, or Python—they are free and much faster. Hand calculation is useful for understanding what the formula does, not for real work.
What if my test statistic is negative?
A negative test statistic just means your sample is below the expected value (for a one-sample test) or one group is lower than the other (for a two-sample test). The sign does not matter for the p-value—a t-statistic of −2.5 and +2.5 have the same p-value. What matters is the absolute size of the number.
How do I know which test statistic to use?
Ask yourself three questions: (1) Do I have measurements or counts? (2) Am I comparing one group to a known value, two groups to each other, or more than two groups? (3) Is my sample small (under 100) or large? Measurements + one group + small sample = t-statistic. Measurements + two groups + small sample = two-sample t-statistic. Counts + any comparison = chi-square. Measurements + large sample = z-statistic. A statistics textbook or your software's help menu can confirm.
What does a very large test statistic mean?
A very large test statistic (like 5 or 10) means your data are far from what you would expect by chance. This usually leads to a very small p-value (close to 0), which means you have strong evidence that the pattern is real. However, a large test statistic does not tell you whether the difference is practically important—a tiny difference can produce a large test statistic if your sample is huge.
Can the test statistic be zero?
Yes. A test statistic of zero means your sample result exactly matches the expected value (or the two groups have identical means). This is extremely rare in real data. A test statistic near zero leads to a p-value near 0.5, meaning your data are consistent with random chance and you have no evidence of a real effect.