On day T you only see the cells with t + d < T: the newest test dates are incomplete.
Epidemic ModelingData and inference
Module 7Data-driven models
Models built from data. On a simulated surveillance system with a known truth, we separate infections from reported cases with an observation model (overdispersion, zeros, the log scale), take weekday and holiday reporting patterns apart, forecast with seasonal ARIMA and state-space models in an honest rolling-origin backtest, correct the latest days for reporting delay with a nowcast, compare machine-learning and deep-learning forecasters with simple baselines, and use large language models carefully, as readers with fixed forms and checks.
Key ideas, one per episode
- Ep. 26Cases are a filtered, delayed, noisy view of infections; counts scatter like a negative binomial, not a Poisson.
- Ep. 27Weekday and holiday patterns come from reporting offices: compare like with like, or model the calendar.
- Ep. 28Seasonal ARIMA beat simple baselines with honest intervals, but every linear model struggles at turning points.
- Ep. 29The latest days always look low because reports are late; a nowcast corrects them, if the delays stay the same.
- Ep. 30On one year of data the simplest learner did best; test every learner with rolling origins against simple baselines.
- Ep. 31Use language models as readers with fixed forms, simple checks and a person for the hard cases.
Textbook: Chapter 7 of T. Lazebnik, Epidemic Modeling: Principles, Algorithms, and Applications (Academic Press, 2026). The episodes and slides follow the chapter’s topics in our own words, figures and simulations; nothing is copied from the book.
Watch
6 short episodes for this module. Pick one from the list, and open the transcript to read along: each timestamp plays the episode from there. The narration is generated with a voice clone of Teddy, used with his permission.
Episode 26 · 2:59
Counts are not cases
Cases are not infections.
Cases are a filtered, delayed, noisy view of infections; counts scatter like a negative binomial, not a Poisson.
TranscriptEpisode 26
Counts are not cases. A dashboard says two thousand cases today. That's not the number of infections, and it isn't even an exact count of cases. Welcome to Module seven: models built from data, starting with the bridge between the epidemic and the numbers.
A simulated system with a known truth. To keep things honest, this module uses a simulated surveillance system, so we know the truth. A town of five million, two waves. One in four infections becomes a reported case, about six days after infection, once a test comes back. Over the year: about one and a half million infections, and three hundred sixty thousand cases. Cases are a filtered, delayed and noisy view of infections. The observation model describes that filter.
How noisy counts are. Start with the noise. Say we expect two thousand cases on a day. If counts were Poisson, almost every day would land between one thousand nine hundred twenty seven and two thousand seventy four. Real counts scatter far more: clusters, testing campaigns, batches of results. In our system the spread follows a negative binomial: the variance is the mean plus the mean squared over k, with k of thirty. Then the same day's ninety percent range is one thousand four hundred thirty five to two thousand six hundred forty one. Check it against the truth. Poisson ranges held the count on only forty one percent of days. Negative binomial ranges, on ninety one percent, as they should. So a jump of two hundred cases can be pure noise. Choose the observation model before you read meaning into the data.
Finding the dispersion. How do you find k? Plot the spread against the mean. Poisson is a straight line: variance equals mean. Our counts curve upward, and a fit gives k of about thirty five; the true value is thirty. Noise that grows with the mean is also why many models work on the log scale. There, a ten percent wobble looks the same at a hundred cases as at ten thousand.
Zeros. Zeros need care too. A zero can mean no cases, a closed lab, or a missing report. In our quiet weeks, with less than one expected case a day, half of the days had zero cases: just what both models predict. So before reaching for a special zero-inflated model, check whether small means already explain the zeros.
The layers of an observation model. The full observation model has more layers: what share of infections are found, how long they take to be reported, and how reporting depends on the calendar. Next: the calendar. Weekday patterns and holidays, and how to keep them from fooling you.
Mondays and Sundays. Every Monday our dashboard jumps, and every Sunday it dips. The virus doesn't keep a calendar. The reporting offices do.
The weekly reporting pattern. In our simulated system, the offices report only seventy five percent of what arrives on Saturdays and fifty five percent on Sundays. The rest waits until Monday. Divide each day by its centered seven day average. Mondays come out at 1.69 times the weekly level. Saturdays drop to 0.74, and Sundays to 0.55. Monday alone carries about a quarter of the week's reports. A regression with a smooth trend and a factor for each weekday finds the same numbers, from the counts alone. And here is the giveaway: count the same cases by test date instead of report date, and the weekly pattern almost vanishes. Every weekday lands within seven percent of the weekly level. The pattern is made by reporting, not by transmission.
Growth from day to day. Why it matters: growth measured from one day to the next swings wildly. On the log scale its noise is about 0.5, enough to make a slow decline look like a sixty percent jump. Compare the same weekday a week apart instead, and the error in the daily growth rate drops to about 0.03. The same trap waits for anything built on daily counts. A reproduction number estimated from raw reports rises every Monday and falls every weekend, unless the weekday effect is removed first. Compare like with like: the same weekday, or a seven day average.
Holidays. Holidays are the same problem, once in a while. On our holiday, day one hundred twenty two, reports fell from six hundred nine to one hundred eighty nine, and the next day jumped to one thousand eighty nine. A seven day average absorbs most of it: the dip and the catch-up cancel inside the window. But comparing the same weekday a week apart is fooled twice. The holiday looks like a seventy percent drop. And one week later, an ordinary day compared with the holiday looks like growth of more than double.
Decomposition and calendar terms. Two tools handle all this. The first: decompose the series into a trend, a weekly pattern and a remainder, for example with a smoother fitted in windows, and model the trend. On the log scale the weekly pattern becomes a set of additive weekday effects. The second: keep calendar terms, weekday and holiday indicators, inside the forecasting model itself, so it learns them together with the trend and carries them into its forecasts. Either way, model the reporting process, so you don't mistake it for the epidemic. Next: models that learn the dependence over time from the data. ARIMA, seasonal ARIMA, and state space models.
Forecasting. So far we described the data. Now we forecast it. The classic tool learns how today's count depends on the last few days: ARIMA.
ARIMA and seasonal ARIMA. Three ingredients. Differencing: work with changes instead of levels, which removes a trend. Auto-regression: today's change depends on the last few changes. Moving average: today's surprise echoes for a few days. Seasonal ARIMA adds the same pieces at a lag of seven days, for the weekly pattern. We fit it to log counts, and pick the orders with an information criterion.
The rolling-origin backtest. Then the honest test, a rolling-origin backtest. Pretend it's day one hundred, fit only on the past, forecast two weeks, and compare with what happened. Move forward two weeks and repeat, seventeen times. Seasonal ARIMA missed by two hundred forty eight cases a day on average. Repeating the last value missed by three hundred thirty six. Repeating last week, by three hundred forty six. The weekly mean, by four hundred fifteen. Its eighty percent intervals caught the truth eighty five percent of the time. The wider intervals, meant to catch it ninety five percent of the time, did exactly that. The intervals also widen with the horizon. One day ahead the average miss was eighty five cases; two weeks ahead, four hundred forty eight. A forecast without honest intervals is half a forecast. And a model has to beat simple baselines before it earns any trust.
State space and missing days. State space models write the same idea as a hidden state, here the level and trend of log cases, plus noisy observations of it. The Kalman filter updates the state day by day. A bonus: missing days are no problem. We deleted fifteen random days and one whole week, and the model kept estimating through the gaps. On the missing days its error was about fifteen percent, no worse than on the days it saw.
Turning points. These linear models are strong baselines. Their weak spot is turning points: they extend the recent trend until the data prove them wrong. Forecasting from day two hundred fifty four, just after the second peak, the model expected about two thousand five hundred seventy cases two weeks later. The truth was one thousand one hundred eighty five: the wave had turned, and the past could not say so. Next: when late reports hide the present. Nowcasting under reporting delay.
The latest days always seem to fall. Look at the latest days on a dashboard, and cases often seem to be falling. Often they aren't. The reports just haven't arrived yet.
Delays and the reporting triangle. In our system, only eight percent of a day's cases are reported by the next morning, and fifty six percent within three days. Seeing them all takes two weeks. Write it as a reporting triangle: one row per test date, one column per delay. The most recent rows are still incomplete. Statisticians call it right truncation: the newest data are cut off before they are complete. On day one hundred fifty, the last test day showed twenty six cases. Two weeks later it had three hundred fifty two.
A simple nowcast. Counting only what has arrived, the last seven days look thirty seven percent lower than they finally turn out. On average, every time. Nowcasting fills in the triangle. Estimate the delay distribution from rows that are complete, then scale up each recent day by the share of its cases you expect to have seen so far. Our simple version cut the error for the last seven days from thirty seven percent to twelve. The nowcast is still a guess: the remaining cases arrive by chance, so the newest days carry the widest uncertainty. A good nowcast reports that uncertainty with the number.
When delays change. But it assumes the delays stay the same. Between days two hundred and two hundred forty, our labs slowed down: the average delay rose from 2.8 to 4.5 days. The nowcast, still using the old delays, fell short by thirty four percent. Better than the raw counts, at sixty one, but badly wrong just as the second wave was growing. And when the labs sped up again, the nowcast was still using the slow delays, and overshot by up to seventy percent. So watch the delays themselves, and estimate them from recent data.
Bayesian nowcasting. Bayesian nowcasting, such as the NobBS method, treats the whole triangle as data, lets the delays change over time, and gives an interval instead of one number. Either way, a nowcast is a layer before the forecast: correct the recent data first, then forecast from the corrected curve. Next: machine learning and deep learning forecasts, and when they help.
Learners against ARIMA. Machine learning wins competitions. Does it win at forecasting epidemics? Today four learners take on seasonal ARIMA, on the same simulated data.
From a series to a table. First, turn the time series into a table. Each row holds the last fourteen days of log cases, their weekly average, the weekday we're predicting, and how far ahead it is. The target is the count on that day. Then any learner can fit it: a ridge regression, a random forest, gradient boosted trees, and a small neural network. One model learns all horizons at once, because the horizon is one of the features. Another option is to forecast one day, feed it back in, and repeat; errors then pile up from day to day.
The backtest. Same honest test as before, with rolling origins: every week from day one hundred fifty to day three hundred twenty five. Twenty six forecasts, two weeks each. Average error, as a share of the cases: ridge regression twenty four percent, seasonal ARIMA twenty six, the neural network twenty seven, the random forest thirty, boosted trees thirty two. Repeating last week: thirty three. On one year of data, the simplest learner did best, and the fancier ones barely beat repeating last week. Machine learning needs data: longer histories, more places, more signals.
Horizon and phase. Errors grow with the horizon, and the ranking changes with it. One day ahead, seasonal ARIMA was best, missing by ten percent. Two weeks ahead it missed by forty seven, while the neural network missed by thirty three and ridge regression by thirty five. And they depend on the phase. When cases were falling toward small numbers, relative errors jumped: for seasonal ARIMA, from twenty three percent in growing weeks to thirty five in falling ones.
Deep learning. Deep learning goes further. Recurrent networks carry a hidden state through time, and gated versions like LSTMs choose what to remember. Temporal convolutions look back through fixed windows. Transformers use attention to weigh every past day. They shine when there are many series and many signals at once: regions, mobility, searches. On one short series they have little to learn from, and they overfit easily without careful regularization and early stopping. Whatever the learner, test it like a forecaster: only the past in training, rolling origins, and simple baselines to beat. Next: large language models, and how they can read the text around an epidemic.
Outbreaks as text. Much of what we learn about an outbreak first appears as text: bulletins, news, situation reports. Large language models read text. How should they join an epidemic pipeline?
A reader with a fixed form. A language model predicts the next word from the words before it. That lets it turn messy text into summaries, labels or structured records. The cautious way to use one: not as the forecaster, but as a reader. Give it a bulletin and a fixed form to fill in: disease, place, date, new cases, deaths, hospital pressure, source. Ask for nothing else.
Weaknesses. Its weaknesses are real. Answers change with the wording of the prompt, it can state facts that aren't in the text, and it drifts when reporting language changes. So never let its output flow straight into a model. Check it.
A toy check. A toy test, with our simulated counts as the bulletins. Suppose the reader slips on two percent of days: it drops a digit, adds a digit, or copies the cumulative total instead of the day's cases. Unchecked, the seven day average is off by more than twenty percent on about nine percent of days. Now add one plain rule: flag any value more than four times, or less than a quarter of, the median of the last two weeks, and send it to a person. The rule caught ninety two percent of the slips with no false alarms, and the average was badly off on fewer than one day in two hundred. Fixed forms, simple checks, trusted sources, and a person for the hard cases: that's how a language model earns its place.
Safeguards and other uses. Other safeguards work the same way. Answer only from trusted sources fed to the model, not from its memory. Process the output with fixed code, not more prompting. Log every input and output so a mistake can be traced. Language models can also summarize papers and help draft analysis code. They can sketch scenarios, too. And they can be asked for forecasts directly, but then they must pass the same rolling-origin test as any other model. The rule holds every time: they assist, and people stay accountable.
Module recap. That closes Module seven: observation models, calendars, linear models, nowcasting, machine learning, and language models. Next, in Module eight, we fit mechanistic models to data.
2:59Episode 26 · 7.1Counts are not casesCases are a filtered, delayed, noisy view of infections; counts scatter like a negative binomial, not a Poisson.
3:05Episode 27 · 7.2Seasonality and reporting artefactsWeekday and holiday patterns come from reporting offices: compare like with like, or model the calendar.
2:41Episode 28 · 7.3ARIMA, SARIMA and state-space modelsSeasonal ARIMA beat simple baselines with honest intervals, but every linear model struggles at turning points.
2:34Episode 29 · 7.4Nowcasting under reporting delayThe latest days always look low because reports are late; a nowcast corrects them, if the delays stay the same.
2:45Episode 30 · 7.5Machine learning and deep learning forecastsOn one year of data the simplest learner did best; test every learner with rolling origins against simple baselines.
2:39Episode 31 · 7.6Large language models in epidemiologyUse language models as readers with fixed forms, simple checks and a person for the hard cases.
Interactive lab
Nowcasting and backtests
Nowcast the latest test dates of the course's simulated surveillance system from its reporting triangle, and compare simple forecasters in a rolling-origin backtest.
The course's simulated year runs in your browser: a reporting triangle, a nowcast with a delay distribution estimated from recent complete days, and a rolling-origin backtest of four simple forecasters.
A surveillance system with a known truth
The course's simulated year: two waves in a town of 5 million; 1 in 4 infections becomes a case about 6 days later; reports arrive over two weeks. Everything runs in your browser.
F(n): share of a day's cases reported within n days, estimated from complete test dates in a recent window.
Rolling origins every 7 days: each forecast sees only reports up to its origin.
Running…
Cases by test date
Orange: what has arrived; blue: the nowcast; dashed: the final count (if shown).
Challenges
Each one is checked on your current settings, here or in the backtest panel below.
- With the slow labs on, find a day where the nowcast is off by more than 30%.
- Still with slow labs, get the nowcast within 15% on a day between 225 and 235, changing only the delay window.
- In the backtest, find a horizon where repeating the last day beats the weekly mean.
- Get the trend × weekday forecast error below 100 cases.
Running…
Average miss
Reported cases per forecast day, over origins every 7 days from day 120.
