Stellar Grove · Concrete Mathematical Modelling
Three traffic laws, one data set
Several speed-density laws look plausible. Can the data tell them apart, and does the choice matter?
Chapter 4 · Validation: accept, improve, or reject. A worked example rebuilt from the chapter's topic in Mike Mesterton-Gibbons, *A Concrete Approach to Mathematical Modelling*; the scenario and numbers are our own illustration, not the book's text. The detector data on this page are simulated from Greenberg's law with known parameters, so the methods can be checked against the truth (see the table at the end).
Headline: All three laws track the data closely (R² 0.91–0.99), yet AIC picks Greenberg decisively (weight 1.00), and residual patterns rule out the straight line. The choice matters: predicted lane capacity ranges from 1,442 to 1,693 vehicles an hour.
- 1.00Akaike weight for Greenberg
- 1,442–1,693capacity predicted by the three laws (veh/h)
- 3/4truth checks passed
The problem
A loop detector records 120 one-minute readings of traffic density (vehicles per mile) and mean speed. Three classic laws describe how speed falls as density rises. Which one does the evidence support, and would picking the wrong one change the engineering answer (the lane's capacity)?
The candidates
Each has two parameters, so AIC differences come purely from fit. Each also implies a capacity (Greenshields , Greenberg , Underwood ).
Results
| Law | Parameters | R² | AIC | Akaike weight | Runs test p | CV error (mph) | Capacity (veh/h) |
|---|---|---|---|---|---|---|---|
| Greenshields (linear) | v_f = 37.3, k_j = 181.4 | 0.913 | 272.4 | 0.000 | 0.000 | 3.10 | 1,693 |
| Greenberg (logarithmic) | c = 17.3, k_j = 226.8 | 0.986 | 51.4 | 1.000 | 0.048 | 1.23 | 1,442 |
| Underwood (exponential) | v_f = 52.6, k_m = 74.5 | 0.981 | 88.9 | 0.000 | 0.000 | 1.45 | 1,442 |
Try it: inspect the residuals
Residuals by model
Slide between the three laws: a good model leaves residuals scattered around zero with no curve.
Key findings
- Fit statistics alone can mislead. All three have R² above 0.91; the straight line's residuals, though, run in long same-sign stretches (runs test p = 0.000), the signature of a missing curve.
- AIC finds the true law here: Greenberg gets weight 1.00, and its parameters land near the planted values (c = 17.3, k_j = 227, true 17.2 and 228).
- Tests err at their stated rate. The runs test flags even the true law here (p = 0.048): at the 5% level it does so in about 1 data set in 20, which is why the truth table below records a fail rather than quietly dropping the check. Judge a model on several diagnostics, not one p-value.
- The decision depends on the choice. Capacity estimates span 1,442–1,693 veh/h (truth 1,443) because the laws differ most where data are thin: validate in the regime you will use the model for.
Truth checks
| Check | Result |
|---|---|
| Best AIC is the true (Greenberg) law | pass |
| 95% interval for c covers 17.2 | pass |
| 95% interval for k_j covers 228 | pass |
| Greenberg residuals show no sign runs (p > 0.05) | fail |
import numpy as np
from books.concrete_mathematics import equilibrium as eq, validation as va
rng = np.random.default_rng(42)
k = np.sort(rng.uniform(15, 190, 120))
v = eq.greenberg_speed(k, 17.2, 228) + rng.normal(0, 1.2, k.size)
fit = va.fit(lambda k, c, kj: c * np.log(kj / k), k, v, p0=[15, 250], names=["c", "k_j"])
print(np.round(fit.params, 2), np.round(fit.ci(), 1).tolist())
# → [ 17.28 226.81] [[16.9, 17.7], [221.4, 232.2]]
Assumptions and extensions
- Simulated data make the truth knowable; real detector data add measurement error in density and a scatter of driver types.
- Equal parameter counts make AIC a pure fit comparison; with unequal counts its penalty matters (Chapter 8's likelihood-ratio test is the nested-model alternative).
- Real flow-density data often show a capacity drop (a two-regime curve) that none of these smooth laws capture: reject all three if your use case lives there.