Skip to content

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 ​

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

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

Model ​

Let be the imported cases on day . The two models are

where is the number of infections on day , the reproduction number and the weight of the generation interval on lag . The hazard draw is   , with the susceptible pool after day and the population. In the first model the pool falls by , and in the second by  .

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   on days 1 to 10 and 0 after,  ,   and the run covers 80 days from no earlier infections.

julia
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.

julia
performance_plot("imports")

Learning more ​