Multiple observation streams: cases, deaths, and strata
Real-time surveillance rarely watches an epidemic through a single lens. The same infections surface as reported cases, hospital admissions, deaths, and often each of these split by age, region, or variant. These streams share one underlying infection process but differ in their reporting delay, ascertainment, and noise []. Fitting them jointly, one infection trajectory and several observation streams, propagates uncertainty correctly and lets a sparse stream (deaths) borrow strength from a dense one (cases).
This tutorial uses one construct, Split, for every multi-stream shape. Split observes the expected series arriving at the point where it sits in the pipeline through several named streams, so where you place it chooses the composition.
Parallel, placed high on infections. Every stream observes the same
, cases and deaths each a delayed, ascertained fraction of . Cascade, placed low after a shared layer. A later stream is observed downstream of an earlier one, deaths as a delayed fraction of the expected reported cases.
Strata, one stream per data-defined group such as an age band.
How Split threads streams
Every observation model in the package returns the uniform pair (; y_t, expected), the sampled observations y_t and the pre-error expected series the error was scored against. Exposing expected is what lets Split do all three shapes with one mechanism. Split feeds each stream the expected series reaching it, and because Split is itself an observation model a shared modifier can run before it. Split((cases = …, deaths = …)) on its own splits infections (parallel). LatentDelay(Split((cases = …, deaths = …)), pmf) applies a common delay first and then splits, so a stream nested inside another stream's pipeline sits downstream of it (cascade).
The threaded quantity is the expected, not the realised, series
A downstream stream reads its upstream stream's expected (pre-error) series, never its realised, sampled counts. So a cascade threads the mean reported cases into deaths, not a noisy draw. The case where an observation depends on another stream's realised observation is not covered here and is out of scope for now.
Split also prefixes each stream's sampled variables with the stream name automatically, so the streams stay distinct without any manual prefix layer.
Parallel: cases and deaths from shared infections
We drive the streams with a renewal infection process, exactly as in the renewal tutorial, and observe it through two pipelines. Cases are a short-delay, high-ascertainment negative-binomial stream. Deaths are a long-delay stream whose ascertainment, the infection-fatality ratio, is itself estimated. Each stream is a full observation model, so its ascertainment can be a fixed fraction or, as here, a latent Intercept model with a prior.
using ComposableTuringIDModels, Distributions, Random, Turing, Mooncake
using ADTypes: AutoMooncake
using Accessors
Random.seed!(1234)
latent = AR(
damp = [truncated(Normal(0.8, 0.05), 0, 1),
truncated(Normal(0.1, 0.05), 0, 1)],
init = [Normal(0.0, 0.2), Normal(0.0, 0.2)],
ϵ_t = HierarchicalNormal(std = HalfNormal(0.1)))
renewal = Renewal(; generation_time = Gamma(6.5, 0.62),
rt = latent, initialisation = Normal(log(100.0), 0.1))
cases = LatentDelay(
Ascertainment(NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
FixedIntercept(log(0.6))), # ~60% case ascertainment
LogNormal(1.6, 0.5)) # short infection→report delay
deaths = @set cases.model.latent_model = Intercept(Normal(log(0.015), 0.25)) # ~1.5% IFR
deaths = @set deaths.delay = LogNormal(2.8, 0.4) # long infection→death delay
parallel = Split((cases = cases, deaths = deaths))Split
├─ cases: LatentDelay
│ └─ model: Ascertainment
│ ├─ model: NegativeBinomialError
│ └─ latent: PrefixLatentModel
│ └─ model: FixedIntercept
└─ deaths: LatentDelay
└─ model: Ascertainment
├─ model: NegativeBinomialError
└─ latent: PrefixLatentModel
└─ model: InterceptA multi-stream model is assembled exactly like a single-stream one.
model = IDModel(renewal, parallel)IDModel
├─ infection: Renewal
│ └─ rt: AR
│ └─ ϵ_t: HierarchicalNormal
└─ observation: Split
├─ cases: LatentDelay
│ └─ model: Ascertainment
│ ├─ model: NegativeBinomialError
│ └─ latent: PrefixLatentModel
│ └─ model: FixedIntercept
└─ deaths: LatentDelay
└─ model: Ascertainment
├─ model: NegativeBinomialError
└─ latent: PrefixLatentModel
└─ model: InterceptPassing missing data simulates a synthetic outbreak. The per-stream data contract is a NamedTuple keyed by stream name, and the returned generated_y_t is a NamedTuple of the two simulated series.
n = 70
sim = as_turing_model(model, (cases = missing, deaths = missing), n)()
y = sim.generated_y_t
(total_cases = sum(y.cases), total_deaths = sum(y.deaths),
n_cases = length(y.cases), n_deaths = length(y.deaths))(total_cases = 16020, total_deaths = 310, n_cases = 96, n_deaths = 70)The two series come back at different lengths. One infection series serves both streams, so it is long enough for the deeper infection→death delay, and the shorter infection→report delay leaves the cases stream with expected values for earlier days too. Both are scored. Pass each stream the observations it has, and data_requirements reports the two lengths before the model is built.
Fitting conditions on both streams at once. We draw two chains in parallel with MCMCThreads(), matching the other tutorials, and differentiate with Mooncake, the recommended backend for this package (see Automatic differentiation backend).
ydata = (cases = y.cases, deaths = y.deaths)
posterior = as_turing_model(model, ydata, n)
chain = sample(
posterior, NUTS(0.95; adtype = AutoMooncake(; config = nothing)),
MCMCThreads(), 250, 2; progress = false)┌ Info: Found initial step size
└ ϵ = 0.0125
┌ Info: Found initial step size
└ ϵ = 0.003125
┌ Warning: There were 5 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 5 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 10 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483The two streams keep their own overdispersion parameters, prefixed by Split as cases.cluster_factor and deaths.cluster_factor, while sharing the one infection trajectory. The deaths stream's estimated IFR intercept (deaths.Ascertainment.intercept) is recovered alongside them. The dense case stream pins the shared
using MCMCChains
summarystats(chain)╭─FlexiSummary (9 statistics) ─────────────────────────────────────────────────╮
│ iter collapsed │
│ chain collapsed │
│ ↓ stat = [mean, std, mcse, ess_bulk, ess_tail, rhat, q5, q50, q95] │
│ │
│ Parameters (118) ── AbstractPPL.VarName │
│ Float64 init[1], init[2], damp[1], damp[2], std, ϵ_t[1], ϵ_t[2], ϵ_t[3], … │
│ ϵ_t[107], ϵ_t[108], ϵ_t[109], init_incidence, cases.cluster_factor │
│ deaths.Ascertainment.intercept, deaths.cluster_factor │
│ │
│ Extras (14) │
│ Float64 n_steps, is_accept, acceptance_rate, log_density │
│ hamiltonian_energy, hamiltonian_energy_error │
│ max_hamiltonian_energy_error, tree_depth, numerical_error │
│ step_size, nom_step_size, logprior, loglikelihood, logjoint │
│ │
│ Summary │
│ param mean std … rhat q5 q50 q95 │
│ init[1] -0.0088 0.1927 0.9995 -0.3346 -0.0096 0.3099 │
│ init[2] 0.2923 0.1457 1.0090 0.0466 0.2998 0.5210 │
│ damp[1] 0.7904 0.0431 1.0107 0.7218 0.7902 0.8600 │
│ damp[2] 0.0862 0.0406 0.9979 0.0208 0.0844 0.1539 │
│ std 0.0676 0.0262 … 1.0065 0.0354 0.0623 0.1208 │
│ ϵ_t[1] 0.4353 1.0272 1.0155 -1.2794 0.3752 2.1215 │
│ ϵ_t[2] 0.4990 0.9079 1.0201 -1.1485 0.5356 1.9926 │
│ ϵ_t[3] 0.3535 1.0173 1.0108 -1.1846 0.3347 2.0814 │
│ ϵ_t[4] 0.3979 1.1307 1.0058 -1.4861 0.3785 2.0656 │
│ ⋮ ⋱ │
│ ϵ_t[105] -0.0430 1.0089 … 1.0199 -1.7695 -0.0408 1.6356 │
│ ϵ_t[106] -0.0026 1.1399 1.0271 -1.9320 0.0235 1.8756 │
│ ϵ_t[107] -0.0751 1.0462 1.0113 -1.7576 -0.0344 1.6194 │
│ ϵ_t[108] 0.0175 0.9772 1.0032 -1.5212 -0.0083 1.6239 │
│ ϵ_t[109] 0.0013 0.9993 1.0090 -1.6193 0.0172 1.4993 │
│ init_incide… 4.6480 0.0984 … 1.0006 4.4842 4.6486 4.8087 │
│ cases.clust… 0.1896 0.0183 0.9971 0.1617 0.1876 0.2218 │
│ deaths.Asce… -4.0820 0.0625 1.0140 -4.1869 -4.0799 -3.9847 │
│ deaths.clus… 0.1168 0.0751 1.0180 0.0138 0.1111 0.2517 │
╰──────────────────────────────────────────────────────────────────────────────╯Summary statistics confirm the parameters converged, but they do not show whether the fit actually tracks the two simulated series. Posterior-predictive draws from the same fitted chain, plotted against the simulated counts, close that loop. The helpers below turn a time × draws matrix into 50% and 95% credible bands and draw a median line with ribbons. predictive_bands walks a named stream's per-index sampled y_t, filling any index a stream's delay leaves unscored with missing.
Split prefixes each stream's y_t, so predictive_bands reads cases.y_t[i] and deaths.y_t[i] off the predict chain, the prefixed equivalent of the bare y_t[i] the renewal tutorial reads from a single-stream model.
missmodel = as_turing_model(model, (cases = missing, deaths = missing), n)
pred = predict(missmodel, chain)
# Each stream is scored over its own expected series, so read its bands at its
# own length. Both end on the same day, so a shared day axis ending at `n`
# right-aligns them the way the model does.
cases_days = (n - length(y.cases) + 1):n
deaths_days = (n - length(y.deaths) + 1):n
cases_bands = predictive_bands(
pred, length(y.cases), i -> @varname(cases.y_t[i]))
deaths_bands = predictive_bands(
pred, length(y.deaths), i -> @varname(deaths.y_t[i]))
fig = Figure(; size = (760, 620))
ax1 = Axis(fig[1, 1]; ylabel = "Cases")
ci_ribbon!(ax1, cases_days, cases_bands; color = :teal,
label = "posterior predictive")
scatter!(ax1, cases_days, y.cases; color = :black, markersize = 6,
label = "simulated")
axislegend(ax1; position = :lt)
ax2 = Axis(fig[2, 1]; xlabel = "Day", ylabel = "Deaths")
ci_ribbon!(ax2, deaths_days, deaths_bands; color = :firebrick,
label = "posterior predictive")
scatter!(ax2, deaths_days, y.deaths; color = :black, markersize = 6,
label = "simulated")
axislegend(ax2; position = :lt)
fig
The band covers the simulated series on almost every day for both streams, and both medians track the outbreak's rise and fall rather than sitting flat at the mean. The sparser death series (82 simulated deaths against 6576 cases over the same 70 days) still recovers. Its band is visibly wider, but it moves with the same underlying trajectory rather than needing its own signal to do so.
Cascade: deaths downstream of reported cases
In the parallel model, cases and deaths both branch off infections, so a reporting artefact in the case series (a weekend dip, an ascertainment change) does not touch deaths. Sometimes we want the opposite, deaths modelled as a delayed fraction of the reported cases, so whatever is reflected in cases propagates into deaths. That is a cascade Split placed lower in the stack. Share the infection→case-report delay, then split.
cascade = LatentDelay( # infection→case delay
Split((
cases = NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
deaths = LatentDelay( # case→death delay
Ascertainment(NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
FixedIntercept(log(0.02))),
LogNormal(2.2, 0.3)))),
LogNormal(1.6, 0.5))LatentDelay
└─ model: Split
├─ cases: NegativeBinomialError
└─ deaths: LatentDelay
└─ model: Ascertainment
├─ model: NegativeBinomialError
└─ latent: PrefixLatentModel
└─ model: FixedInterceptThe deaths stream's expected input is the delayed-and-ascertained expected cases rather than the raw infections, so it is both scaled by the fatality fraction and shortened by the case delay.
cascade_model = IDModel(renewal, cascade)
cas = as_turing_model(cascade_model, (cases = missing, deaths = missing), n)()
(cases_expected = length(cas.expected_y_t.cases),
deaths_expected = length(cas.expected_y_t.deaths),
deaths_per_case = round(
sum(cas.expected_y_t.deaths) / sum(cas.expected_y_t.cases), digits = 3))(cases_expected = 87, deaths_expected = 70, deaths_per_case = 0.016)Strata: one stream per age band
A stratified stream, one observation series per age band, region, or variant, is again the same construct, here composed with the renewal infection process and observed through one named stream per band. Each band is a full observation model, so its delay and ascertainment can differ, and its parameters are namespaced by the band name.
strata_obs = Split((
young = LatentDelay(
Ascertainment(NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
FixedIntercept(log(0.7))), LogNormal(1.5, 0.4)),
old = LatentDelay(
Ascertainment(NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
FixedIntercept(log(0.4))), LogNormal(1.8, 0.4))))
strata_model = IDModel(renewal, strata_obs)
strata_sim = as_turing_model(
strata_model, (young = missing, old = missing), n)().generated_y_t
map(s -> sum(skipmissing(s)), strata_sim) # totals per band(young = 7880, old = 4825)The streams above each observe the same infections. When the streams instead draw on a weighted mix of infections, one band, another band, and a summed total, the same Split carries an observation-strata × infection-strata weight matrix, and a single template model is replicated once per data stream. Split(template, W) projects the infection series reaching it through W, so it composes inside an IDModel like any other observation model. The infections come from the modelled process, not a hand-built series. One weight matrix covers the one-to-one (an identity map), many-to-one (an aggregation row summing infection strata into one stream), and many-to-many (a general matrix) infection → observation cases.
Here the renewal process supplies one infection stratum, and W maps it onto a young band, an old band, and their total.
W = reshape([0.7, 0.3, 1.0], 3, 1) # young, old, and their total
weighted = Split(LatentDelay(PoissonError(), LogNormal(1.6, 0.5)), W)
weighted_model = IDModel(renewal, weighted)
age = as_turing_model(
weighted_model, (young = missing, old = missing, total = missing), n)()
map(s -> sum(skipmissing(s)), age.generated_y_t) # simulated total per band(young = 4876, old = 2061, total = 7129)The aggregate total stream sees the summed expected infections of both bands, so its expected series is exactly young .+ old.
Simulating checks that the forward map runs. It does not check that a many-to-one W is actually recoverable from data. Fitting weighted_model to its own simulated streams answers that. The fit conditions on young, old, and the aggregate total together, exactly as Split conditions on any other named streams.
weighted_data = (young = age.generated_y_t.young, old = age.generated_y_t.old,
total = age.generated_y_t.total)
weighted_posterior = as_turing_model(weighted_model, weighted_data, n)
weighted_chain = sample(
weighted_posterior, NUTS(0.95; adtype = AutoMooncake(; config = nothing)),
MCMCThreads(), 250, 2; progress = false)┌ Info: Found initial step size
└ ϵ = 0.025
┌ Info: Found initial step size
└ ϵ = 0.0001953125
┌ Warning: There were 59 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 158 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 217 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483young, old, and total are not three independent counts. total is exactly young + old, so all three read the same one-stratum
summarystats(weighted_chain)╭─FlexiSummary (9 statistics) ─────────────────────────────────────────────────╮
│ iter collapsed │
│ chain collapsed │
│ ↓ stat = [mean, std, mcse, ess_bulk, ess_tail, rhat, q5, q50, q95] │
│ │
│ Parameters (89) ── AbstractPPL.VarName │
│ Float64 init[1], init[2], damp[1], damp[2], std, ϵ_t[1], ϵ_t[2], ϵ_t[3], … │
│ ϵ_t[78], ϵ_t[79], ϵ_t[80], ϵ_t[81], ϵ_t[82], ϵ_t[83] │
│ init_incidence │
│ │
│ Extras (14) │
│ Float64 n_steps, is_accept, acceptance_rate, log_density │
│ hamiltonian_energy, hamiltonian_energy_error │
│ max_hamiltonian_energy_error, tree_depth, numerical_error │
│ step_size, nom_step_size, logprior, loglikelihood, logjoint │
│ │
│ Summary │
│ param mean std … rhat q5 q50 q95 │
│ init[1] 0.1541 1.0088 3.3358 -0.8884 0.1770 1.1618 │
│ init[2] -0.9201 0.4237 3.3616 -1.4117 -0.8748 -0.4979 │
│ damp[1] 0.4147 0.1455 2.8034 0.2580 0.4162 0.5600 │
│ damp[2] 0.7860 0.0898 2.7321 0.6963 0.7777 0.8781 │
│ std 1.2212 0.3383 … 3.2608 0.8498 1.2640 1.5582 │
│ ϵ_t[1] -0.7958 0.2150 3.3129 -1.0347 -0.7851 -0.5811 │
│ ϵ_t[2] 0.8338 0.6193 3.1569 0.2152 0.8055 1.4731 │
│ ϵ_t[3] 0.1628 0.9477 2.4926 -0.8150 0.1711 1.1096 │
│ ϵ_t[4] 1.7477 0.0283 3.3220 1.6940 1.7689 1.7739 │
│ ⋮ ⋱ │
│ ϵ_t[76] -0.1141 0.3398 2.3409 -0.4534 -0.1403 0.2470 │
│ ϵ_t[77] 0.1015 1.6858 1.9306 -1.5882 0.1113 1.7856 │
│ ϵ_t[78] 0.7482 0.7006 2.4747 0.0484 0.7279 1.4708 │
│ ϵ_t[79] 1.5285 0.3746 2.2201 1.1544 1.5210 1.9208 │
│ ϵ_t[80] -0.0483 1.4036 … 2.7034 -1.4504 -0.0700 1.3887 │
│ ϵ_t[81] -0.4829 1.1265 2.2391 -1.6245 -0.4720 0.6424 │
│ ϵ_t[82] -0.8163 0.7244 2.2065 -1.5568 -0.8086 -0.0926 │
│ ϵ_t[83] 1.0974 0.3329 2.3289 0.7581 1.1021 1.4299 │
│ init_incide… -0.0167 1.5159 2.8247 -1.5306 -0.0609 1.5531 │
╰──────────────────────────────────────────────────────────────────────────────╯Posterior-predictive bands per stream, plotted against the simulated counts, show whether the shared infection process and the W weights together recover each stratum. That includes total, which is nowhere in the infection process itself and only assembled from it by W.
weighted_pred = predict(as_turing_model(
weighted_model, (young = missing, old = missing, total = missing), n),
weighted_chain)
young_bands = predictive_bands(weighted_pred, n, i -> @varname(young.y_t[i]))
old_bands = predictive_bands(weighted_pred, n, i -> @varname(old.y_t[i]))
total_bands = predictive_bands(weighted_pred, n, i -> @varname(total.y_t[i]))
fig2 = Figure(; size = (760, 780))
ax_young = Axis(fig2[1, 1]; ylabel = "Young")
ax_old = Axis(fig2[2, 1]; ylabel = "Old")
ax_total = Axis(fig2[3, 1]; ylabel = "Total (young + old)", xlabel = "Day")
for (ax, bands, obs, color) in (
(ax_young, young_bands, age.generated_y_t.young, :teal),
(ax_old, old_bands, age.generated_y_t.old, :firebrick),
(ax_total, total_bands, age.generated_y_t.total, :purple))
ci_ribbon!(ax, 1:n, bands; color = color, label = "posterior predictive")
scatter!(ax, 1:n, obs; color = :black, markersize = 6, label = "simulated")
end
axislegend(ax_young; position = :lt)
fig2
Despite the slower mixing, the 95% band covers the simulated counts on almost every day for all three streams, so the many-to-one map is recovered. A single shared young and old need no independent signal of their own, and total still lands on its simulated series because W ties it to the same shared path.
Here the single renewal process supplied one infection stratum, broadcast through W. When the strata are genuinely separate infection processes, several distinct regions each with its own latent, swap the single infection model for CombineInfections. It draws each process independently and stacks the results into the same infection-strata × time matrix Split/StrataMap already expect, so IDModel(CombineInfections([...]), Split(template, W)) maps several distinct infection processes onto streams end-to-end. For one process carried across a strata axis instead, with partially pooled per-stratum deviations, see Stratify and Partial pooling across groups. It also composes with Renewal's mixing slot, see Coupled patch models.
References
- K. Sherratt, S. Abbott, S. R. Meakin, J. Hellewell, J. D. Munday, N. Bosse, M. Jit and S. Funk. Exploring surveillance data biases when estimating the reproduction number: with insights into subpopulation transmission of COVID-19 in England. Philosophical Transactions of the Royal Society B 376, 20200283 (2021).