Contents/ Part XXVII · Capstone Projects: Statistical Testing/ Chapter 162

Did the Program Lower Blood Pressure?

Capstone 3. The same patients, measured before and after an eight-week program. Because each person is measured twice, we compare each patient to themselves and study the change. A paired-design pass through the framework, ending with the one question a before-and-after test cannot answer on its own.

⏱️ ~16 min read
🧪 Paired t-test
📊 Chapter 162

Capstones 1 and 2 compared separate things: a mean to a target, then two independent groups. This one compares a group to itself. When the same patients are measured before and after a treatment, the two columns are not independent, they are linked person by person, and using that link is the whole point of the paired t-test.

The brief
Setting
A clinic enrolled hypertensive patients in an eight-week lifestyle-and-medication program and measured each person's systolic blood pressure at the start and at the end.
The question
Did systolic blood pressure change over the eight weeks?
Why it matters
The clinic is deciding whether to keep funding the program. A drop worth having is one large enough to matter clinically, not merely one small enough to be detected.
What we do
Analyze the two readings as pairs with a paired t-test, report the mean change in mmHg with its interval, and then confront what the missing control group does to the conclusion.
The paired t-test is a one-sample t-test on the differences. For each subject you compute after minus before, then test whether the mean of those differences is zero. Its assumption is that the differences are roughly normal, and its rank-based twin is the Wilcoxon signed-rank test.
🩺
The finding, up front

Across 55 patients, systolic blood pressure fell about 7 mmHg (146.7 to 139.5). The paired test leaves no doubt, t(54) = 7.37, p < 0.001, with a 95% interval for the drop of [5.3, 9.3] mmHg. The catch, and the real lesson, is that a single before-and-after group cannot prove the program caused it.

1

The Question, the Hypotheses, the Design

A clinic enrolled hypertensive patients in an eight-week lifestyle-and-medication program and measured each person's systolic blood pressure at the start and at the end. The question is whether blood pressure changed.

Framework stepThis project
GoalDecide whether mean systolic BP changed from before to after the program.
HypothesesH₀: mean change = 0  vs  H₁: mean change ≠ 0, two-sided, α = 0.05.
Data typeTwo continuous readings per patient (sbp_before, sbp_after), in mmHg.
DesignPaired (within-subject): the same people measured twice. Not two independent groups.
2

Meet the Data, Then Clean It

The export has 64 rows for 62 patients, and a paired analysis has a strict requirement: a patient is only usable if they have both readings. So the cleaning is: drop duplicate rows, drop patients missing a follow-up (the dropouts), and drop impossible values (a real systolic BP lies between 70 and 250 mmHg, so a 0, a 29, and a 300 all go). That leaves 55 complete pairs.

The right first picture for paired data is a line per patient, from their before value to their after value.

Two panels. On the left, a paired plot: one thin gray line per patient connecting their before reading to their after reading, with most lines sloping downward, and a thick gold line showing the group mean falling from about 147 to about 139 mmHg. On the right, a histogram of each patient's change (after minus before): most of the mass is to the left of a dashed red 'no change' line at zero, meaning most patients dropped.
Left: each patient's before-to-after line (gray), with the mean in gold. Most slope down. Right: the distribution of the change per patient sits mostly left of zero (dashed red), which is exactly what the test measures.

Before averaged 146.7 mmHg, after averaged 139.5, so the mean change is about 7 mmHg down. Whether that drop is real is the question, but first it is worth seeing why the paired design is the strong way to ask it.

3

Why a Paired Test, and What It Assumes

Patients differ hugely from one another in baseline blood pressure. If we treated the before and after columns as two independent groups, all that person-to-person variation would swamp the eight-week change we care about. Pairing removes it: by taking each patient's own change, the differences between people cancel out, and only the change is left. The paired t-test is then just a one-sample test asking whether those changes average to zero.

A paired test collapses two columns into one: the change 1 · SAME PATIENT, TWICE beforeafter people differ; the link matters 2 · ONE NUMBER EACH after − before the change for that patient person-to-person spread cancels 3 · TEST vs ZERO is the mean change 0? one-sample t on the differences (Wilcoxon if not normal)
What pairing buys you here

Before and after correlate at 0.85 (same people), and using that link shrinks the standard error from 2.44 mmHg (if we wrongly treated the columns as independent) to 0.99 mmHg, about two and a half times more precise. The same data gives a paired t of 7.4 but an independent-samples t of only 3.0. Same numbers, far more power, purely from respecting the design.

Because the paired test works on the differences, its assumption is about the differences, not the raw readings: the changes should be roughly normal. Shapiro-Wilk gives p = 0.89, and the Q-Q plot agrees, so the assumption holds and no transformation is needed.

Two panels checking the normality of the differences. On the left, a histogram of the per-patient changes with a fitted normal curve overlaid; the bars follow the bell shape and are centered below zero. On the right, a normal quantile-quantile plot of the differences where the points fall close to the straight diagonal line. The left panel title reports a Shapiro-Wilk p-value of 0.89.
The assumption check is on the changes, not the raw readings. They track a normal curve and hug the Q-Q line (Shapiro-Wilk p = 0.89), so the paired t-test is valid; we run Wilcoxon as a backup anyway.
4

Run the Test, Report the Whole Result

The paired t-test asks how far the mean change (about 7 mmHg down) sits from zero, in standard-error units. With the tiny paired standard error, that is more than seven standard errors away, which chance does not produce.

Paired t
7.37
on 54 degrees of freedom
p-value
< 0.001
about 1 × 10−9
95% CI for the change
−9.3 to −5.3
mmHg, excludes 0
Cohen's dz
0.99
a large effect

