Estimating R
How Epidemics Spread
Chapter 8 · Estimating R
Every model so far began with a number handed to us: an R of 2, a contact rate, a transmission chance. Nobody hands those to a health officer. What arrives each morning is a list of positive tests, a few hospital admissions, and some interviews with people who fell ill. In 1948 the Framingham Heart Study began following thousands of ordinary residents of one Massachusetts town for years, to see who developed heart disease and what they had in common (per search summaries, around 5,200 people were recruited). In 1950 Richard Doll and Austin Bradford Hill published a very different design in the British Medical Journal: they asked hospital patients with lung cancer, and matched patients with other illnesses, about their smoking, and compared the two groups. The first design starts with the exposure and waits for the illness; the second starts with the illness and looks back at the exposure. This chapter uses simulations to ask how we get from messy counts to a number like R, which studies answer which questions, and how the way we count can mislead us before any model is applied.
Estimating R from a Growth Curve
In the early days of an outbreak, with nobody immune and nothing changed, cases grow exponentially, as in How Epidemics Spread 2. If we plot the logarithm of daily cases against the day, the points fall near a straight line, and the slope of that line is the growth rate r per day. A growth rate is easy to measure. R is what we want, and it needs one more ingredient: how long it takes for one case to infect the next. The serial interval is the time between the start of symptoms in one case and the start of symptoms in the person they infected. It is measured from interviews. The generation interval is the time between the two infections, which usually cannot be seen. The two have the same mean in simple models but different spreads, and in practice the serial interval is used as a stand-in (a point I am relying on from general knowledge, not from a source I checked this session).
A shortcut is R = exp(r × mean interval). It is exact only if every infection takes exactly the mean time. When the interval varies, as it always does, the correct conversion is smaller. For an interval with a gamma shape (a flexible curve with a mean and a spread), my derivation gives R = (1 + r × scale) ^ shape. The code simulates outbreaks with a known R, fits the growth rate on days 10 to 20, and compares the two conversions. Each case has a random number of children (Poisson, mean R) and each child is infected a random whole number of days later. The serial interval is assumed gamma-shaped with a mean of 5 days and a standard deviation of 2.5 days. The four helper functions are reused in the exercises.
The gamma conversion recovers the true R well: 2.04 for a true 2.0 and 3.01 for a true 3.0. The shortcut overshoots, by a little at R = 1.2 (1.25) and by a lot at R = 3 (3.56), because it pretends that nobody infects anyone sooner than the average. The small upward drift at the low values (1.24 for 1.2 and 1.56 for 1.5) has two likely causes that I did not separate: rounding of lags to whole days, and, at R = 1.2, the two runs that died out and were left out, which removes the unluckiest outbreaks (both are inferences, untested). The second table shows the weak point. The simulation knows the serial interval exactly; a real analyst does not. If the true mean is 5 days but we assume 3, the estimate for a true R of 2.0 falls to 1.56, and an assumed 7 gives 2.62. An estimate of R is only as good as the interval it was converted with.
| Growth rate r | Serial interval | R | |
|---|---|---|---|
| What it is | slope of log daily cases | onset of symptoms to onset in the next case | new cases per case |
| Observed directly? | yes, from the counts | from interviews (a sample) | no, always inferred |
| Main risk | noisy when counts are small | wrong mean gives wrong R | inherits both errors |
| Result in the simulation (true R = 2.0) | fitted on days 10 to 20 | mean 5 days, sd 2.5 assumed | 2.04 (gamma), 2.18 (shortcut) |
Cohort and Case-Control Studies
Counts tell us how fast an epidemic grows, but not why. To find what puts people at risk (a food, a gathering, a type of work) we compare groups. A cohort study takes a group of people, records who was exposed, follows everyone, and compares the risk of illness in the exposed with the risk in the unexposed. Their ratio is the risk ratio (RR). It is the cleaner design but needs everyone followed, which is expensive when the illness is rare. A case-control study goes the other way: collect the ill people (cases), pick some well people (controls), and ask both groups about the exposure. It cannot give risks, because the numbers of cases and controls were chosen by the investigator, but it gives the odds ratio (OR): the odds of exposure among cases divided by the odds of exposure among controls. The code builds a made-up town of 20,000 people with 30 per cent exposed, then runs both designs on it. Two illnesses are tried with the same true risk ratio of 5: a rare one (5 per cent of the exposed ill against 1 per cent of the unexposed) and a common one (50 per cent against 10 per cent). The intervals use the standard log method and are approximate.
In the rare case the two designs agree with the truth within their intervals: the cohort risk ratio is 4.60 (3.77 to 5.61), against a true 5.0, and the case-control odds ratio is 4.53 (2.97 to 6.90), against a true odds ratio of 5.21 calculated by hand. The case-control interval is much wider, even though the cohort followed 20,000 people and the case-control study interviewed only 400. In the common case the story changes. The cohort still recovers the risk ratio (4.96), but the case-control study estimates 8.44 (6.88 to 10.35), close to the true odds ratio of 9.00 and well away from the risk ratio of 5. The odds ratio is a different quantity from the risk ratio. It is close to the risk ratio only when the illness is rare, a standard result in epidemiology that this run illustrates, not proves. The practical lesson: a case-control odds ratio from a common illness should not be quoted as “times more likely”.
| Cohort study | Case-control study | |
|---|---|---|
| Starts from | exposure | illness |
| Measures | risk, so risk ratio | odds of exposure, so odds ratio |
| People needed | everyone at risk (20,000 here) | cases plus a few controls (400 or 2,000 here) |
| Good for | common exposures, several outcomes | rare illnesses, quick outbreak investigations |
| Main risks | cost, loss to follow-up | choosing controls, recall of past exposure |
| Rare illness (RR 5 true) | 4.60 | 4.53 (true OR 5.21) |
| Common illness (RR 5 true) | 4.96 | 8.44 (true OR 9.00) |
Bias in Testing
So far the counts were correct. Real counts are not. A sensitive test (sensitivity: the share of infected people who test positive) misses few cases; a specific test (specificity: the share of uninfected people who test negative) raises few false alarms. Even a decent test can mislead when the infection is uncommon. Worse, the people tested are rarely a random sample: those with symptoms, or contacts of a known case, or people with the time to queue, are tested more. The code makes a town of 100,000 with 2 per cent truly infected, a test with 80 per cent sensitivity and 98 per cent specificity, and two plans. Plan A tests 5,000 random people. Plan B tests only people who come forward, which we assume 40 per cent of infected people do against 3 per cent of the rest. Each plan reports the share positive and a corrected figure from the Rogan-Gladen formula, (observed + specificity − 1) / (sensitivity + specificity − 1), which removes the effect of test errors only.
The true share infected is 1.93 per cent. Plan A sees 3.24 per cent positive, about 1.7 times the truth, because at this low prevalence the false alarms from the uninfected outnumber the real finds: by my arithmetic, using the expected values, roughly 56 per cent of positive results here are false. The corrected figure, 1.59 per cent, is close but not exact, and the gap is plausibly sampling noise (about 160 positives out of 5,000 tests, so a small change in the count moves the result by a few tenths of a point; my reasoning, not tested here). Plan B is badly off: 18.25 per cent positive, and 20.83 per cent after correction, more than ten times the truth. The formula repaired the test errors but could not repair the selection, since infected people were far more likely to be tested. A bigger sample would not fix this either: Plan B’s sample is large (3,716 tests) and still wrong. The common remedy is a random survey, even a small one; the size and the randomness are separate questions, and randomness is the one that matters here.
| Source of error | What goes wrong | Does it fix itself with more tests? | Remedy |
|---|---|---|---|
| Test errors | false positives and missed cases distort the share positive | no | correct with sensitivity and specificity |
| Who gets tested | the tested are more often the infected (Plan B) | no | random sampling; report who was tested |
| Changing test effort | more tests find more cases with no change in infections (Exercise 2) | makes it worse | report the share positive as well as counts |
| Result in this run | truth 1.93% | A 3.24%, 1.59% corrected | B 18.25%, 20.83% corrected |
Simulate 100 outbreaks with a true R of 2.0 and the 5-day gamma serial interval (assumed), over 30 days. Estimate R from the growth rate in five windows (days 0 to 10, 5 to 15, 10 to 20, 15 to 25, 20 to 30), then, for the window 10 to 20, using assumed serial-interval standard deviations of 1.0, 2.5 and 4.0 days with the mean fixed at 5. Which window is least noisy here, and what would make a later window misleading in a real epidemic?
📄 View solutionKeep the true share infected fixed at 1 per cent (assumed) but let the number of daily tests double every 14 days, from 2,000 tests on day 0, over 28 days, with 80 per cent sensitivity and 98 per cent specificity (assumed). Estimate the growth rate and the apparent R from the raw positive counts, then from the share of tests that are positive. Which is misleading, and by how much?
📄 View solutionIn a town of 20,000 (30 per cent exposed, 5 per cent of the exposed and 1 per cent of the unexposed ill, assumed), repeat a case-control study with 100 cases 500 times, using 1, 2, 4 and 10 controls per case. Print the mean odds ratio and the spread of its logarithm for each. How much does adding controls help, and what limits it?
📄 View solutionQuick Reference
- Growth rate r: slope of the log of daily cases, fitted over a window where nothing else changes
- Serial interval: symptom onset to symptom onset between infector and infected; stands in for the generation interval (infection to infection)
- From r to R: R = exp(r × mean) only if the interval never varies; for a gamma interval R = (1 + r × scale) ^ shape (my derivation, checked by simulation)
- Cohort study: follow exposed and unexposed, compare risks; risk ratio = risk if exposed / risk if unexposed
- Case-control study: compare exposure in cases and controls; odds ratio approximates the risk ratio only if the illness is rare
- Sensitivity / specificity: share of infected who test positive / share of uninfected who test negative
- Rogan-Gladen: true share = (observed + specificity − 1) / (sensitivity + specificity − 1); fixes test errors, not selection
- Testing bias: volunteers, symptomatic people and rising test numbers distort counts; a random sample and the share positive help
- Assumes: constant R during the fitting window, known test accuracy, illustrative numbers