Skip to content

The instantaneous and effective reproduction numbers from a run ​

Introduction ​

The infections of a renewal process on a day are the reproduction number times the pressure, a weighted sum of earlier infections. This 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.

Packages used ​

julia
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"))
end

The instantaneous reproduction number ​

The renewal process of one town of Three towns, step by step is

where is the number of infections on day , the weight of the generation interval on lag , with   lags, and the pressure on day . is the reproduction number, the gain of the 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   days.

A call with record = Pressure() returns with the infections. The pressure of the first days includes the infections in the history. The estimate is the ratio

julia
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-16

The ratio equals to rounding error on every day. On a day with   the ratio is NaN when   and 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 with the hazard form gives

where is the susceptible pool after day , with  , and the hazard of infection on day . Here  . The ratio of infections to pressure is then the effective reproduction number,

julia
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.

julia
# 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.(-λ) ./ λ
true

The ratio counts all of , including values that the gain does not multiply. Imports added after the depletion by a Transform are such values, and the effective reproduction number is then  . An 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.

julia
performance_plot("reproduction number")

References ​

  1. C. Fraser. Estimating individual and household reproduction numbers in an emerging epidemic. PLoS ONE 2, e758 (2007).

  2. 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 ​