Skip to content

The reproduction number from a run ​

Introduction ​

The reproduction number on each day can be read back from the infections a renewal run returns. A renewal's infections on a day are the reproduction number times the pressure, a weighted sum of earlier infections. A call with record = (:pressure,) returns the pressure of each day with the infections, so dividing the infections by it gives the reproduction number.

Packages used ​

julia
using ComposableRecurrences
using ComposableRecurrences: Depletion
using CairoMakie, AlgebraOfGraphics, DataFramesMeta

CairoMakie.activate!(type = "png", px_per_unit = 2)

The instantaneous reproduction number ​

The one-town renewal of Three towns is

where is the number of infections on day and the generation interval on lag , with   lags. is the pressure on day . is the reproduction number, the gain of the Recurrence. It is 1.8 up to day 50 and falls in equal steps to 0.8 on day 56. The run starts from ten infections on each of the six days before day 1. The call's trace holds as trace.pressure, computed as each step computes it, so the first days read the earlier infections in the history. The ratio   is then .

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)
renewal = Recurrence(gi)
infections, trace = renewal(R; history = seed, record = (:pressure,))
R_hat = infections ./ trace.pressure

@chain DataFrame(day = 1:T, value = R, series = "Gain") begin
    data(_) * mapping(:day, :value => "Reproduction number", color = :series => "") *
        visual(Lines, linewidth = 2)
    _ + data(DataFrame(day = 1:T, value = R_hat, series = "Infections / pressure")) *
        mapping(:day, :value => "Reproduction number", color = :series => "") *
        visual(Scatter, markersize = 6)
    draw(_; axis = (xlabel = "Day",))
end

The ratio matches to round-off on every day. Where is zero the ratio is NaN with no infections and Inf otherwise. With strata, the pressure includes the coupling, so the ratio works on each stratum. For infections that did not come from a traced call, pressure recomputes the pressure from them and the same history.

The effective reproduction number ​

A Depletion of susceptibles with the hazard form draws

where is the number of susceptibles left after day , with  , and is the hazard on day .   is the town's population. The ratio is then the effective reproduction number:

With record = (:trace,) the call's trace also holds each modifier's Trace. For a Depletion its first row is the pool after each day, which gives to check the formula.

julia
N = 60_000.0
depleted = Recurrence(gi; modifiers = (Depletion(N),))
y, tr = depleted(R; history = seed, record = (:trace,))
q = tr.pressure
R_eff = y ./ q
pool = [N; only(tr.modifiers)[1, 1:(end - 1)]]
λ = R .* q ./ N
@assert R_eff ≈ R .* pool ./ N .* -expm1.(-λ) ./ λ

@chain DataFrame(day = 1:T, Gain = R, Effective = R_eff) begin
    stack(Not(:day); variable_name = :series, value_name = :R)
    data(_) * mapping(:day, :R => "Reproduction number", color = :series => "") *
        visual(Lines, linewidth = 2)
    draw(_; axis = (xlabel = "Day",))
end

matches the formula to round-off. It falls below as the pool runs down. It falls below 1 on day 38, two days after infections peak and before the intervention on day 50. After day 75 the pool holds 28% of the town.

The ratio counts all of , including values the gain does not multiply. Imports added after the depletion by Transform(+, ι) are such values, so with them   is the effective reproduction number. An add input enters before the depletion and is drawn with the rest, so the ratio then includes its share.

Performance ​

Each bar times the effective reproduction number of the three towns, with depletion, over 200 days with a 20-day generation interval, against a preallocated hand-written loop.

julia
performance_plot("reproduction number")

Learning more ​