Reporting triangle, case reproduction number and expected descendants
This page computes three quantities indexed by the day of infection from one run of the model of Three towns, step by step:
the reporting triangle, the expected reports by infection day and reporting delay, and its right-truncated form at a given day [];
the case reproduction number, the expected number of infections caused by one infection on a given day [, ];
the expected number of descendants of one infection on a given day, over all later generations.
The first is the terms of a Convolution before its sum over lags. The second is the transpose of a convolution, a sum over later times. The third is a Recurrence run backwards in time.
Model and notation
Infections
The generation interval distribution gi, K, pop, seed, R, towns and T are those of Three towns, step by step.
using ComposableRecurrences
using ComposableRecurrences: Depletion, Pressure, Primary, contributions
using CairoMakie, AlgebraOfGraphics, DataFramesMeta
using ForwardDiff
CairoMakie.activate!(type = "png", px_per_unit = 2)
renewal = Recurrence(
gi; coupling = K, modifiers = (Depletion(PerStratum(pop)),)
)
delay = Convolution([0.0, 0.1, 0.25, 0.3, 0.2, 0.1, 0.05])
ρ = 0.4
run = renewal(R; history = seed, record = Pressure())
infections = run.y
size(infections)(3, 75)Two helpers draw every figure: one puts the rows of a matrix in a long table, and one draws lines from such a table.
# The rows of `x` as named series in a long table, with `days` as its times.
function long(x, names; days = axes(x, 2), name = :series)
df = DataFrame(permutedims(x), names)
df.day = collect(days)
return stack(df, Not(:day); variable_name = name, value_name = :value)
end
# Lines of `:value` against `:day`, coloured by `colour`, with `kwargs`
# passed to the axis.
function lines_by(df, colour; col = nothing, kwargs...)
by = col === nothing ? mapping(color = colour => "") :
mapping(color = colour => "", col = col)
plt = data(df) * mapping(:day, :value) * by * visual(Lines, linewidth = 2)
return draw(plt; axis = (; kwargs...), figure = (size = (640, 300),))
endReporting triangle
The expected number of reports in town
and these reports are made on day
contributions returns the terms of a convolution before the sum over lags. With indexing = Primary() each column holds the terms of one input time, here an infection day, and stop is the last day on which a term may arrive.
# Expected reports by stratum, delay and infection day, for reports made up
# to day `stop`.
function reporting_triangle(delay, infections, ρ; stop = size(infections, 2))
return contributions(
delay, infections; gain = ρ, indexing = Primary(), stop
)
end
# The sum of a triangle over delays: reports by stratum and infection day.
reported(triangle) = dropdims(sum(triangle; dims = 2); dims = 2)
triangle = reporting_triangle(delay, infections, ρ; stop = T + 6)
size(triangle)(3, 7, 75)With stop = T + 6 every delay of every infection day is included, so each infection day's reports sum to
reported(triangle) ≈ ρ .* infectionstruecells = DataFrame(
day = repeat(1:T; inner = 7), delay = repeat(0:6; outer = T),
value = vec(triangle[1, :, :])
)
draw(
data(cells) * mapping(:day, :delay, :value => "Expected reports") *
visual(Heatmap);
axis = (xlabel = "Infection day", ylabel = "Delay (days)"),
figure = (size = (640, 300),)
)
In town A the largest cell is infection day 36, the day of peak infections, at a delay of 3 days, the mode of
Right truncation
At day stop = τ leaves out every term that arrives later. Nowcasting reported cases from a right-truncated reporting triangle estimates the eventual reports of recent days from such a triangle, with a fixed delay and with a delay whose hazard depends on the reporting day.
Case reproduction number
The instantaneous reproduction number is the ratio of new infections to the infection pressure on the same day [, ]. In this model it is
which is below record = Pressure() returns
instantaneous = run.y ./ run.pressure
round.(instantaneous[:, [1, 36, 50, 75]]; digits = 2)3×4 Matrix{Float64}:
1.8 1.1 0.55 0.23
1.8 1.75 1.29 0.41
1.8 1.73 1.16 0.37The case reproduction number is the expected number of infections caused by one infection on day
The sum over tail supplies them, here as the values of day
# The transpose of the convolution with the generation interval on lags
# 1 to L: a sum over the L days after each day.
forward_sum(g) = Convolution(g; lags = 1:length(g))'
# The case reproduction number by stratum and infection day, from the
# instantaneous one, holding its last value after the last day.
function case_reproduction_number(g, K, instantaneous)
x = K' * instantaneous
return forward_sum(g)(x; tail = repeat(x[:, end], 1, length(g)))
end
case = case_reproduction_number(gi, K, instantaneous)
round.(case[:, [1, 36, 50, 75]]; digits = 2)3×4 Matrix{Float64}:
1.8 0.9 0.36 0.23
1.8 1.7 0.76 0.41
1.8 1.65 0.68 0.37# A long table of `x` by town, labelled as the series `label`.
by_town(x, label) = @transform(long(x, towns; name = :town), :series = label)
lines_by(
vcat(by_town(instantaneous, "Instantaneous"), by_town(case, "Case")),
:series; col = :town, xlabel = "Day", ylabel = "Reproduction number"
)
The case reproduction number is the instantaneous one averaged over the following generation interval, whose mean is 3.4 days. It falls below 1 on day 35 in town A, 49 in town B and 48 in town C, and the instantaneous reproduction number on days 38, 52 and 52.
Expected descendants
Let
The value of
which is the form of a Recurrence with kernel reverse of a recurrence is that run. Its tail, the values after the last day, is zero by default, which is the terminal condition above.
# Expected descendants by stratum and infection day, up to the last day.
function expected_descendants(g, K, instantaneous)
backwards = reverse(Recurrence(g; coupling = transpose(K)))
W = backwards(instantaneous; add = instantaneous)
return 1 .+ forward_sum(g)(K' * W)
end
descendants = expected_descendants(gi, K, instantaneous)
round.(descendants[:, [1, 20, 40, 60, 75]]; digits = 1)3×5 Matrix{Float64}:
1219.8 36.2 2.5 1.3 1.0
12669.0 424.9 12.3 1.7 1.0
9886.0 333.0 9.9 1.6 1.0lines_by(
long(descendants, towns), :series;
xlabel = "Infection day", ylabel = "Expected descendants by day 75",
yscale = log10
)
One infection on day 1 has 1,220 expected descendants by day 75 in town A, 12,669 in town B and 9,886 in town C. An infection on day 75 has 1, itself.
The expected number of descendants is also a sensitivity. With
linear = Recurrence(gi; coupling = K)
total(a) = sum(linear(instantaneous; history = seed, add = reshape(a, 3, T)))
reshape(ForwardDiff.gradient(total, zeros(3 * T)), 3, T) ≈ descendantstrueReferences
C. Fraser. Estimating individual and household reproduction numbers in an emerging epidemic. PLoS ONE 2, e758 (2007).
A. Cori, N. M. Ferguson, C. Fraser and S. Cauchemez. A new framework and software to estimate time-varying reproduction numbers during epidemics. American Journal of Epidemiology 178, 1505–1512 (2013).
M. Höhle and M. an der Heiden. Bayesian nowcasting during the STEC O104:H4 outbreak in Germany, 2011. Biometrics 70, 993–1002 (2014).
J. Wallinga and P. Teunis. Different epidemic curves for severe acute respiratory syndrome reveal similar impacts of control measures. American Journal of Epidemiology 160, 509–516 (2004).