In plain terms: we are 95% confident the true average drop is between 5.3 and 9.3 mmHg, and because that whole range is below zero, blood pressure genuinely fell. The Wilcoxon signed-rank test agrees (p well below 0.001), so the result does not depend on the differences being exactly normal.

A histogram of the per-patient changes in systolic blood pressure. A dashed red line marks zero (no change). A solid dark line marks the mean change at about minus 7 mmHg, and a shaded gold band spanning minus 9.3 to minus 5.3 mmHg marks the 95% confidence interval. The entire band lies to the left of zero.
The result in one picture: the mean change and its 95% interval (gold band) sit entirely to the left of zero (dashed red). An interval for the change that misses zero is a significant change.
A confidence interval for the change that misses 0 rejects H₀ −12 −8 −4 0 change in systolic BP, after − before (mmHg) · the interval clears 0, so reject H₀ 0 = no change (H₀) 95% CI [−9.3, −5.3] 7.3 mmHg drop
5

The Verdict, and the Missing Control Group

Statistically the answer is settled: blood pressure fell by about 7 mmHg, a large and, clinically, meaningful drop, a sustained 5-to-10 mmHg reduction measurably lowers cardiovascular risk. But the framework's last step is where this project earns its keep, because the honest verdict has a sharp limit.

The test proves change, not cause

There was no control group. The paired t-test proves blood pressure changed; it cannot prove the program caused the change, because other explanations fit the same data just as well.

Why a single before-and-after can mislead THIS STUDY: ONE ARM 7 mmHg drop observed program? placebo? regression? natural? · can't tell WITH A CONTROL ARM (ILLUSTRATIVE) Control ~4 Program ~7 = true effect ~3 the control also drops (placebo, regression, time); the gap is the program
6

The Paired t-Test in Data Science & AI

Any time the same units are measured under two conditions, pairing applies, and it appears often in data and ML work.

Where it appearsThe two measurements
Model A vs B, same itemsTwo models scored on the same test examples: compare their per-item errors as pairs.
Before / after a changeLatency or accuracy on the same requests, measured before and after a code change.
Within-user experimentsEach user tried both variants (a crossover design), so the two readings are paired.
Repeated benchmarksThe same benchmark suite run on two configurations of one machine.
Practice note

Pairing is the cheapest power boost in statistics: when a comparison can be run on the same units, a paired test often needs a fraction of the sample a between-group test would. The same warning from this chapter applies, though: a before-and-after measurement shows a change but not its cause, so for causal claims you still need a control or a proper experiment.

7

Estimate, and Ask What Age Was Doing

QuantityEstimate95% confidence interval
Change in systolic BP−7.27 mmHg−9.25 to −5.29 mmHg
Cohen's dz0.990.71 to 1.39 (bootstrap)
Before/after correlation0.850.78 to 0.90 (bootstrap)

A cardiologist asking whether the drop clears a 5 mmHg clinical threshold now gets a straight answer: probably, but the lower end of the interval sits right on it. That is a materially different conversation from "p is less than 0.001". The before-and-after correlation carries an interval too, and it stays high throughout, which is what confirms the pairing is buying real precision rather than getting lucky in this sample.

The covariate check did not come back quiet

The file records each participant's age, which the analysis had ignored. Age barely relates to baseline blood pressure here, but it relates to how much blood pressure moved (r = +0.27, p = 0.05). The sign is easy to misread: change is negative, so a positive correlation means older participants dropped less. Split at the median age and the younger half fell 10.2 mmHg against the older half's 4.6, a gap of 5.6 mmHg (p = 0.004) comparable to the whole program effect.

That is effect modification, not confounding. Nothing is explained away; the headline is refined, and the program looks considerably more effective in younger participants. Two cautions come with it. The subgroup split was chosen after seeing the data, which is the trap Capstone 4 is built around, so it is a hypothesis for the next study rather than a finding from this one. And more fundamentally, no covariate you can measure fixes a missing control group: regression to the mean, placebo, and eight weeks of natural variation are not columns in the file, and they would produce an age pattern too.

🐍

The full project, step by step

The companion notebook runs all twelve framework steps: it loads the raw file, draws the paired plot, drops the duplicates, dropouts, and impossible readings with a printed audit trail, checks the normality of the differences (Shapiro-Wilk, Q-Q), runs the paired t-test with scipy and confirms the effect size, interval, and power with pingouin, cross-checks with Wilcoxon signed-rank, and shows the (wrong) independent-samples test to make the value of pairing concrete. Every number here comes from its output.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub
Download the project files

The dataset (capstone-blood-pressure-before-after.xlsx) holds the before and after readings on the bp sheet, with a codebook and notes, and it keeps the dropouts, duplicates, and impossible values so you can practice the paired cleaning. Two written reports accompany it: a plain-language brief for the clinical lead (result first, with the causation caution), and a technical report, a journal-style write-up with full methods, the efficiency argument for pairing, results tables, and references, including a note on what a single-arm design cannot establish.

🎓 Key Takeaways

  • The paired t-test is a one-sample test on each subject's change; here systolic BP fell about 7 mmHg over eight weeks.
  • Pairing needs both readings: dropouts missing a follow-up cannot be used, so 64 rows became 55 complete pairs.
  • Pairing buys power: the before-after correlation (0.85) shrank the standard error 2.5x versus treating the columns as independent.
  • Check the differences, not the raw values: Shapiro p = 0.89, so the paired t was valid; t(54) = 7.37, p < 0.001, 95% CI [5.3, 9.3] mmHg, dz = 0.99.
  • Change is not cause: with no control group, regression to the mean and other effects could explain part of the drop.
8

Quiz: Test Yourself

Eight questions on this capstone, from the paired design to the missing control group. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved.