Align observations to a real event, retain calendar context and make missing periods explicit.
Event-aligned charts: choose a baseline before comparing trajectories
Event time is not calendar time
An event-aligned chart puts each subject's event at relative time zero. This lets a reader compare trajectories before and after events that occurred on different calendar dates. Store the actual event timestamp as well as the relative offset; otherwise seasonality, outages and policy changes disappear. Specify whether an offset means elapsed hours, calendar days or complete reporting periods. Time-series period rules are essential when the event occurs late in a day or across a daylight-saving change.
Fix the baseline rule
A common display subtracts each subject's pre-event value or divides by it. These produce different shapes and units. Select the baseline window before inspecting outcomes, report how many valid observations contributed to it, and reject a percentage change when the baseline is zero. If one subject has only one pre-event measurement and another has 47, their aligned curves carry different reliability. Denominator and grain rules should stay visible with the chart. Plot absolute values alongside normalized values when the magnitude of the original series matters.
Missing is not flat
Do not fill missing pre-event days with the baseline or connect a line across an unobserved outage without a marker. A cohort average at relative day five may use fewer subjects than at day one because follow-up ends; show the contributing count by offset. Attrition can make a trend look like improvement. Small-sample uncertainty belongs near sparse tails, and forecast intervals must not be substituted for missing actual observations.
The line does not prove an effect
A change at time zero can reflect selection into the event, a concurrent intervention, regression to the mean or ordinary seasonality. An annotation identifies timing, not causality. Compare a relevant untreated group or a pre-specified benchmark if the decision requires an effect estimate, and state the assumptions of that comparison. Annotation and causal-claim boundaries apply here. Export subject ID, event date, relative offset, original value, baseline window, normalized value and eligibility state so every plotted line can be reconstructed.
Worked contract
from datetime import date
from math import isfinite
def event_aligned_change(event_day: date, observations: dict[date, float],
baseline_days: tuple[date, ...]
) -> list[tuple[int, float, float]]:
if not baseline_days or len(set(baseline_days)) != len(baseline_days):
raise ValueError("baseline days must be distinct")
if any(day >= event_day or day not in observations for day in baseline_days):
raise ValueError("baseline must be observed before the event")
if any(not isfinite(value) for value in observations.values()):
raise ValueError("observations must be finite")
baseline = sum(observations[day] for day in baseline_days) / len(baseline_days)
return sorted(((day - event_day).days, value, value - baseline)
for day, value in observations.items())
incident_counts = {
date(2026, 10, 5): 47, date(2026, 10, 6): 59,
date(2026, 10, 8): 38, date(2026, 10, 9): 35,
}
aligned = event_aligned_change(
date(2026, 10, 7), incident_counts,
(date(2026, 10, 5), date(2026, 10, 6)),
)
assert aligned == [(-2, 47, -6), (-1, 59, 6), (1, 38, -15), (2, 35, -18)]
assert all(offset != 0 for offset, _, _ in aligned)Performance and operating cost
For N observations and B baseline days, validation and averaging take O(N+B) time; sorting relative periods takes O(N log N) time and O(N) output space. The function leaves missing event day zero absent instead of inventing a value. Calendar dates are appropriate only when day-level reporting is the contract; intraday events need zoned timestamps and a declared binning method. Subtracting a baseline describes change, not a causal estimate.
Common Mistakes
- Discarding calendar dates after alignment and losing concurrent-event context.
- Choosing a favorable baseline window after seeing the result.
- Drawing a continuous line over days with no observations.
- Calling a post-event change proof that the event caused it.
Validation drill
Align 81 facilities around a maintenance intervention. Show each facility's baseline window and post-event coverage, then recompute the cohort curve using only facilities observed through day 14.
Read next
- Time-series charts: distinguish missing days, zeros and provisional periods
- Aggregation grain and denominator: make every plotted mark auditable
- Uncertainty on charts: show denominators and intervals beside estimates
- Chart annotations: align events to the right clock without claiming causality
