The instantaneous and effective reproduction numbers from a run
Introduction
This tutorial is for a user who wants the reproduction number that a run implies, for example to report it alongside infections. The infections of a renewal process on a day are the reproduction number times the pressure, a weighted sum of earlier infections. The tutorial computes the reproduction number of each day of a run as the ratio of the infections to the pressure [, ]:
without depletion, where the ratio is the instantaneous reproduction number given as the gain;
with susceptible depletion, where the ratio is the effective reproduction number.
It assumes you have read Three towns, step by step.
Packages used
using ComposableRecurrences
using ComposableRecurrences: Depletion, Pressure, Trace
using CairoMakie, AlgebraOfGraphics, DataFramesMeta
CairoMakie.activate!(type = "png", px_per_unit = 2)
# The named series, each a vector over days, as one long table.
function long(series::Pair...)
table = DataFrame("day" => eachindex(last(first(series))), series...)
return stack(table, Not(:day); variable_name = :series)
end
# Lines of the reproduction numbers in `table` against day.
function plot_reproduction_numbers(table)
layers = data(table) *
mapping(:day, :value, color = :series => "") *
visual(Lines, linewidth = 2)
return draw(layers; axis = (xlabel = "Day", ylabel = "Reproduction number"))
endThe instantaneous reproduction number
The renewal process of one town of Three towns, step by step is
where Recurrence. It is 1.8 to day 50 and falls linearly to 0.8 on day 56. The history is 10 infections on each of the six days before day 1, and the run covers
A call with record = Pressure() returns
gi = [0.05, 0.2, 0.3, 0.25, 0.12, 0.08]
T = 75
R = [1.8 - clamp((t - 50) / 6, 0, 1) for t in 1:T]
seed = fill(10.0, 6)
# The infections of `renewal` over their pressure on each day, with the
# pressure.
function reproduction_number(renewal, R, history)
run = renewal(R; history, record = Pressure())
return run.y ./ run.pressure, run.pressure
end
R_hat, q = reproduction_number(Recurrence(gi), R, seed)
maximum(abs, R_hat .- R)4.440892098500626e-16The ratio equals
Zero pressure, strata and unrecorded pressure
On a day with NaN when Inf otherwise. With strata the pressure includes the coupling, and the ratio is taken stratum by stratum. pressure recomputes the pressure from infections and their history when a call did not record it.
The effective reproduction number
A Depletion of a population
where
N = 60_000.0
depleted = Recurrence(gi; modifiers = (Depletion(N),))
R_eff, q_depleted = reproduction_number(depleted, R, seed)
plot_reproduction_numbers(long("Gain" => R, "Effective" => R_eff))The effective reproduction number is below 1 from day 38, two days after infections peak and 12 days before the gain starts to fall. On day 75 it is 0.23 against a gain of 0.8, with 28% of the population still susceptible.
The right-hand side of the equation is checked against the pool that the modifier records. With Trace() in record a call also returns the Trace of each modifier, whose first row for a Depletion is the pool after each day.
# The pool before each day, from the trace of a `Depletion` of `N`.
pool_before(trace, N) = [N; trace[1, 1:(end - 1)]]
traced = depleted(R; history = seed, record = Trace())
S_before = pool_before(only(traced.trace), N)
λ = R .* q_depleted ./ N
R_eff ≈ R .* S_before ./ N .* -expm1.(-λ) ./ λtrueThe check holds to rounding error.
Imports and the ratio
The ratio counts all of Transform are such values, and the effective reproduction number is then add input enters before the depletion and is drawn from the pool, so the ratio then includes its share of the infections.
Performance
The timed model is the effective reproduction number of the model of Three towns, step by step, over 200 days with a generation interval of 20 lags. The figure gives its minimum time and that of a preallocated hand-written loop of the same model.
performance_plot("reproduction number")References
C. Fraser. Estimating individual and household reproduction numbers in an emerging epidemic. PLoS ONE 2, e758 (2007).
A. Cori, N. M. Ferguson, C. Fraser and S. Cauchemez. A new framework and software to estimate time-varying reproduction numbers during epidemics. American Journal of Epidemiology 178, 1505–1512 (2013).
Learning more
Imported cases gives the two ways of adding imports that the dropdown on imports refers to.
Case reproduction number computes the reproduction number indexed by the day of infection.