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 [ DocumenterCitations.CitationSiteNode("sherratt2021surveillance-cite-2")
]. 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 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 (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 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: 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 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, 4; progress = false)┌ Info: Found initial step size
└ ϵ = 0.025
┌ Info: Found initial step size
└ ϵ = 0.025
┌ Info: Found initial step size
└ ϵ = 0.00625
┌ Info: Found initial step size
└ ϵ = 0.0125
┌ Warning: There were 7 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 7 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 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/WteH7/src/mcmc/hmc.jl:483
┌ Warning: There were 9 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 27 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 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], 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.0227 0.2059 0.0060 1198.2576 580.8964 1.0005 … │
│ init[2] 0.3007 0.1438 0.0040 1253.4481 767.4709 1.0023 … │
│ damp[1] 0.7899 0.0440 0.0014 1037.6380 742.5488 0.9993 … │
│ damp[2] 0.0893 0.0431 0.0018 527.2352 399.8928 1.0079 … │
│ std 0.0689 0.0286 0.0011 680.7109 679.6304 1.0000 … │
│ ϵ_t[1] 0.4177 1.0161 0.0265 1461.5955 583.2867 1.0014 … │
│ ϵ_t[2] 0.4016 0.9374 0.0262 1269.8485 543.3719 0.9996 … │
│ ϵ_t[3] 0.3612 1.0382 0.0265 1535.0783 657.0691 1.0000 … │
│ ϵ_t[4] 0.3242 0.9975 0.0249 1610.3401 587.8216 1.0034 … │
│ ϵ_t[5] 0.2311 1.0242 0.0271 1427.1727 754.4636 1.0002 … │
│ ϵ_t[6] 0.2167 0.9652 0.0235 1675.2520 906.1256 1.0012 … │
│ ϵ_t[7] 0.1685 0.9813 0.0266 1367.0891 814.3606 0.9995 … │
│ ϵ_t[8] 0.1326 1.0230 0.0275 1375.4358 548.8957 1.0008 … │
│ ϵ_t[9] 0.0491 1.0693 0.0267 1609.6242 728.6964 1.0062 … │
│ ϵ_t[10] 0.0237 1.0055 0.0254 1567.8553 640.9748 1.0027 … │
│ ϵ_t[11] -0.0991 0.9741 0.0327 887.8038 743.1139 0.9993 … │
│ ϵ_t[12] -0.1734 1.0220 0.0241 1789.8501 750.9943 1.0032 … │
│ ϵ_t[13] -0.1528 0.9641 0.0288 1107.5604 613.6660 1.0001 … │
│ ϵ_t[14] -0.1775 1.0220 0.0284 1297.9461 766.6262 1.0017 … │
│ ϵ_t[15] -0.1412 0.9807 0.0254 1499.9538 767.2566 1.0006 … │
│ ϵ_t[16] -0.1445 0.9458 0.0219 1820.8486 533.8022 1.0052 … │
│ ϵ_t[17] -0.1448 0.9889 0.0287 1161.9020 447.8845 1.0061 … │
│ ϵ_t[18] -0.1617 0.9107 0.0215 1796.3634 712.6278 1.0017 … │
│ ϵ_t[19] -0.1444 0.9733 0.0265 1324.8450 720.1504 1.0010 … │
│ ϵ_t[20] -0.1296 0.9647 0.0252 1468.7685 728.6893 0.9994 … │
│ ϵ_t[21] -0.1084 0.9930 0.0249 1633.2275 646.8067 1.0018 … │
│ ϵ_t[22] -0.2307 0.9605 0.0264 1322.9351 918.0346 1.0012 … │
│ ϵ_t[23] -0.3294 0.9512 0.0241 1553.8037 820.5636 1.0018 … │
│ ϵ_t[24] -0.3480 0.9517 0.0254 1419.4621 740.1128 1.0011 … │
│ ϵ_t[25] -0.2807 0.9605 0.0239 1621.3827 750.2714 0.9992 … │
│ ϵ_t[26] -0.1833 0.9562 0.0249 1477.1882 642.2523 1.0019 … │
│ ϵ_t[27] -0.2220 0.9761 0.0244 1543.6757 728.4672 1.0000 … │
│ ϵ_t[28] -0.3085 0.8974 0.0270 1107.2829 669.7796 1.0010 … │
│ ϵ_t[29] -0.3159 0.9585 0.0256 1412.8421 778.8563 1.0063 … │
│ ϵ_t[30] -0.3197 0.9857 0.0266 1377.6055 583.2867 0.9990 … │
│ ϵ_t[31] -0.3039 0.9360 0.0227 1701.0322 667.9714 1.0029 … │
│ ϵ_t[32] -0.3714 0.9711 0.0223 1865.9072 624.4842 0.9995 … │
│ ϵ_t[33] -0.3266 0.9356 0.0245 1448.1296 545.1375 1.0053 … │
│ ϵ_t[34] -0.4299 0.9644 0.0234 1672.5835 680.3712 1.0009 … │
│ ϵ_t[35] -0.4866 0.9082 0.0259 1222.3995 566.8387 0.9994 … │
│ ϵ_t[36] -0.3846 0.9084 0.0232 1552.0502 685.0658 1.0015 … │
│ ϵ_t[37] -0.2455 0.9522 0.0224 1796.2423 720.8847 0.9993 … │
│ ϵ_t[38] -0.1435 0.9428 0.0257 1348.7756 835.2785 1.0003 … │
│ ϵ_t[39] -0.0187 0.9070 0.0230 1541.4863 403.7302 1.0016 … │
│ ϵ_t[40] 0.0836 0.9798 0.0285 1185.0927 633.8346 0.9998 … │
│ ϵ_t[41] 0.1948 0.9153 0.0242 1423.2565 647.7097 0.9990 … │
│ ϵ_t[42] 0.3085 0.8945 0.0209 1839.4273 666.6075 1.0025 … │
│ ϵ_t[43] 0.4323 0.8505 0.0235 1291.2984 794.1873 0.9994 … │
│ ϵ_t[44] 0.4704 0.9038 0.0241 1412.3056 661.0597 1.0052 … │
│ ϵ_t[45] 0.3955 0.9685 0.0282 1181.6288 741.3550 1.0007 … │
│ ϵ_t[46] 0.2611 0.9727 0.0242 1615.5251 665.2838 1.0014 … │
│ ϵ_t[47] 0.2526 0.9295 0.0233 1585.0804 763.1982 1.0030 … │
│ ϵ_t[48] 0.2973 0.9494 0.0244 1511.9999 761.6719 0.9996 … │
│ ϵ_t[49] 0.2975 0.9293 0.0236 1559.0241 657.1710 0.9997 … │
│ ϵ_t[50] 0.3288 0.9672 0.0236 1616.1347 472.3442 1.0031 … │
│ ϵ_t[51] 0.3606 0.9140 0.0235 1544.3203 618.9382 1.0011 … │
│ ϵ_t[52] 0.2575 0.9165 0.0237 1484.7529 373.2091 1.0085 … │
│ ϵ_t[53] 0.1803 0.9970 0.0280 1281.9403 677.9194 1.0010 … │
│ ϵ_t[54] 0.0021 0.9885 0.0291 1146.0114 522.9763 1.0020 … │
│ ϵ_t[55] -0.0572 0.9769 0.0250 1512.6955 685.8843 0.9992 … │
│ ϵ_t[56] -0.1175 0.9677 0.0230 1751.9837 702.6811 1.0036 … │
│ ϵ_t[57] -0.1033 0.9440 0.0265 1273.3356 715.1011 1.0087 … │
│ ϵ_t[58] 0.0309 0.9856 0.0274 1311.6247 677.9046 0.9990 … │
│ ϵ_t[59] 0.1198 0.9513 0.0246 1527.8503 840.7347 0.9991 … │
│ ϵ_t[60] 0.2160 0.9734 0.0238 1673.5593 852.3965 0.9990 … │
│ ϵ_t[61] 0.3256 0.9828 0.0263 1397.6647 645.7115 0.9993 … │
│ ϵ_t[62] 0.2060 1.0098 0.0254 1580.6167 667.7908 1.0006 … │
│ ϵ_t[63] 0.1193 0.9785 0.0250 1550.6051 812.2976 1.0001 … │
│ ϵ_t[64] 0.0895 1.0207 0.0234 2123.0194 624.1918 1.0013 … │
│ ϵ_t[65] 0.0579 1.0002 0.0272 1374.5386 687.2600 0.9994 … │
│ ϵ_t[66] -0.0133 1.0191 0.0284 1289.7502 746.1424 1.0008 … │
│ ϵ_t[67] 0.0236 1.0142 0.0302 1116.7505 472.1464 1.0014 … │
│ ϵ_t[68] -0.0137 1.0843 0.0264 1673.4759 539.0298 1.0066 … │
│ init_incide… 4.6586 0.0962 0.0032 907.2991 651.4771 1.0057 … │
│ cases.clust… 0.0925 0.0209 0.0008 736.7655 418.7672 0.9995 … │
│ deaths.Asce… -4.1927 0.0998 0.0031 1007.9276 709.3554 0.9991 … │
│ deaths.clus… 0.1046 0.0806 0.0022 517.3914 230.8190 1.0000 … │
╰──────────────────────────────────────────────────────────────────────────────╯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)
cases_bands = predictive_bands(pred, n, i -> @varname(cases.y_t[i]))
deaths_bands = predictive_bands(pred, n, i -> @varname(deaths.y_t[i]))
fig = Figure(; size = (760, 620))
ax1 = Axis(fig[1, 1]; ylabel = "Cases")
ci_ribbon!(ax1, 1:n, cases_bands; color = :teal,
label = "posterior predictive")
scatter!(ax1, 1:n, y.cases; color = :black, markersize = 6,
label = "simulated")
axislegend(ax1; position = :lt)
ax2 = Axis(fig[2, 1]; xlabel = "Day", ylabel = "Deaths")
ci_ribbon!(ax2, 1:n, deaths_bands; color = :firebrick,
label = "posterior predictive")
scatter!(ax2, 1:n, 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: 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}[221, 300, 364, 459, 587, 672, 796, 966, 1161, 1243 … 413561, 502997, 519343, 745459, 781827, 1042968, 1164933, 1498731, 1442432, 1698714], deaths = Union{Missing, Int64}[missing, missing, missing, missing, missing, missing, missing, missing, missing, missing … 1292, 1808, 1970, 2438, 3212, 4737, 5300, 5406, 7354, 7796]), expected_y_t = (cases = [259.14551858410283, 302.5314632108998, 362.0839444713968, 440.4568191965176, 529.3823132648952, 629.5514787644402, 764.4271197323013, 933.0651641774323, 1123.6945045747957, 1321.672530479016 … 392267.733308067, 455080.96403242124, 531221.0302610882, 626172.7545284253, 736264.0327889898, 871755.2729537727, 1.0486941629198566e6, 1.2745589160074168e6, 1.5455688944717413e6, 1.8864942274538926e6], deaths = [22.600608162440896, 26.481335042441753, 30.81806643406608, 35.574533954698, 40.678778832124756, 46.05438349905974, 51.65003108871018, 57.456029359371634, 63.523441564085154, 70.00377857112882 … 1304.8275552111322, 1670.2429377720728, 2123.853746664651, 2668.7637402057353, 3304.3288923129026, 4029.885961782183, 4848.960691301729, 5773.138307490052, 6824.912205472526, 8038.201090931774]), I_t = [118.31973250644974, 198.27514344593808, 132.4755645390774, 177.1985893618629, 180.2389717998761, 153.6850457384318, 166.3429065167771, 178.036291602577, 190.74102594173877, 253.3382046620325 … 909861.1389812249, 1.0309755105911415e6, 1.1261212325141171e6, 1.5109486595455597e6, 1.8448750294267156e6, 2.311628194056436e6, 2.5114220856328104e6, 3.6468156204897743e6, 3.7843204849980283e6, 3.8676734880504357e6], Z_t = [-0.12371941581418021, 0.4234359095965231, 0.03352544218757464, 0.276710650002005, 0.22387757112331438, 0.007500347775375976, 0.03653888875340648, 0.07669840121131183, 0.13843980007112072, 0.4106426794968514 … 0.654180788529853, 0.6362215692440747, 0.5689634515824465, 0.694014845847364, 0.7292309298980832, 0.7802828620502114, 0.6688101255006356, 0.8383897464335003, 0.6779770141263308, 0.4975192256060734])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 = 2824, old = 1407)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 = 3896, old = 1701, total = 5893)The aggregate total stream sees the summed expected infections of both bands — 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.003125
┌ Info: Found initial step size
└ ϵ = 9.765625e-5
┌ Warning: There were 8 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 3 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 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: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 (74) ── 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], 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.0227 0.2040 0.0094 463.3727 363.5771 0.9985 … │
│ init[2] 0.0606 0.0896 0.0051 284.1899 462.0680 0.9990 … │
│ damp[1] 0.7849 0.0450 0.0020 491.1634 373.3434 0.9986 … │
│ damp[2] 0.0904 0.0449 0.0035 148.3199 68.5874 1.0077 … │
│ std 0.0286 0.0130 0.0007 332.5988 301.1084 1.0080 … │
│ ϵ_t[1] -0.0040 1.0490 0.0871 142.6313 201.3633 0.9981 … │
│ ϵ_t[2] 0.1224 1.0083 0.0941 118.1568 150.9706 0.9998 … │
│ ϵ_t[3] 0.1067 1.0535 0.0841 160.2240 270.9822 1.0018 … │
│ ϵ_t[4] 0.0851 1.0257 0.0724 203.7056 331.5127 1.0058 … │
│ ϵ_t[5] 0.0385 0.9630 0.0847 126.7014 213.9815 1.0093 … │
│ ϵ_t[6] -0.0102 1.0283 0.0890 132.5187 197.2492 1.0001 … │
│ ϵ_t[7] 0.1128 0.9792 0.0721 180.4906 163.7426 1.0099 … │
│ ϵ_t[8] 0.2659 0.9525 0.0645 217.2508 254.8606 1.0033 … │
│ ϵ_t[9] 0.1317 0.9851 0.0756 169.1896 238.5836 0.9981 … │
│ ϵ_t[10] 0.3618 0.9422 0.0706 177.7146 325.3525 1.0109 … │
│ ϵ_t[11] 0.2288 0.9211 0.0607 233.9358 182.4880 1.0011 … │
│ ϵ_t[12] 0.0437 1.0147 0.0757 178.3727 256.1445 1.0148 … │
│ ϵ_t[13] 0.1833 1.0128 0.0935 117.4951 197.2280 1.0105 … │
│ ϵ_t[14] 0.1478 0.9570 0.0640 225.6374 223.2972 0.9995 … │
│ ϵ_t[15] 0.0382 0.9579 0.0707 181.4874 266.3765 1.0037 … │
│ ϵ_t[16] -0.0655 0.9524 0.0765 152.7083 272.8495 1.0237 … │
│ ϵ_t[17] -0.0707 0.9529 0.0759 158.1635 201.4842 1.0152 … │
│ ϵ_t[18] -0.0403 1.0151 0.0755 190.3370 144.7541 1.0045 … │
│ ϵ_t[19] -0.1847 0.9040 0.0668 188.2259 227.2449 1.0208 … │
│ ϵ_t[20] -0.4296 0.9849 0.0782 162.9074 270.6605 0.9996 … │
│ ϵ_t[21] -0.3122 0.9348 0.0604 240.9694 223.1377 1.0127 … │
│ ϵ_t[22] -0.4005 0.8988 0.0690 172.5172 183.6561 1.0158 … │
│ ϵ_t[23] -0.4086 0.9592 0.0646 222.4435 277.0060 1.0021 … │
│ ϵ_t[24] -0.4467 0.9335 0.0698 177.4611 223.7115 1.0013 … │
│ ϵ_t[25] -0.3985 0.9737 0.0702 197.8795 142.1666 1.0022 … │
│ ϵ_t[26] -0.2965 0.9434 0.0702 182.8022 311.8315 1.0038 … │
│ ϵ_t[27] -0.3319 0.9829 0.0674 212.7274 239.2827 1.0052 … │
│ ϵ_t[28] -0.2048 0.9944 0.0708 196.4512 177.3018 0.9986 … │
│ ϵ_t[29] -0.3409 1.0048 0.0694 209.8236 225.4092 0.9993 … │
│ ϵ_t[30] -0.1546 0.9055 0.0580 240.5564 287.6882 1.0155 … │
│ ϵ_t[31] -0.0381 0.9393 0.0812 134.2339 231.6244 1.0001 … │
│ ϵ_t[32] -0.0723 0.9794 0.0638 236.7164 287.6539 1.0100 … │
│ ϵ_t[33] -0.0427 0.8579 0.0536 257.3685 278.9418 1.0014 … │
│ ϵ_t[34] -0.0423 0.8901 0.0660 175.0876 270.6605 1.0036 … │
│ ϵ_t[35] 0.0593 0.9467 0.0705 181.7434 219.4168 1.0096 … │
│ ϵ_t[36] -0.0581 0.9559 0.0668 203.5557 328.4725 1.0099 … │
│ ϵ_t[37] 0.0143 1.0076 0.0729 192.7617 221.1253 0.9982 … │
│ ϵ_t[38] -0.0782 1.0075 0.0748 182.0045 248.9146 1.0009 … │
│ ϵ_t[39] -0.0438 0.9177 0.0665 192.6053 200.8921 1.0176 … │
│ ϵ_t[40] -0.2146 0.8992 0.0647 189.8042 272.7294 1.0005 … │
│ ϵ_t[41] -0.2497 0.9429 0.0658 199.0135 270.6605 0.9997 … │
│ ϵ_t[42] -0.3811 1.0374 0.0811 163.2556 295.3635 1.0007 … │
│ ϵ_t[43] -0.4853 0.9875 0.0715 191.3600 213.3787 0.9998 … │
│ ϵ_t[44] -0.5239 1.0256 0.0828 154.4153 266.9761 1.0017 … │
│ ϵ_t[45] -0.5409 0.9699 0.0580 279.9382 285.2636 1.0015 … │
│ ϵ_t[46] -0.4494 0.9233 0.0693 176.3605 255.2036 0.9998 … │
│ ϵ_t[47] -0.3353 0.9465 0.0600 251.7732 260.2579 1.0002 … │
│ ϵ_t[48] -0.3868 0.8688 0.0538 266.9945 330.8633 1.0007 … │
│ ϵ_t[49] -0.2828 1.0088 0.0909 125.8648 188.0083 1.0089 … │
│ ϵ_t[50] -0.2608 0.9454 0.0651 209.1133 351.9539 1.0054 … │
│ ϵ_t[51] -0.2575 0.8914 0.0662 185.0228 231.1533 1.0227 … │
│ ϵ_t[52] -0.2143 0.9548 0.0692 197.1432 188.3307 0.9991 … │
│ ϵ_t[53] -0.0823 0.9670 0.0688 199.2521 289.0001 1.0075 … │
│ ϵ_t[54] 0.0201 1.0030 0.0884 136.6327 148.8147 1.0263 … │
│ ϵ_t[55] -0.0390 0.9316 0.0616 227.7271 278.7395 1.0073 … │
│ ϵ_t[56] -0.0722 0.9685 0.0693 189.3916 311.9060 1.0159 … │
│ ϵ_t[57] -0.0696 0.8653 0.0554 245.3553 282.7785 0.9991 … │
│ ϵ_t[58] 0.0216 0.9719 0.0702 192.8102 262.6967 1.0018 … │
│ ϵ_t[59] 0.0236 0.9230 0.0644 206.9390 282.8092 0.9993 … │
│ ϵ_t[60] -0.0343 0.9345 0.0656 195.1515 314.9978 1.0001 … │
│ ϵ_t[61] -0.0840 0.9055 0.0680 176.6999 248.9146 1.0002 … │
│ ϵ_t[62] -0.1182 0.9729 0.0803 160.2822 201.9894 1.0096 … │
│ ϵ_t[63] -0.3118 0.9757 0.0783 155.7332 138.8440 1.0104 … │
│ ϵ_t[64] -0.1029 0.9543 0.0602 250.8946 279.5625 1.0011 … │
│ ϵ_t[65] -0.2050 0.9652 0.0712 180.9532 313.9324 1.0046 … │
│ ϵ_t[66] 0.0440 0.9815 0.0731 180.4781 268.0032 1.0013 … │
│ ϵ_t[67] 0.0812 1.0208 0.0922 121.7157 181.6305 1.0012 … │
│ ϵ_t[68] 0.0348 1.0019 0.0725 191.7569 262.6781 0.9987 … │
│ init_incide… 4.6060 0.0957 0.0042 519.7594 436.0858 0.9996 … │
╰──────────────────────────────────────────────────────────────────────────────╯Posterior-predictive bands per stream, plotted against the simulated counts, show whether the shared infection process and the W weights together recover each stratum — including total, which is nowhere in the infection process itself, 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, not merely simulated. A single shared young and old need no independent signal of their own, and total — a stream the infection process never draws directly — still lands on its simulated series because W ties it to the same shared path. Split(template, W) many-to-one aggregation is not just forward-simulated here, it is fit and recovered.
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 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).