Concepts
Calibration, uncertainty and validation
Updated 3 November 2026 · 4 min read
Fitting a model to data finds the values that make it match. It doesn’t tell you the model is right, and it doesn’t always tell you the values are. This page is about what a fit can and can’t say, worked through on the outbreak and oil field tutorials, and how to test a model on data it hasn’t seen.
What the fit does#
Fit to Data adjusts the constants you tick to make the model’s values at the measured times as close as possible to the measurements. “As close as possible” means the smallest sum of squared differences, each divided by its series’ tolerance so that series in different units count fairly. SepalSolver’s Lsqcurvefit does the search.
Where the ± comes from#
At the best fit, the builder nudges each fitted value a little and sees how much the model’s predictions move. Values that move the predictions a lot are pinned down tightly by the data; values that barely move them are not. Together with how far the data scatter about the fitted line, that gives each value a standard error:
where J is how the predictions move with each value, ri are the differences at the m measurements, and n is the number of values fitted. The ± shown is 1.96 standard errors: about 95% of the time, the true value lies within it.
That “about 95%” rests on three assumptions. The rest of this page is what happens when each one fails.
Assumption 1: the model is right#
The ± measures only the scatter in the data. If the model is missing something, the fit makes the values it is allowed to move cover for it, and reports a tight ± around the wrong answer.
The oil field tutorial shows the classic case. Without an aquifer, the oil in place fits at 418 ± 27 MMSTB with R² 0.987. The field holds 250. The pressure the aquifer was holding up had to be explained somehow, and more oil was the only way the model could do it.
How to catch it: look for something the model implies that should stay constant, and check that it does. In the oil field, the oil in place each pressure survey implies drifted from 330 to 470 MMSTB. A right model gives the same answer from every survey; once the aquifer was added, every survey implied between 240 and 253.
Assumption 2: the data can tell the values apart#
Fit the outbreak’s contact rate and the length of the illness to the first 15 days only, and the match is excellent, R² 0.997, with values that are badly wrong: a contact rate of 0.57 ± 0.18 and 3.4 ± 2.0 days ill, against a truth of 0.42 and 7.
- Reported ill (first 15 days used)
- Fitted to all 46 days
- Fitted to the first 15 days
Show the numbers
| day | Reported ill (first 15 days used) | Fitted to all 46 days | Fitted to the first 15 days |
|---|---|---|---|
| 0 | 10 | 10 | 10 |
| 5 | 45 | 40 | 40 |
| 10 | 150 | 153 | 157 |
| 15 | 567 | 550 | 532 |
| 20 | 1612 | 1566 | 1213 |
| 25 | 2756 | 2734 | 1452 |
| 30 | 2918 | 2798 | 1012 |
| 35 | 1831 | 2073 | 533 |
| 40 | 1267 | 1326 | 249 |
| 45 | 807 | 793 | 111 |
| 50 | – | 460 | 48 |
| 55 | – | 262 | 21 |
| 60 | – | 148 | 9 |
| 65 | – | 84 | 4 |
| 70 | – | 47 | 2 |
| 75 | – | 26 | 1 |
| 80 | – | 15 | 0 |
Early in an outbreak the number ill grows at a rate of contact rate minus one over days ill: 0.42 − 1/7 = 0.277 for the truth, 0.573 − 1/3.42 = 0.281 for the fit. Any pair with that difference fits the early data equally well. The data can’t separate the two values, and the fit picks a pair more or less at random.
The ± values warned about this. Ranges of ±31% and ±58% say: these data cannot answer this question. When ranges are that wide, believe the ranges, not the values. Fit fewer constants, fix one you can measure some other way, or wait for data that depend on them differently. Here, the data past the peak.
Assumption 3: the scatter is the same everywhere#
The ± assumes every measurement is equally noisy. Real counts aren’t: an error of 6% on 2,800 cases is a lot more people than 6% of 50. With such data, the large values dominate the fit, and the ± comes out too tight.
That is likely why fitting both outbreak values to all 46 days gives 6.87 ± 0.11 days ill when the truth, 7, is just outside the range. One time in twenty, a 95% range misses by chance alone. Scatter that grows with the count makes it more likely.
Testing a model properly#
A model that matches the data it was fitted to has passed a weak test, because the fit made it match. The strong test is data it hasn’t seen.
- Hold some back. Fit to the first part of the record and compare the model with the rest. The outbreak fitted to 15 days fails this test visibly; the full fit passes it.
- Check what should be constant. Implied values that drift from one measurement to the next are the clearest sign of a missing mechanism.
- Sweep before you fit. If an output barely moves across a constant’s range, no data on that output will pin the constant down.
- Fit as few values as you can. Each extra one improves the match and weakens the answer. R² always goes up when you add a constant; that is not evidence the constant belongs.
See also
- Fit constants to measurementsChoose what to fit, run the fit, and read the ± and R² that come back.
- Fit to DataLsqcurvefit: the constants that make the model match the measurements best.
- Fitting an outbreak to case dataImport daily case counts, let Fit to Data find the contact rate, and judge how far to trust it.
- An oil field from pressure historyBuild a material balance from objects, match it to twelve pressure surveys, and forecast with wells.