Skip to content

Symptom onsets, hospital admissions and deaths as a chain of delays ​

Introduction ​

A clinical outcome follows an earlier event after a delay and with a probability. This tutorial computes symptom onsets from infections, hospital admissions from onsets and deaths from admissions, each as a delay with a probability. It then replaces the two delays from onset to death by one delay.

Packages used ​

julia
using ComposableRecurrences
using CairoMakie, AlgebraOfGraphics, DataFramesMeta

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

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

Infections ​

The infections are those of the renewal process of A renewal process with susceptible depletion and a reporting delay,

where is the number of infections on day , the reproduction number and the weight of the generation interval on lag . is 1.4 to day 30, 0.9 to day 50 and 1.2 after, the history is 5 infections on the day before day 1, and the run covers 80 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 = Recurrence(gi)(R; history = [5.0])

A chain of delays ​

Onsets follow infections, admissions follow onsets with probability , and deaths follow admissions with probability :

where , and are the weights of the three delays on lag . Each transition is a Convolution with the delay as its kernel and the probability as its gain. Here   and  .

julia
# The outcome that follows each `event` after `delay` with `probability`.
function outcome(event, delay; probability = 1.0)
    return Convolution(delay)(event; gain = probability)
end

wO = [0.0, 0.2, 0.5, 0.3]
wA = [0.3, 0.4, 0.2, 0.1]
wD = [0.1, 0.2, 0.4, 0.2, 0.1]
h, f = 0.1, 0.25
onsets = outcome(infections, wO)
admissions = outcome(onsets, wA; probability = h)
deaths = outcome(admissions, wD; probability = f)

named = [
    "Infections" => infections, "Onsets" => onsets,
    "Admissions" => admissions, "Deaths" => deaths,
]
outcomes = long(named...)
draw(
    data(outcomes) *
        mapping(:day, :value, row = :series => sorter(first.(named))) *
        visual(Lines, linewidth = 2);
    axis = (xlabel = "Day", ylabel = "Count"), facet = (; linkyaxes = :none)
)

Over the 80 days admissions are 8.5% of infections and deaths 1.9%. Both are below   and  , as the outcomes of the last infections fall after day 80.

One delay from onset to death ​

Two delays in sequence are one delay whose weights are the convolution of theirs:

A tuple of delays passed as the kernel is this chain of delays. The keyword lags gives its length, here the 8 lags of  .

julia
onset_to_death = Convolution((wA, wD); lags = 8)
deaths_direct = onset_to_death(onsets; gain = h * f)
deaths_direct ≈ deaths
true

The one delay returns the deaths of the two delays in sequence.

Performance ​

The timed model is onsets, admissions and deaths as a chain of three delays of 20 lags over 200 days. The figure gives its minimum time and that of a preallocated hand-written loop of the same model.

julia
performance_plot("clinical outcomes")

Learning more ​