Skip to content

Clinical outcomes ​

Introduction ​

Each clinical transition is a delay that happens with some probability. Here symptom onsets follow infections, hospital admissions follow onsets and deaths follow admissions.

Packages used ​

julia
using ComposableRecurrences
using CairoMakie, AlgebraOfGraphics, DataFramesMeta

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

Infections ​

The infections come from the renewal process of Renewal then delay:

where is the number of infections on day , the reproduction number and the generation interval's weight on lag . Here is 1.4 to day 30, 0.9 to day 50 and 1.2 after.

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 its probability as the gain. Here is 0.1 and is 0.25.

julia
onsets = Convolution([0.0, 0.2, 0.5, 0.3])(infections)
admissions = Convolution([0.3, 0.4, 0.2, 0.1])(onsets; gain = 0.1)
deaths = Convolution([0.1, 0.2, 0.4, 0.2, 0.1])(admissions; gain = 0.25)

@chain DataFrame(
    "day" => 1:T, "Infections" => infections, "Onsets" => onsets,
    "Admissions" => admissions, "Deaths" => deaths
) begin
    stack(Not(:day); variable_name = :outcome, value_name = :count)
    data(_) * mapping(:day, :count, row = :outcome => sorter("Infections", "Onsets", "Admissions", "Deaths")) *
        visual(Lines, linewidth = 2)
    draw(_; axis = (xlabel = "Day", ylabel = "Count"), facet = (; linkyaxes = :none))
end

Each outcome follows the shape of the one before, later and smaller. Over the run, admissions are 8.5% of infections and deaths 1.9%. These shares are below   and  , because infections still grow at the end and the last ones have outcomes after the run.

One delay from onset to death ​

Two delays one after the other are one delay whose weights are the convolution of theirs:

A chain of delays, the tuple (dA, dD), is this delay. It needs lags, here the 8 lags of the full convolution.

julia
dA, dD = [0.3, 0.4, 0.2, 0.1], [0.1, 0.2, 0.4, 0.2, 0.1]
onset_to_death = Convolution((dA, dD); lags = 8)
deaths_direct = onset_to_death(onsets; gain = 0.1 * 0.25)

@chain DataFrame("day" => 1:T, "Two delays" => deaths, "One chained delay" => deaths_direct) begin
    stack(Not(:day); variable_name = :model, value_name = :count)
    data(_) * mapping(:day, :count, color = :model => "", linestyle = :model => "") *
        visual(Lines, linewidth = 2)
    draw(_; axis = (xlabel = "Day", ylabel = "Deaths"))
end

Performance ​

Each bar times onsets, admissions and deaths as a chain of three delays over 200 days with 20-day delays, against a preallocated hand-written loop.

julia
performance_plot("clinical outcomes")

Learning more ​