Calculating a P Value: Step-by-Step Guide
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
To calculate a p-value, you first compute a test statistic (like t, z, or chi-square) from your sample data, then find the probability of observing that statistic or something more extreme under the null hypothesis. The exact method depends on your test type and whether you’re doing a one-tailed or two-tailed test. This guide walks you through the general process, the formulas involved, and common pitfalls—no statistical software required.
Formula
For a z-test (when the sample size is large or the population standard deviation is known), the p-value comes from the standard normal distribution. If your test statistic is t and you have df degrees of freedom, the p-value for a two-tailed test is:
p = 2 × P(T > |t|)
where T follows a t-distribution with df degrees of freedom. For a one-tailed test, it’s simply P(T > t) (right-tailed) or P(T < t) (left-tailed). The calculator above uses a normal approximation (which works well for df > 30) to compute the p-value from your t-statistic and degrees of freedom. For exact t-distribution probabilities, you’d use statistical software or a t-table.
Worked Example
Suppose you have a t-statistic of 2.1 with 30 degrees of freedom, and you want a two-tailed p-value. Using the normal approximation:
- Compute the cumulative probability: Φ(2.1) ≈ 0.9821 (from standard normal table).
- The upper tail is 1 – 0.9821 = 0.0179.
- Two-tailed p = 2 × 0.0179 = 0.0358.
So the p-value is approximately 0.0358. This matches the calculator’s output (0.0358) when you enter t=2.1, df=30, and select Two-tailed.
What Is a P-Value, Really?
A p-value is the probability of obtaining test results at least as extreme as the ones you observed, assuming the null hypothesis is true. It’s not the probability that the null hypothesis is true, nor is it the probability that your alternative hypothesis is true. It’s a measure of how surprising your data would be if there were no real effect. A small p-value (typically < 0.05) suggests that the observed result is unlikely under the null, leading researchers to reject the null hypothesis in favor of the alternative.
How to Choose the Right Test
Before calculating a p-value, you need to pick the correct statistical test. The choice depends on:
- Data type: continuous, categorical, or ordinal.
- Number of groups: one sample, two independent samples, paired samples, or more than two groups.
- Distribution: normal or non-normal (use non-parametric tests if not normal).
- Sample size: large samples (n > 30) allow normal approximations; small samples require exact distributions.
Common tests include the t-test (comparing means), chi-square test (categorical data), ANOVA (comparing multiple means), and correlation tests. Each has its own formula for the test statistic and its own distribution for the p-value.
Common Mistakes and Misconceptions
- Confusing one-tailed and two-tailed: A two-tailed test doubles the p-value for a symmetric distribution. Always decide before running the test.
- Misinterpreting the p-value: A p-value of 0.03 does not mean there’s a 3% chance the null is true. It means that if the null were true, you’d see data this extreme 3% of the time.
- Ignoring assumptions: Using a t-test on heavily skewed data can give misleading p-values. Check normality or use a non-parametric alternative.
- Rounding too early: Rounding the test statistic before computing the p-value can change the result. Keep full precision until the end.
- Using the wrong degrees of freedom: For a t-test, df = n – 1 for a one-sample test, but for a two-sample test it’s more complex (often approximated).
How to Read the Result
Once you have a p-value, compare it to your significance level (α), usually 0.05. If p ≤ α, you reject the null hypothesis and conclude there’s evidence for the alternative. If p > α, you fail to reject the null—this doesn’t prove the null is true, just that your data isn’t strong enough to refute it. Always report the p-value with the test statistic and degrees of freedom, e.g., t(30) = 2.1, p = 0.036.
Limitations of the Formula
The normal approximation used in the calculator is accurate when df is large (roughly > 30). For small df, the t-distribution has heavier tails, and the normal approximation underestimates the p-value. For exact p-values with small samples, use a t-table or software. Also, the p-value depends on the sample size: a tiny effect can become statistically significant with a huge sample, and a large effect can be non-significant with a small sample. Always consider the effect size and practical significance, not just the p-value.
Frequently Asked Questions
What is the difference between p-value and significance level?
The significance level (α) is a threshold you set before the test, typically 0.05. The p-value is calculated from your data. You reject the null if p < α. The p-value tells you how extreme your data is, while α is the risk of a false positive you're willing to accept.
Can a p-value be exactly zero?
No. A p-value is a probability, so it’s always between 0 and 1. Very small p-values (like 0.000001) are common with large effects or big samples, but they’re never exactly zero. Software may display “< 0.0001" due to rounding.
How do I calculate a p-value from a z-score?
For a z-score, use the standard normal distribution. For a two-tailed test, p = 2 × (1 – Φ(|z|)), where Φ is the cumulative distribution function. For one-tailed, p = 1 – Φ(z) (right) or Φ(z) (left). You can find Φ(z) from a z-table or using the error function.
What if my test statistic is negative?
For a two-tailed test, the sign doesn’t matter—you take the absolute value. For a one-tailed test, the direction matters: a negative t-statistic would be significant for a left-tailed test, not a right-tailed one. Always check the direction of your alternative hypothesis.
Why do different calculators give slightly different p-values?
Differences can arise from approximations (normal vs. exact t-distribution), rounding of intermediate values, or whether the calculator uses a continuity correction. For most practical purposes, small differences (like 0.035 vs. 0.034) don’t change your conclusion.
Related
Formula used
in t | Test statistic | - | 2.1 | 0 in df | Degrees of freedom | - | 30 | 1 sel tail | Test type | Two-tailed=2, One-tailed (right)=1, One-tailed (left)=-1 out p | P-value (normal approx.) | - | (1 - 0.5 * (1 + erf(t / sqrt(2)))) * (tail == 2 ? 2 : (tail == 1 ? 1 : 0)) + (tail == -1 ? (0.5 * (1 + erf(t / sqrt(2)))) : 0) | 4
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.