Imported cases
Introduction
Imported cases are infections that arrive from outside the population. They can enter a renewal process with susceptible depletion before the depletion or after it.
Packages used
using ComposableRecurrences
using ComposableRecurrences: Depletion, Transform
using CairoMakie, AlgebraOfGraphics, DataFramesMeta
CairoMakie.activate!(type = "png", px_per_unit = 2)Before or after depletion
Let add and as a Transform(+, b) after the Depletion give
where add keyword enters before the modifiers, so imports are drawn from the pool like local cases. A Transform(+, b) enters where it sits in the modifier tuple. After the Depletion, the imports are added on top and do not draw down the pool. Here 3 cases a day arrive on days 1 to 10,
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]
before = Recurrence(gi; modifiers = (Depletion(N),))(R; history = [0.0], add = ι)
after = Recurrence(gi; modifiers = (Depletion(N), Transform(+, TimeVarying(ι))))(R; history = [0.0])
@chain DataFrame("day" => 1:T, "add, drawn from the pool" => before, "Transform(+, ι) after Depletion" => after) begin
stack(Not(:day); variable_name = :imports, value_name = :count)
data(_) * mapping(:day, :count, color = :imports => "") * visual(Lines, linewidth = 2)
draw(_; axis = (xlabel = "Day", ylabel = "Infections"))
endThe 30 imports added after the depletion are not drawn from the pool, so local spread has more susceptibles to infect. The peak is higher, 93 infections against 88, and the outbreak leaves a smaller pool.
Performance
Each bar times a seeded renewal with hazard depletion and imports both before and after it over 200 days with a 20-day generation interval, against a preallocated hand-written loop.
performance_plot("imports")Learning more
Modifier order: how the place of a modifier in the tuple changes the model.
Public API: every public name with its docstring.