Imported cases before or after susceptible depletion
Introduction
This tutorial is for a user whose population receives infections from outside. Imported cases are infections acquired outside the modelled population. The tutorial adds them to a renewal process with susceptible depletion in two ways and compares the infections each gives:
before the depletion, where an imported case is drawn from the susceptible pool;
after the depletion, where it is not.
It builds on A renewal process with susceptible depletion and a reporting delay.
Packages used
using ComposableRecurrences
using ComposableRecurrences: Depletion, Transform
using CairoMakie, AlgebraOfGraphics, DataFramesMeta
CairoMakie.activate!(type = "png", px_per_unit = 2)Model
Let
where
The add input of a call enters before the modifiers, so imports passed as add are drawn from the pool like local cases. A Transform(+, b) acts at its place in the tuple of modifiers, so after the Depletion it adds imports that leave the pool unchanged. Here
gi = [0.1, 0.3, 0.3, 0.2, 0.1]
T = 80
N = 2_000.0
R = fill(1.8, T)
ι = [t <= 10 ? 3.0 : 0.0 for t in 1:T]
# Infections of the renewal process with imports `ι` drawn from the pool
# of a population `N`.
function imports_before(gi, R, ι, N)
renewal = Recurrence(gi; modifiers = (Depletion(N),))
return renewal(R; history = [0.0], add = ι)
end
# The same with the imports added after the draw from the pool.
function imports_after(gi, R, ι, N)
modifiers = (Depletion(N), Transform(+, TimeVarying(ι)))
return Recurrence(gi; modifiers)(R; history = [0.0])
end
before = imports_before(gi, R, ι, N)
after = imports_after(gi, R, ι, N)
table = stack(
DataFrame(
"day" => 1:T, "Before depletion (add)" => before,
"After depletion (Transform)" => after
),
Not(:day); variable_name = :imports
)
draw(
data(table) * mapping(:day, :value, color = :imports => "") *
visual(Lines, linewidth = 2);
axis = (xlabel = "Day", ylabel = "Infections")
)Infections peak on day 20 in both models, at 93 with the imports after the depletion and at 88 with them before it. Over the 80 days the totals are 1521 and 1480. The 30 imports added after the depletion are not drawn from the pool, so the local infections have 30 more susceptible people to draw from.
Performance
The timed model is a seeded renewal process with hazard depletion and imports both before and after it, 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("imports")Learning more
Order states how the place of a modifier in the tuple changes the step.
The reproduction number from a run removes imports from the infections before taking the effective reproduction number.