Epidemic ModelingData and inference

Module 8Parameter estimation and calibration

Fitting models to data, and knowing when you can't. On one simulated outbreak with a known truth, we fit by least squares (and see why cumulative fits give false confidence), compare grid, Bayesian, genetic and swarm searches, refine with gradients, curvature and Nelder-Mead, fit models without a likelihood with approximate Bayesian computation and a particle filter, calibrate for a purpose with targets, observation mappings and losses, and diagnose identifiability and misspecification.

By the end you should be able to fit a model by weighted least squares, choose a search method for the problem at hand, use simulation-based inference when no likelihood exists, design a calibration around its purpose, and check identifiability with profiles and stress tests.

Key ideas, one per episode

  • Ep. 32Least squares recovers R0 2.5, but a fit on cumulative counts claimed ±0.004 when the real spread was ±0.15.
  • Ep. 33Global searches find the valley fast; none reliably polishes the last percent: hand over to a local method.
  • Ep. 34Curvature-aware methods reached the best fit in about 20 model runs; plain gradient descent was still 48% off after 1,500.
  • Ep. 35ABC recovered R0 from simulations alone; a particle filter saw R fall below 1 six days after a lockdown.
  • Ep. 36Same model, same data: four calibration targets gave 476 to 800 peak beds; the truth was 681.
  • Ep. 37Early data measure growth, not R0; a good fit is not proof: check parameters, profiles and unseen data.

Textbook: Chapter 8 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.

The title slide of Module 8: Parameter estimation and calibration

33 slides, written to be read on your own, with worked examples, “try it” boxes, our own small simulations and check-yourself questions (answers at the end). PDF, 1.3 MB.

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 32 · 2:53

Fitting by least squares

Fitting an epidemic model by least squares on a simulated outbreak with a known truth: the loss, weights and the log scale, and why fitting cumulative counts makes error bars far too small.

Least squares recovers R0 2.5, but a fit on cumulative counts claimed ±0.004 when the real spread was ±0.15.

TranscriptEpisode 32
0:00

Model meets data. We have a model, and we have data. Which parameter values make the model match the data? Welcome to Module eight: parameter estimation and calibration.

0:17

One outbreak, known truth. All module long we use one simulated outbreak with a known truth. A town of one hundred thousand, R naught 2.5: a transmission rate beta of 0.25 per day, and ten infectious days on average. Forty percent of infections are reported, with extra noise. Over a hundred days, thirty four thousand eight hundred fifty one cases were reported. Now we pretend we don't know beta or gamma.

0:44

Least squares. Least squares: for any beta and gamma, run the model, subtract its curve from the data, square each difference, and add them up. The best parameters make that sum as small as possible. Squaring punishes big misses and keeps the sum smooth, so a solver can slide downhill. And when the noise is normal with a known size, least squares is exactly maximum likelihood. Our fit gives beta 0.249. Gamma comes out at 0.099, so R naught is 2.51, against a true 2.5. A least squares solver finds this in a fraction of a second.

1:20

Weights and the log scale. But counts are noisier when they are big. A day with a thousand cases wobbles far more than a day with ten, so plain least squares lets the peak dominate. Weights fix that: divide each difference by the size of noise you expect on that day. Or fit on the log scale, where a ten percent miss counts the same at any size.

1:40

The cumulative trap. Now a trap. Fitting the cumulative curve looks beautiful: smooth, with tiny residuals. But each day's total carries all the earlier days' errors, so the errors are not independent. We repeated the fit on two hundred new noisy datasets from the same truth. The cumulative fit claimed its R naught was good to plus or minus 0.005. The estimates actually spread by 0.15, and its ninety five percent intervals held the truth only five percent of the time. Fitting daily counts was more honest, but still too confident: its intervals held the truth seventy four percent of the time, because the noise model behind the error bars was too simple.

2:21

Next. Least squares is the baseline: simple, fast, and often enough. Next: how to search when the landscape is rough. Grids, Bayesian optimization, genetic algorithms and swarms.

Interactive lab

Fitting an outbreak

Fit the module's simulated outbreak by weighted least squares with a grid, Nelder–Mead, gradient descent or a swarm, shorten the data to see the beta–gamma valley, and fit a stochastic town with ABC rejection.

The first panel fits the module's SIR outbreak and draws the loss over beta and gamma with each search's path; the second runs approximate Bayesian computation on a random outbreak in a town of 2,000. Everything runs in your browser.

Simple math

One outbreak with a known truth

The module's SIR outbreak: a town of 100,000, beta 0.25 and gamma 0.1 (R0 2.5), 40% of infections reported with negative binomial noise. Everything runs in your browser.

Weighted least squares
loss = Σ (data − model)² / model

Each day's miss is divided by the noise expected on that day, so big days don't drown small ones.

Four searches
grid · Nelder–Mead · gradient · swarm

Each counts its model runs; the yellow dot is the best fit found by a careful reference search.

ABC rejection
keep θ if distance(summaries) is small

Draw beta and gamma from a box, simulate a random outbreak, keep the closest draws.

beta
–
gamma
–
R0
–
Model runs
–
Loss vs best
–

Running…

Loss map

Dark: small loss. Orange: the search's path and result; yellow: the best fit; white ring: the truth.

Data and fit

Grey: reported cases; orange: the fitted model over all 100 days.

Challenges

Each one is checked on your current settings, here or in the ABC panel below.

  1. Fit all 100 days with Nelder–Mead and get within 1% of the best fit.
  2. Find a start point from which gradient descent gets within 5% of the best fit.
  3. With 30 days of data or fewer, find a valley: fits within 5% of the best whose gamma values are more than 0.1 apart.
  4. In ABC, get the 90% interval of R0 narrower than 1.0 with at least 50 kept draws.
Draws kept
–
R0, median
–
R0, 90% interval
–
Fizzled
–

Running…

Kept draws

Blue: kept (beta, gamma); dashed box: the prior; dashed lines: the 90% range of R0; ring: the truth.