Course / Tutorials / Week 11 / Q-33
Quick tutorial Q-33 · Week 11 · about 15 min · Foundation
A rolling mean and a band
Set a baseline band from four weeks of simulated morning heart rate, add a seven-day rolling mean that looks back only, and see which of the two shows a real rise first.
- Ask
- Collect
- Check (this week)
- Interpret
- Coach
- Reassess (this week)
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 11 (sections 11.8, 11.8.1)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-32 Split by athlete, not by row.
The decision
An athlete's morning heart rate has been high for a few days. Before saying anything, decide whether the week as a whole sits outside the athlete's usual range, or only a few mornings do. This is training information, not a medical assessment.
The raw data
raw/morning_hr_simulated.csv: SIMULATED: 42 mornings of resting heart rate with a 4 bpm rise after day 35, and the book's own 7-day rolling mean (`roll7`) to check against. Book example data, Chapter 11 (book/ch11-statistics/data/morning_hr.csv, made bycode/morning_hr.pywith a fixed seed). Simulated, not a recording.
Try it
One morning's heart rate says little: it moves by a few beats a minute from day to day with no change in you. Two tools from Chapter 11 make a daily series readable. A band is your usual range, the mean plus or minus one standard deviation of a baseline period. A rolling mean is the mean of the last seven days, recomputed each day; it smooths the day-to-day noise and reacts a little late.
The file is the book's simulated six weeks of morning heart rate (Section 11.8). In the simulation the true level rises by 4 beats a minute after day 35, so you know what the tools should find.
A baseline band from the first four weeks
Type a prediction to enable Run.
Show the expected result without running
42 mornings; baseline mean 51.3 bpm, band 49.2 to 53.4 baseline mornings outside the band: 12 of 28
Twelve of 28 ordinary mornings fall outside a band of one standard deviation. For normal scatter you expect about a third outside; with day-to-day memory in the series (a high morning tends to follow a high morning) runs outside are common. One morning above the band is not news.
A trailing seven-day mean
Type a prediction to enable Run.
Show the expected result without running
largest difference from the book's column: 0.004 bpm 7-day mean on day 35 49.9, on day 42 53.5 mornings above the band in the last week: 3 of 7 7-day mean above the band from day 42
Only three of the seven high mornings clear the band. The rolling mean climbs every day of the week, from 49.9 to 53.5, and ends above the band on day 42: the band says "watch", the rolling mean says "the week as a whole has moved". Use rolling(7) (the last seven days), not rolling(7, center=True): a centered window uses days that have not happened yet, which a tracker cannot do and a forecast must not do (Section 11.8.1).
The chart
Show the expected result without running

For the athlete: "Your morning heart rate this week averaged about 2 beats a minute above your usual level; that is training information, not a diagnosis, so tell us how you are sleeping and we will look again next week."
Action card
- Finding
- The last week's mean rose about 2 bpm and reached the top of the usual range; single mornings did not show it clearly.
- Evidence
- The 7-day mean rose from 49.9 to 53.5 bpm, above a band of 49.2 to 53.4; only 3 of 7 mornings were above it.
- How sure
- Moderate. One week above the band; the next week decides.
- Action
- Ask about sleep, illness and training load; change nothing else yet.
- Test again
- Look at the 7-day mean again in one week.
Check yourself
Why is it normal for many baseline mornings (12 of 28 here) to fall outside a band of one standard deviation?
Why use
rolling(7)and notrolling(7, center=True)in a tracker?
Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2. In the browser the same code runs on Pyodide, so the last digit can differ.