Statistical foundations · optional calculation guide

Where does a p-value come from?

See how software turns a medical comparison into a test statistic, compares it with results expected under H₀ and prints a p-value.

Use this when: you understand the plain-language idea and want to see the calculation.
You will follow: data → H₀ → test statistic → reference distribution → p-value.
Main guide: What a p-value means.

The calculation

A p-value is the final step in a conditional chain.

  1. 1Observed data

    Record the group values or model coefficient.

  2. 2Null hypothesis

    Specify H₀ and the value it predicts.

  3. 3Test statistic

    Standardise the observed departure from H₀.

  4. 4Reference distribution

    Ask how that statistic behaves if H₀ and the model are correct.

  5. 5Tail probability

    Count results at least as extreme as the one observed.

The formal idea in plain language

Assuming H₀ and the statistical model are correct, the p-value is the probability of obtaining the observed test statistic, or one at least as incompatible with H₀ as the statistic actually observed.

Standalone worked example

A text reminder and clinic attendance.

Appointment messageDid not attendAttendedObserved total
Usual letter5050100
Letter plus text reminder3664100
  1. State H₀. In the target population, message type and appointment attendance are independent under the chi-square model.
  2. Calculate expected counts under H₀. Because each message group contains 100 people, the model expects 43 non-attenders and 57 attenders in each row.
  3. Measure the discrepancy. The observed cells differ from those expected counts, giving Pearson χ² ≈ 4.00 with 1 degree of freedom.
  4. Use the null reference distribution. Under H₀ and the chi-square assumptions, compare 4.00 with a χ² distribution having 1 degree of freedom.
  5. Read the tail area. The probability of χ² being at least this large is about p = 0.046.

The reminder group’s attendance was 64%, compared with 50% for the letter-only group: a difference of 14 percentage points (approximate 95% CI 0.4 to 27.6). The p-value describes the null-model compatibility; it does not measure the size, importance or cause of the difference.

What it represents

Keep compatibility separate from magnitude and truth.

It is conditional.

The calculation assumes H₀, the chosen test, sampling process and model assumptions.

It is not P(H₀ is true).

A frequentist p-value does not assign probabilities to H₀ or H₁.

It is not effect size.

Use the estimate and confidence interval for direction, magnitude and precision.

It is not clinical importance.

Compare the effect with a justified medical threshold, harms, benefits and context.

It is not causality.

Design, confounding, selection, measurement and assumptions govern causal interpretation.

It is not a selection rule.

P-values from bivariate analyses do not determine which covariates enter an adjustment set.

Check your understanding

Can you explain the printed number?

What does p ≈ 0.046 represent in the worked chi-square comparison?

Answer: assuming independence, the null hypothesis and the chi-square model are correct, a χ² statistic at least as large as about 4.00 would occur in roughly 4.6% of repeated comparable samples. It is not a 4.6% probability that H₀ is true.

Continue Learn Type I and Type II errors → Use the boy-who-cried-wolf story to separate false alarms from missed detections, then continue to multiple testing.
Go deeper · more p-value examples and software