Skip to content

A renewal process with susceptible depletion and a reporting delay ​

Introduction ​

This tutorial is for a user building their first model of one population. It builds the model in three parts:

  • a renewal process for infections, with a reproduction number that changes over time [, ];

  • depletion of a finite susceptible population, in two forms;

  • reported cases as a share of infections after a delay.

It also compares a seed of one day with a seed on an exponential growth path.

It assumes you have read Three towns, step by step.

Packages used ​

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

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

Two functions draw every figure.

julia
# The named series, each a vector over `days`, as one long table.
function long(series::Pair...; days = eachindex(last(first(series))))
    table = DataFrame("day" => collect(days), series...)
    return stack(table, Not(:day); variable_name = :series)
end

# Lines of `:value` against `:day`, one colour a series, with `kwargs`
# passed to the axis.
function lines_by(table; kwargs...)
    layers = data(table) * mapping(:day, :value, color = :series => "") *
        visual(Lines, linewidth = 2)
    return draw(layers; axis = (; xlabel = "Day", kwargs...))
end

A renewal process ​

Infections on day are a weighted sum of earlier infections, scaled by the reproduction number:

where is the number of infections on day , the reproduction number and the weight of the generation interval on lag , with   lags. is the gain of the Recurrence and its kernel. The history is 5 infections on the day before day 1, and the run covers   days.

julia
gi = [0.1, 0.3, 0.3, 0.2, 0.1]
T = 80
R = [t <= 30 ? 1.4 : t <= 50 ? 0.9 : 1.2 for t in 1:T]

# Infections on days 1 to `length(R)` of the renewal process with
# generation interval `gi`, after applying `modifiers`.
function infections(gi, R, history; modifiers = ())
    return Recurrence(gi; modifiers)(R; history)
end

single_seed = infections(gi, R, [5.0])
lines_by(long("Infections" => single_seed); ylabel = "Infections")

Seeding on a growth path ​

A seed of days that grows at rate per day is

where is the seed on the -th of the days before day 1 and the seed on the last of them. exponential_history returns . Here   and  , close to the growth rate of this renewal process at  . A run on a growth path of rate has a daily growth ratio of .

julia
r0 = 0.12
growing = exponential_history(5.0, r0, length(gi))

# The ratio of each value of `y` to the one before it.
growth_ratio(y) = y[2:end] ./ y[1:(end - 1)]

ratios = long(
    "Growing seed" => growth_ratio(infections(gi, R, growing))[1:24],
    "Single seed day" => growth_ratio(single_seed)[1:24];
    days = 2:25
)
lines_by(ratios; ylabel = "Daily growth ratio", limits = (nothing, (0, 2)))

With the growing seed the ratio is between 1.1265 and 1.1272 on days 2 to 25, against  . With a single seed day it ranges from 1.06 to 3.14 over the same days.

Susceptible depletion ​

A Depletion draws the infections of each day from a pool of susceptible people in a population of :

where is the number of new infections before depletion and  . Depletion(N) takes the hazard form, and Depletion(N, Floor()) the floored form. Here   and   on every day.

julia
N = 2_000.0
R_high = fill(1.8, T)
hazard = infections(gi, R_high, [5.0]; modifiers = (Depletion(N),))
floored = infections(gi, R_high, [5.0]; modifiers = (Depletion(N, Floor()),))

lines_by(long("Hazard" => hazard, "Floor" => floored); ylabel = "Infections")

The susceptible pool after day is less the infections up to day .

julia
# The pool left after each day, from a population `N` and `infections`.
susceptible(N, infections) = N .- cumsum(infections)

lines_by(
    long(
        "Hazard" => susceptible(N, hazard),
        "Floor" => susceptible(N, floored)
    );
    ylabel = "Susceptible"
)

The hazard form peaks at 84 infections on day 24 and leaves 531 people susceptible on day 80. The floored form peaks at 90 infections on the same day and leaves 494.

Why the hazard form draws less

The hazard form draws   and the floored form about . Since    for  , the hazard form draws less from the same pool.

Reported cases ​

Reports are a share of the infections of the hazard form, after a delay:

where is the number of reports on day and the weight of the reporting delay on lag , with   lags. is the kernel of a Convolution and   its gain.

julia
delay = Convolution([0.0, 0.1, 0.25, 0.3, 0.2, 0.1, 0.05])
reports = delay(hazard; gain = 0.4)

lines_by(long("Infections" => hazard, "Reports" => reports); ylabel = "Count")

Reports peak at 33 on day 27, three days after infections peak.

Performance ​

The timed model is a seeded renewal process with hazard depletion 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("renewal")

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 ​