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
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
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
where Convolution with its probability as the gain. Here
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))
endEach 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
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.
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"))
endPerformance
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.
performance_plot("clinical outcomes")Learning more
Time-varying delays and kernels: delays that change over time.
Public API: every public name with its docstring.