A renewal process with susceptible depletion and a reporting delay
Introduction
This tutorial builds a model of one population 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.
Packages used
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.
# 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...))
endA renewal process
Infections on day
where Recurrence and
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
where exponential_history returns
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
Susceptible depletion
A Depletion draws the infections of each day from a pool
where Depletion(N) takes the hazard form, and Depletion(N, Floor()) the floored form. Here
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
# 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. The hazard form draws less from the same pool because
Reported cases
Reports are a share
where Convolution and
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.
performance_plot("renewal")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 adds infections from outside to this model, before and after depletion.
Vaccination adds a second pool of vaccinated people.
Clinical outcomes chains further delays after the infections.