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 [4]. Fitting them jointly — one infection trajectory, several observation streams — propagates uncertainty correctly and lets a sparse stream (deaths) borrow strength from a dense one (cases).
This case study 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 (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), while 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 (error-corrupted) observation — feeding sampled cases, not expected cases, into deaths — 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 case study, 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
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 = LatentDelay(
Ascertainment(NegativeBinomialError(cluster_factor = HalfNormal(0.1)),
Intercept(Normal(log(0.015), 0.25))), # estimated ~1.5% IFR
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: InterceptThe composed model assembles the renewal infection process and the two-stream observation model exactly like a single-stream study.
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(skipmissing(y.cases)), total_deaths = sum(skipmissing(y.deaths)))(total_cases = 6576, total_deaths = 82)Fitting conditions on both streams at once. We draw a full chain with NUTS, matching the other case studies, 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.025
┌ Info: Found initial step size
└ ϵ = 0.00625
┌ Warning: There were 11 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/WteH7/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/WteH7/src/mcmc/hmc.jl:483
┌ Warning: There were 16 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/WteH7/src/mcmc/hmc.jl:483The two streams keep their own overdispersion parameters — Split prefixes them cases.cluster_factor and deaths.cluster_factor — while sharing the one infection trajectory, and 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 (77) ── AbstractPPL.VarName │
│ Float64 ar_init[1], ar_init[2], damp_AR[1], damp_AR[2], std, ϵ_t[1], │
│ ϵ_t[2], ϵ_t[3], ϵ_t[4], ϵ_t[5], ϵ_t[6], ϵ_t[7], ϵ_t[8], ϵ_t[9], │
│ ϵ_t[10], ϵ_t[11], ϵ_t[12], ϵ_t[13], ϵ_t[14], ϵ_t[15], ϵ_t[16], │
│ ϵ_t[17], ϵ_t[18], ϵ_t[19], ϵ_t[20], ϵ_t[21], ϵ_t[22], ϵ_t[23], │
│ ϵ_t[24], ϵ_t[25], ϵ_t[26], ϵ_t[27], ϵ_t[28], ϵ_t[29], ϵ_t[30], │
│ ϵ_t[31], ϵ_t[32], ϵ_t[33], ϵ_t[34], ϵ_t[35], ϵ_t[36], ϵ_t[37], │
│ ϵ_t[38], ϵ_t[39], ϵ_t[40], ϵ_t[41], ϵ_t[42], ϵ_t[43], ϵ_t[44], │
│ ϵ_t[45], ϵ_t[46], ϵ_t[47], ϵ_t[48], ϵ_t[49], ϵ_t[50], ϵ_t[51], │
│ ϵ_t[52], ϵ_t[53], ϵ_t[54], ϵ_t[55], ϵ_t[56], ϵ_t[57], ϵ_t[58], │
│ ϵ_t[59], ϵ_t[60], ϵ_t[61], ϵ_t[62], ϵ_t[63], ϵ_t[64], ϵ_t[65], │
│ ϵ_t[66], ϵ_t[67], ϵ_t[68], 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 mcse ess_bulk ess_tail rhat … │
│ ar_init[1] -0.0167 0.1969 0.0080 608.7734 338.1784 1.0085 … │
│ ar_init[2] 0.3081 0.1415 0.0058 572.9745 438.1188 1.0069 … │
│ damp_AR[1] 0.7872 0.0397 0.0018 459.0148 340.2352 0.9993 … │
│ damp_AR[2] 0.0884 0.0400 0.0018 482.4593 232.9202 0.9997 … │
│ std 0.0709 0.0315 0.0020 224.8616 353.1196 1.0017 … │
│ ϵ_t[1] 0.4174 0.9535 0.0337 799.9039 383.5403 1.0033 … │
│ ϵ_t[2] 0.4383 1.0196 0.0420 573.2935 394.7271 1.0021 … │
│ ϵ_t[3] 0.4226 0.9838 0.0373 686.4259 360.1761 1.0017 … │
│ ϵ_t[4] 0.2835 1.0372 0.0415 645.6188 324.3197 0.9985 … │
│ ϵ_t[5] 0.2258 0.9224 0.0376 606.2190 335.9886 1.0055 … │
│ ϵ_t[6] 0.1821 0.9958 0.0389 646.4268 352.1886 0.9985 … │
│ ϵ_t[7] 0.0865 1.0591 0.0420 619.7250 269.3216 1.0001 … │
│ ϵ_t[8] 0.1064 1.0096 0.0373 706.4556 389.4000 0.9992 … │
│ ϵ_t[9] 0.0873 0.9638 0.0393 605.9683 379.2472 1.0006 … │
│ ϵ_t[10] -0.0470 0.9528 0.0342 783.6397 312.7835 0.9992 … │
│ ϵ_t[11] -0.0683 0.9554 0.0329 839.2337 326.6224 1.0019 … │
│ ϵ_t[12] -0.1503 0.9704 0.0409 593.3585 267.9787 0.9980 … │
│ ϵ_t[13] -0.2123 0.9165 0.0400 509.3176 463.3332 0.9998 … │
│ ϵ_t[14] -0.1247 0.9502 0.0342 772.1716 329.3277 0.9995 … │
│ ϵ_t[15] -0.0795 0.8833 0.0338 672.0970 436.2902 1.0025 … │
│ ϵ_t[16] -0.1239 0.9095 0.0348 678.8929 381.4196 1.0090 … │
│ ϵ_t[17] -0.1410 0.9791 0.0385 645.0351 261.6471 1.0025 … │
│ ϵ_t[18] -0.1437 1.0127 0.0382 640.0786 285.3709 1.0049 … │
│ ϵ_t[19] -0.0759 0.9049 0.0350 662.5868 356.0969 0.9990 … │
│ ϵ_t[20] -0.1015 0.9110 0.0314 839.9808 494.3162 1.0014 … │
│ ϵ_t[21] -0.1593 0.9189 0.0375 602.4113 359.2774 1.0005 … │
│ ϵ_t[22] -0.2519 0.9422 0.0364 686.2616 322.0453 1.0007 … │
│ ϵ_t[23] -0.2879 0.9490 0.0365 685.4431 324.9934 1.0080 … │
│ ϵ_t[24] -0.3468 0.8774 0.0369 574.4803 338.3355 0.9981 … │
│ ϵ_t[25] -0.2839 0.9775 0.0353 762.4121 339.7730 1.0001 … │
│ ϵ_t[26] -0.1702 0.9813 0.0331 895.2634 426.6203 1.0080 … │
│ ϵ_t[27] -0.2465 0.9164 0.0356 658.4948 393.5136 1.0006 … │
│ ϵ_t[28] -0.2863 0.9560 0.0314 890.2652 390.0418 0.9991 … │
│ ϵ_t[29] -0.3223 0.9946 0.0327 926.0141 441.5745 0.9996 … │
│ ϵ_t[30] -0.3531 0.9440 0.0349 739.5174 269.8338 1.0055 … │
│ ϵ_t[31] -0.2723 0.9733 0.0359 735.8630 330.8633 0.9983 … │
│ ϵ_t[32] -0.3969 1.0054 0.0300 1187.3777 421.6128 0.9985 … │
│ ϵ_t[33] -0.3773 0.8911 0.0377 553.3166 367.4394 1.0023 … │
│ ϵ_t[34] -0.4531 0.9390 0.0332 772.4996 242.8868 1.0149 … │
│ ϵ_t[35] -0.4574 1.0242 0.0386 701.7419 328.6701 0.9983 … │
│ ϵ_t[36] -0.4577 0.9438 0.0394 572.6689 335.2012 1.0042 … │
│ ϵ_t[37] -0.2487 1.0353 0.0444 532.5144 327.9930 1.0023 … │
│ ϵ_t[38] -0.0969 0.9718 0.0387 653.8856 283.1417 0.9987 … │
│ ϵ_t[39] -0.0456 1.0090 0.0424 578.7541 292.4394 0.9982 … │
│ ϵ_t[40] 0.0995 0.9972 0.0413 578.1188 258.4775 1.0005 … │
│ ϵ_t[41] 0.1478 0.8874 0.0349 681.3036 419.4254 0.9990 … │
│ ϵ_t[42] 0.2913 0.9459 0.0353 771.7828 326.7585 1.0007 … │
│ ϵ_t[43] 0.4653 0.9476 0.0320 892.6603 375.4466 1.0029 … │
│ ϵ_t[44] 0.4989 0.9849 0.0372 706.3668 374.3784 0.9999 … │
│ ϵ_t[45] 0.3900 0.9577 0.0297 1063.0841 420.6952 0.9989 … │
│ ϵ_t[46] 0.2941 0.9503 0.0424 487.6664 369.1865 0.9981 … │
│ ϵ_t[47] 0.1929 0.9240 0.0328 786.6528 342.9361 0.9989 … │
│ ϵ_t[48] 0.2198 0.8750 0.0324 730.9891 436.0858 0.9996 … │
│ ϵ_t[49] 0.3283 0.9298 0.0323 820.7980 438.4716 0.9989 … │
│ ϵ_t[50] 0.4068 0.8958 0.0341 698.5367 421.0140 1.0014 … │
│ ϵ_t[51] 0.3638 0.9059 0.0347 674.7412 353.1196 0.9982 … │
│ ϵ_t[52] 0.2788 0.9450 0.0351 727.6787 323.8611 1.0070 … │
│ ϵ_t[53] 0.1363 0.9700 0.0378 662.9945 349.7983 1.0060 … │
│ ϵ_t[54] 0.0009 0.9360 0.0403 580.7933 290.6354 1.0008 … │
│ ϵ_t[55] -0.0306 0.9105 0.0347 698.1041 473.4051 1.0056 … │
│ ϵ_t[56] -0.0956 1.0551 0.0414 666.4419 334.7822 1.0003 … │
│ ϵ_t[57] -0.0912 0.9511 0.0353 744.5334 426.6203 0.9996 … │
│ ϵ_t[58] 0.0189 0.8726 0.0358 591.1011 374.3784 0.9990 … │
│ ϵ_t[59] 0.1211 0.9472 0.0362 680.4948 397.9875 1.0072 … │
│ ϵ_t[60] 0.2234 0.9437 0.0365 678.8759 398.3738 0.9997 … │
│ ϵ_t[61] 0.3054 0.8950 0.0358 629.6084 418.6966 0.9983 … │
│ ϵ_t[62] 0.2672 0.9952 0.0382 683.4244 390.7283 0.9987 … │
│ ϵ_t[63] 0.0830 0.9294 0.0354 672.3966 424.2951 1.0000 … │
│ ϵ_t[64] 0.1138 1.0223 0.0458 468.5815 323.1316 1.0035 … │
│ ϵ_t[65] 0.0042 1.0164 0.0363 770.8517 349.8738 0.9985 … │
│ ϵ_t[66] 0.0008 0.9650 0.0390 609.6326 369.5485 0.9981 … │
│ ϵ_t[67] 0.0391 1.0448 0.0356 851.4229 374.2049 1.0016 … │
│ ϵ_t[68] -0.0719 1.0216 0.0341 886.1598 428.3560 0.9986 … │
│ init_incide… 4.6628 0.0951 0.0038 644.3478 357.4018 0.9983 … │
│ cases.clust… 0.0943 0.0204 0.0010 434.2503 244.9705 0.9990 … │
│ deaths.Asce… -4.1914 0.1012 0.0045 507.8046 254.6337 1.0010 … │
│ deaths.clus… 0.1048 0.0781 0.0032 420.5161 295.8708 1.0025 … │
╰──────────────────────────────────────────────────────────────────────────────╯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: the cases stream applies its error to the delayed expectation, and the deaths stream sits downstream, delayed again by the case-report→death interval and scaled by the fatality fraction.
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))
cascade_model = IDModel(renewal, cascade)
cas = as_turing_model(cascade_model, (cases = missing, deaths = missing), n)()(generated_y_t = (cases = Union{Missing, Int64}[270, 218, 297, 216, 337, 350, 349, 317, 345, 235 … 18, 24, 42, 36, 27, 32, 26, 28, 15, 16], deaths = Union{Missing, Int64}[missing, missing, missing, missing, missing, missing, missing, missing, missing, missing … 2, 0, 1, 1, 2, 1, 1, 0, 0, 0]), expected_y_t = (cases = [227.09297655006515, 243.34766824296463, 261.48168753785353, 278.2756274314308, 290.9627856707276, 301.28182061015445, 312.3983423411687, 324.84589430964934, 335.20267973117086, 339.2005876922202 … 31.186316265782217, 28.694989824511666, 26.44369524061574, 24.485114690631903, 22.782521197898706, 21.169716185551678, 19.462217764470903, 17.66258532039226, 15.938218082601603, 14.341444599295773], deaths = [6.438898577278827, 6.52699593084055, 6.567662962367721, 6.564000144659306, 6.517047629226355, 6.424169592255845, 6.280901953934635, 6.084810397911528, 5.838057962715189, 5.547591893051596 … 1.1520649516076356, 1.0772106846356602, 1.0106802434475657, 0.9503586772567186, 0.8943779493996293, 0.8411996384131999, 0.7896930783313525, 0.739292731336043, 0.6900632656439981, 0.6424963952669397]), I_t = [124.82023240024644, 118.78877067901828, 125.1487735449749, 134.7185804215374, 158.58527604659736, 156.77778466087597, 176.86934435498142, 184.4853794947595, 201.74499799634336, 237.88281397858518 … 20.165685555311335, 18.842248244661604, 17.723028988752468, 15.751613393207471, 12.275154235021272, 11.73102792823999, 10.622872267713365, 9.386131507924796, 7.465721130334022, 5.331369642723152], Z_t = [0.5312446389953557, 0.3423504104670212, 0.2619472009124497, 0.2309590587560234, 0.32222357859830564, 0.25145249562109956, 0.3032385726661695, 0.2704627134438929, 0.28597582344222056, 0.3785932527760605 … -0.30701422716001264, -0.2801358465279927, -0.25738877419206196, -0.3042302765638897, -0.4888920355466818, -0.46241069165440163, -0.46741840122631073, -0.4769601397674182, -0.5856294205914865, -0.8032070473681384])The Split sits after the shared case delay and before the error leaves, so the deaths stream's expected input is the delayed-and-ascertained expected cases, not the raw infections: it is both scaled by the fatality fraction and shortened by the case delay.
(cases_expected_length = length(cas.expected_y_t.cases),
deaths_expected_length = length(cas.expected_y_t.deaths),
deaths_are_a_fraction_of_cases =
sum(cas.expected_y_t.deaths) < sum(cas.expected_y_t.cases))(cases_expected_length = 55, deaths_expected_length = 38, deaths_are_a_fraction_of_cases = true)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 = 2733, old = 1504)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 = 3718, old = 1619, total = 5585)The aggregate total stream sees the summed expected infections of both bands — its expected series is exactly young .+ old.
Here the single renewal process supplied one infection stratum, broadcast through W. When the strata are genuinely separate infection processes — several distinct regions, say, 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 a shared infection curve replicated per group by a partially pooled level instead — the panel case, not several distinct processes — see GroupedInfections and Partial pooling across groups.
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).