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 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
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: 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 4 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 1 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: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[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], ϵ_t[69], ϵ_t[70], ϵ_t[71], ϵ_t[72], ϵ_t[73], ϵ_t[74], │
│ ϵ_t[75], ϵ_t[76], ϵ_t[77], ϵ_t[78], ϵ_t[79], ϵ_t[80], ϵ_t[81], │
│ ϵ_t[82], ϵ_t[83], ϵ_t[84], ϵ_t[85], ϵ_t[86], ϵ_t[87], ϵ_t[88], │
│ ϵ_t[89], ϵ_t[90], ϵ_t[91], ϵ_t[92], ϵ_t[93], ϵ_t[94], ϵ_t[95], │
│ ϵ_t[96], ϵ_t[97], ϵ_t[98], ϵ_t[99], ϵ_t[100], ϵ_t[101], ϵ_t[102], │
│ ϵ_t[103], ϵ_t[104], ϵ_t[105], ϵ_t[106], ϵ_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 mcse ess_bulk ess_tail rhat … │
│ init[1] -0.0013 0.2036 0.0092 494.9262 274.7515 0.9987 … │
│ init[2] 0.2779 0.1440 0.0063 503.4938 322.7647 0.9983 … │
│ damp[1] 0.7877 0.0438 0.0017 697.5355 472.1835 0.9990 … │
│ damp[2] 0.0881 0.0397 0.0017 512.5994 205.7317 0.9994 … │
│ std 0.0710 0.0260 0.0012 384.8138 392.3959 1.0070 … │
│ ϵ_t[1] 0.4951 0.9624 0.0441 471.1979 319.7528 1.0015 … │
│ ϵ_t[2] 0.4110 0.9889 0.0443 487.6173 458.2825 1.0040 … │
│ ϵ_t[3] 0.4067 0.9798 0.0473 427.5624 282.9033 1.0001 … │
│ ϵ_t[4] 0.3386 0.9847 0.0460 464.7590 301.6340 0.9993 … │
│ ϵ_t[5] 0.3763 0.9215 0.0428 458.1129 367.4394 1.0002 … │
│ ϵ_t[6] 0.3088 1.0251 0.0441 547.8347 271.6760 1.0031 … │
│ ϵ_t[7] 0.3661 0.9016 0.0429 433.4091 359.2774 1.0064 … │
│ ϵ_t[8] 0.3127 1.0187 0.0437 558.0876 402.8850 1.0001 … │
│ ϵ_t[9] 0.2622 0.9779 0.0525 357.0334 372.9939 1.0021 … │
│ ϵ_t[10] 0.2366 0.9827 0.0406 580.9020 342.8555 0.9987 … │
│ ϵ_t[11] 0.1736 1.0077 0.0434 540.3375 348.7163 1.0030 … │
│ ϵ_t[12] 0.0355 0.9484 0.0541 305.0989 372.2645 0.9999 … │
│ ϵ_t[13] 0.0432 0.9738 0.0414 597.0369 199.5295 0.9986 … │
│ ϵ_t[14] -0.0209 1.0113 0.0435 547.7332 405.8768 0.9996 … │
│ ϵ_t[15] -0.1175 0.9732 0.0407 578.7883 429.7968 0.9997 … │
│ ϵ_t[16] -0.1329 0.9412 0.0427 488.1046 269.5773 1.0005 … │
│ ϵ_t[17] -0.2512 0.9464 0.0476 398.4702 343.0167 0.9998 … │
│ ϵ_t[18] -0.1606 0.9878 0.0433 566.2923 406.3628 1.0020 … │
│ ϵ_t[19] -0.1396 1.0104 0.0497 415.4504 141.6960 1.0103 … │
│ ϵ_t[20] -0.2425 0.9636 0.0483 389.2802 299.0191 1.0004 … │
│ ϵ_t[21] -0.2749 1.0239 0.0462 495.9256 374.3784 0.9985 … │
│ ϵ_t[22] -0.3412 0.9708 0.0451 469.8528 307.9416 1.0010 … │
│ ϵ_t[23] -0.2232 0.9214 0.0467 394.6824 353.1196 1.0010 … │
│ ϵ_t[24] -0.1381 0.9843 0.0455 460.8040 363.5387 0.9986 … │
│ ϵ_t[25] -0.2316 0.9981 0.0453 484.2379 299.6594 0.9990 … │
│ ϵ_t[26] -0.2202 0.9377 0.0381 588.1152 338.1784 0.9983 … │
│ ϵ_t[27] -0.1764 0.9851 0.0411 563.0517 397.1099 0.9994 … │
│ ϵ_t[28] -0.3242 0.9503 0.0399 550.4047 309.9413 0.9990 … │
│ ϵ_t[29] -0.2435 0.9440 0.0502 351.6576 306.4249 1.0012 … │
│ ϵ_t[30] -0.2833 1.0405 0.0516 461.4874 255.7551 0.9986 … │
│ ϵ_t[31] -0.3138 0.9960 0.0464 462.3091 326.0769 0.9995 … │
│ ϵ_t[32] -0.3409 0.9356 0.0396 560.6949 428.7079 0.9991 … │
│ ϵ_t[33] -0.4841 0.9188 0.0375 609.0363 381.4196 0.9983 … │
│ ϵ_t[34] -0.3333 0.9713 0.0428 524.9851 316.5341 1.0010 … │
│ ϵ_t[35] -0.2743 0.9726 0.0481 420.2325 274.0306 1.0030 … │
│ ϵ_t[36] -0.2247 0.9367 0.0464 403.5123 461.6350 0.9992 … │
│ ϵ_t[37] -0.1564 0.9089 0.0438 424.4359 347.5764 1.0040 … │
│ ϵ_t[38] -0.0329 0.9752 0.0491 408.1079 263.0038 1.0064 … │
│ ϵ_t[39] -0.0281 1.0641 0.0511 448.6384 226.6411 0.9983 … │
│ ϵ_t[40] 0.0628 0.9748 0.0408 557.8004 322.9116 0.9988 … │
│ ϵ_t[41] 0.1644 0.9249 0.0563 260.8206 279.1092 1.0023 … │
│ ϵ_t[42] 0.2081 1.0803 0.0508 471.9068 138.5410 1.0106 … │
│ ϵ_t[43] 0.2652 0.9357 0.0423 500.6395 346.5598 0.9990 … │
│ ϵ_t[44] 0.1851 0.9320 0.0449 443.2110 400.7875 1.0024 … │
│ ϵ_t[45] 0.1894 0.9214 0.0393 557.7264 418.6966 1.0067 … │
│ ϵ_t[46] 0.0938 0.8696 0.0397 477.5305 346.0410 1.0014 … │
│ ϵ_t[47] 0.2006 0.9349 0.0402 533.1695 358.9981 0.9989 … │
│ ϵ_t[48] 0.2067 0.8826 0.0382 533.8804 367.4984 1.0021 … │
│ ϵ_t[49] 0.2876 0.9403 0.0466 429.3987 188.1479 1.0026 … │
│ ϵ_t[50] 0.2667 0.9268 0.0415 507.9063 338.0755 1.0043 … │
│ ϵ_t[51] 0.1376 0.9790 0.0427 526.8577 453.8363 0.9996 … │
│ ϵ_t[52] 0.0775 0.9558 0.0420 526.8967 420.1011 0.9993 … │
│ ϵ_t[53] 0.0691 0.9757 0.0403 587.1797 397.9938 0.9994 … │
│ ϵ_t[54] -0.0405 0.9382 0.0499 357.5848 320.8168 1.0048 … │
│ ϵ_t[55] 0.1557 1.0746 0.0510 448.8754 381.4196 1.0044 … │
│ ϵ_t[56] -0.0079 0.9905 0.0439 513.7551 348.5526 1.0004 … │
│ ϵ_t[57] 0.0908 0.9965 0.0500 402.4963 286.0614 1.0100 … │
│ ϵ_t[58] 0.1970 0.9485 0.0422 500.0898 407.5449 1.0009 … │
│ ϵ_t[59] 0.1062 0.9691 0.0443 472.6596 292.4802 1.0019 … │
│ ϵ_t[60] -0.0175 0.9769 0.0528 355.2604 326.1723 0.9992 … │
│ ϵ_t[61] -0.0633 0.9036 0.0366 608.5306 294.6978 1.0026 … │
│ ϵ_t[62] -0.1280 0.9279 0.0420 476.5551 432.7666 0.9999 … │
│ ϵ_t[63] -0.1627 0.9483 0.0436 465.2186 408.3394 0.9996 … │
│ ϵ_t[64] -0.0888 0.9055 0.0383 556.7416 307.5556 1.0064 … │
│ ϵ_t[65] -0.0848 0.9510 0.0444 458.1286 382.0824 0.9997 … │
│ ϵ_t[66] -0.0330 1.0146 0.0418 588.5874 338.0755 1.0114 … │
│ ϵ_t[67] 0.1266 0.9668 0.0560 297.2368 291.4485 1.0027 … │
│ ϵ_t[68] 0.2589 1.0495 0.0465 528.5104 254.2073 1.0015 … │
│ ϵ_t[69] 0.4020 1.0203 0.0489 444.0920 294.0999 1.0242 … │
│ ϵ_t[70] 0.4635 0.9768 0.0419 559.9303 470.5002 1.0127 … │
│ ϵ_t[71] 0.4537 0.9649 0.0499 367.7013 353.1196 1.0003 … │
│ ϵ_t[72] 0.4715 0.8953 0.0439 410.0809 374.3784 1.0045 … │
│ ϵ_t[73] 0.4372 1.0218 0.0458 494.6813 368.0397 0.9993 … │
│ ϵ_t[74] 0.3564 0.9478 0.0354 707.2042 223.6439 1.0238 … │
│ ϵ_t[75] 0.2416 0.9597 0.0476 411.9718 335.5171 1.0015 … │
│ ϵ_t[76] 0.1312 0.8954 0.0363 609.7587 397.1099 1.0010 … │
│ ϵ_t[77] 0.0712 0.9514 0.0508 349.7236 366.5422 1.0002 … │
│ ϵ_t[78] 0.1935 0.9778 0.0457 437.4028 403.9293 1.0054 … │
│ ϵ_t[79] 0.2501 0.9536 0.0428 487.1742 304.0568 1.0035 … │
│ ϵ_t[80] 0.2582 0.9702 0.0420 543.3152 371.6207 1.0006 … │
│ ϵ_t[81] 0.3997 0.9398 0.0403 542.7843 333.2991 1.0022 … │
│ ϵ_t[82] 0.4210 0.9346 0.0418 499.5761 272.0414 0.9981 … │
│ ϵ_t[83] 0.3703 1.0451 0.0508 423.0876 285.2636 1.0033 … │
│ ϵ_t[84] 0.3537 0.9167 0.0390 545.9185 408.7387 0.9980 … │
│ ϵ_t[85] 0.2570 0.9496 0.0431 485.9301 270.1779 0.9992 … │
│ ϵ_t[86] 0.2105 1.0006 0.0558 331.6689 267.5656 1.0029 … │
│ ϵ_t[87] 0.1033 0.9762 0.0515 352.6720 212.4289 1.0009 … │
│ ϵ_t[88] 0.0260 1.0061 0.0507 391.1297 299.0191 1.0050 … │
│ ϵ_t[89] -0.0937 0.9761 0.0496 384.2995 361.4108 1.0032 … │
│ ϵ_t[90] -0.0553 0.9466 0.0447 450.3302 374.3784 1.0029 … │
│ ϵ_t[91] -0.2994 0.9771 0.0419 559.6986 326.9978 0.9992 … │
│ ϵ_t[92] -0.3974 0.9751 0.0425 541.8667 308.5591 1.0025 … │
│ ϵ_t[93] -0.4145 0.9238 0.0467 394.1804 259.1674 1.0067 … │
│ ϵ_t[94] -0.4426 0.9757 0.0478 411.5339 236.6707 1.0028 … │
│ ϵ_t[95] -0.3757 0.9780 0.0420 537.2189 415.6823 1.0055 … │
│ ϵ_t[96] -0.2552 0.9079 0.0333 735.0722 348.6833 0.9993 … │
│ ϵ_t[97] -0.2741 0.9170 0.0395 535.9830 428.3560 0.9999 … │
│ ϵ_t[98] -0.3362 0.9977 0.0436 542.8649 258.4465 1.0024 … │
│ ϵ_t[99] -0.1201 1.0282 0.0437 541.9932 297.0342 1.0094 … │
│ ϵ_t[100] -0.0719 0.9401 0.0414 514.5566 331.9867 0.9989 … │
│ ϵ_t[101] 0.0446 0.9786 0.0437 490.7066 343.0728 0.9988 … │
│ ϵ_t[102] 0.0902 0.9891 0.0404 592.3429 407.5449 1.0018 … │
│ ϵ_t[103] -0.0027 0.9184 0.0466 392.2346 337.4747 0.9991 … │
│ ϵ_t[104] 0.0682 0.8934 0.0397 499.6432 305.0328 1.0065 … │
│ ϵ_t[105] -0.0650 0.9880 0.0484 419.5799 364.0197 1.0164 … │
│ ϵ_t[106] -0.0262 1.0064 0.0486 436.9778 371.6324 1.0001 … │
│ ϵ_t[107] 0.1056 0.9645 0.0417 529.3335 312.7750 0.9987 … │
│ ϵ_t[108] 0.0233 0.9528 0.0565 318.4227 186.5034 1.0027 … │
│ ϵ_t[109] 0.0198 1.0079 0.0451 508.4420 420.1179 0.9989 … │
│ init_incide… 4.6486 0.0916 0.0044 434.9447 299.0191 1.0001 … │
│ cases.clust… 0.1867 0.0149 0.0007 476.3363 330.0444 1.0004 … │
│ deaths.Asce… -4.0816 0.0628 0.0027 530.9108 345.6327 1.0014 … │
│ deaths.clus… 0.1184 0.0858 0.0038 361.0900 184.7072 1.0019 … │
╰──────────────────────────────────────────────────────────────────────────────╯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 = 14218, old = 7495)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 = 48836, old = 20976, total = 69660)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.000390625
┌ Info: Found initial step size
└ ϵ = 1.220703125e-5young, 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[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], ϵ_t[69], ϵ_t[70], ϵ_t[71], ϵ_t[72], ϵ_t[73], ϵ_t[74], │
│ ϵ_t[75], ϵ_t[76], ϵ_t[77], ϵ_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 mcse ess_bulk ess_tail rhat … │
│ init[1] 0.1178 0.2058 0.0910 5.2090 19.2892 1.1438 … │
│ init[2] -0.0091 0.1535 0.1308 1.4590 53.8885 1.9560 … │
│ damp[1] 0.8108 0.0454 0.0172 6.5653 11.8350 1.0765 … │
│ damp[2] 0.1431 0.0527 0.0264 4.9719 13.1813 1.1373 … │
│ std 0.1129 0.0269 0.0234 1.3716 11.1187 2.0392 … │
│ ϵ_t[1] 1.0636 1.4071 1.3684 1.3628 29.8000 2.1263 … │
│ ϵ_t[2] 0.8220 0.6272 0.2242 8.0470 17.4163 1.0900 … │
│ ϵ_t[3] 1.0350 0.9061 0.7724 1.6552 14.4590 1.8474 … │
│ ϵ_t[4] 0.5609 0.6823 0.3114 4.8866 10.9735 1.1535 … │
│ ϵ_t[5] -0.3429 1.1606 1.1029 1.3856 32.9214 2.1263 … │
│ ϵ_t[6] 1.1842 0.6657 0.2342 8.7394 20.4563 1.1320 … │
│ ϵ_t[7] 1.2701 0.7479 0.6391 1.4303 25.7953 2.0436 … │
│ ϵ_t[8] -0.2826 1.0061 0.9554 1.3201 11.6193 2.1165 … │
│ ϵ_t[9] 0.5264 0.5276 0.3602 2.2498 41.0395 1.3978 … │
│ ϵ_t[10] 1.1273 0.6732 0.5675 1.5190 20.3678 1.8816 … │
│ ϵ_t[11] -0.5574 0.3876 0.2048 3.9852 44.6568 1.2269 … │
│ ϵ_t[12] -0.2276 0.5126 0.1460 17.1765 33.3347 1.4040 … │
│ ϵ_t[13] 0.6919 0.7127 0.3880 5.3781 10.8455 1.1387 … │
│ ϵ_t[14] -0.5612 0.5112 0.1286 15.5463 20.4907 1.1404 … │
│ ϵ_t[15] -0.5328 0.9484 0.8430 1.3380 12.6941 2.1084 … │
│ ϵ_t[16] 0.3340 0.8195 0.7465 1.3709 10.8996 2.1100 … │
│ ϵ_t[17] 0.5955 0.3867 0.1093 11.7206 21.5202 1.2934 … │
│ ϵ_t[18] 0.2665 0.5221 0.2527 4.9684 25.8922 1.3869 … │
│ ϵ_t[19] 1.4649 1.2599 1.1842 1.3491 21.0228 2.1263 … │
│ ϵ_t[20] -1.4129 1.0665 0.9994 1.3188 14.0079 2.1237 … │
│ ϵ_t[21] -0.6181 0.5461 0.1800 10.3458 16.2957 1.3443 … │
│ ϵ_t[22] 0.3705 0.5654 0.3284 2.6759 10.8708 1.3033 … │
│ ϵ_t[23] -0.2224 0.4469 0.1176 15.2346 12.5156 1.2679 … │
│ ϵ_t[24] 0.6342 0.4954 0.3180 2.3922 18.1498 1.3528 … │
│ ϵ_t[25] 0.7338 0.6439 0.3510 8.0525 14.6660 1.3595 … │
│ ϵ_t[26] 0.1384 0.9105 0.7545 1.3775 14.8988 2.0022 … │
│ ϵ_t[27] -0.8321 0.4881 0.3649 1.8026 23.8858 1.5966 … │
│ ϵ_t[28] 0.2984 0.7865 0.3624 4.5878 12.0648 1.1654 … │
│ ϵ_t[29] 0.5601 0.3936 0.0864 19.9727 38.8582 1.1833 … │
│ ϵ_t[30] -0.7710 0.6706 0.3736 5.2714 20.4061 1.3827 … │
│ ϵ_t[31] 0.2818 0.4980 0.1850 9.9390 11.2800 1.0850 … │
│ ϵ_t[32] -0.6321 0.5401 0.1834 9.8795 11.3956 1.1889 … │
│ ϵ_t[33] -1.2469 0.9812 0.8182 1.6854 11.5911 1.6583 … │
│ ϵ_t[34] -0.2474 0.6285 0.5502 1.3891 25.3211 2.0181 … │
│ ϵ_t[35] 0.4550 0.5567 0.3645 2.5581 15.7766 1.3599 … │
│ ϵ_t[36] 0.5222 0.6071 0.2109 8.3263 12.9519 1.2848 … │
│ ϵ_t[37] -0.3126 1.0023 0.8075 1.6514 14.3396 1.6363 … │
│ ϵ_t[38] -1.5151 0.6587 0.2657 6.8359 17.3094 1.5854 … │
│ ϵ_t[39] -0.8861 0.4732 0.1848 7.0852 50.9137 1.0759 … │
│ ϵ_t[40] -0.8087 1.1818 1.1280 1.3492 14.8953 2.1263 … │
│ ϵ_t[41] -0.2076 0.6713 0.5596 1.5073 21.8835 1.8221 … │
│ ϵ_t[42] -1.5513 0.5465 0.2664 4.0843 24.4865 1.1900 … │
│ ϵ_t[43] 0.4057 0.8130 0.7098 1.3724 17.1451 2.0876 … │
│ ϵ_t[44] -0.4305 1.5950 1.5626 1.3267 15.9509 2.1263 … │
│ ϵ_t[45] -0.2970 0.9641 0.9075 1.3309 23.6173 2.1240 … │
│ ϵ_t[46] -0.2388 0.4302 0.1468 9.6142 11.7068 1.0343 … │
│ ϵ_t[47] -0.2710 0.3418 0.0921 12.8121 37.9850 1.1282 … │
│ ϵ_t[48] -0.4135 0.4327 0.2127 4.2386 52.9678 1.1733 … │
│ ϵ_t[49] 0.0432 0.4738 0.1287 16.0998 21.7478 1.0279 … │
│ ϵ_t[50] 0.9441 0.5065 0.1781 10.4528 35.5647 1.1421 … │
│ ϵ_t[51] -0.2295 1.0635 0.9953 1.3166 10.8746 2.1263 … │
│ ϵ_t[52] -1.4010 0.6049 0.2226 7.8750 16.2584 1.4694 … │
│ ϵ_t[53] -1.9561 0.3528 0.0920 18.2731 23.7231 1.3110 … │
│ ϵ_t[54] -0.4279 0.6303 0.5639 1.3444 17.8584 2.0934 … │
│ ϵ_t[55] -0.3049 0.5681 0.2141 7.4848 31.1898 1.0918 … │
│ ϵ_t[56] -0.6006 0.5901 0.4691 1.6842 11.6017 1.6160 … │
│ ϵ_t[57] -1.1645 0.6497 0.5346 1.4195 11.2435 1.9633 … │
│ ϵ_t[58] 0.2032 0.6354 0.5112 1.6140 28.1531 1.7132 … │
│ ϵ_t[59] -0.4896 1.1971 1.1417 1.3374 11.3152 2.1263 … │
│ ϵ_t[60] 0.5155 0.5599 0.4266 1.8026 12.0849 1.5797 … │
│ ϵ_t[61] 0.2791 0.7174 0.5951 1.5579 20.7520 1.7674 … │
│ ϵ_t[62] 0.7420 0.6208 0.4341 2.0462 13.1674 1.5140 … │
│ ϵ_t[63] 0.2560 0.5434 0.4622 1.8360 66.9133 1.6074 … │
│ ϵ_t[64] 0.6217 0.4846 0.3086 2.7807 13.7473 1.3223 … │
│ ϵ_t[65] -0.2771 0.5885 0.4779 1.6164 13.4810 1.7076 … │
│ ϵ_t[66] -0.0947 0.6814 0.6065 1.3774 12.5622 1.9962 … │
│ ϵ_t[67] 0.9092 0.7567 0.5768 2.1168 11.9417 1.4090 … │
│ ϵ_t[68] 0.2650 0.6484 0.4197 2.1057 11.4352 1.4320 … │
│ ϵ_t[69] -0.1420 0.8443 0.3409 6.5104 11.2528 1.5666 … │
│ ϵ_t[70] 0.8970 0.7807 0.6841 1.3504 10.9808 2.0379 … │
│ ϵ_t[71] 0.1150 0.7349 0.6156 1.4921 24.7607 1.8641 … │
│ ϵ_t[72] 1.1177 0.5358 0.1719 10.1456 28.7860 1.0249 … │
│ ϵ_t[73] -0.3314 0.4877 0.1598 11.0285 20.4563 1.1109 … │
│ ϵ_t[74] -1.0266 0.5308 0.2822 4.2922 23.5710 1.3493 … │
│ ϵ_t[75] -0.8897 0.4335 0.1075 20.6033 20.6989 1.3257 … │
│ ϵ_t[76] -0.6345 0.3756 0.1425 10.8437 37.2183 1.1240 … │
│ ϵ_t[77] 0.2897 0.4233 0.0864 24.2913 51.5238 1.0975 … │
│ ϵ_t[78] -0.2949 1.0628 0.9770 1.3806 22.0333 2.1048 … │
│ ϵ_t[79] -0.6647 0.6258 0.1879 11.7169 23.7325 1.3643 … │
│ ϵ_t[80] 0.2798 0.6839 0.6022 1.3957 16.0616 2.0265 … │
│ ϵ_t[81] 1.0159 0.5098 0.1643 10.3520 11.2890 1.0801 … │
│ ϵ_t[82] 0.1525 0.6401 0.5357 1.4741 36.0368 1.9899 … │
│ ϵ_t[83] 0.4320 0.8269 0.3116 6.9865 15.1597 1.5624 … │
│ init_incide… 4.5788 0.0975 0.0438 4.9836 25.9224 1.1449 … │
╰──────────────────────────────────────────────────────────────────────────────╯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).