Skip to content

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.

julia
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: Intercept

The composed model assembles the renewal infection process and the two-stream observation model exactly like a single-stream study.

julia
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: Intercept

Passing 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.

julia
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).

julia
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.0125
┌ Info: Found initial step size
└   ϵ = 0.025
┌ Info: Found initial step size
└   ϵ = 0.00625
┌ Warning: There were 14 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 2 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 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 24 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

The 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 process; the sparse death stream is observed jointly rather than fit in isolation.

julia
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.0313  0.1919  0.0060  1057.2579  678.0658  1.0055  …      │
│     ar_init[2]   0.3025  0.1387  0.0046   900.7807  948.4357  1.0039  …      │
│     damp_AR[1]   0.7889  0.0446  0.0014  1063.8178  790.5099  1.0003  …      │
│     damp_AR[2]   0.0888  0.0422  0.0015   779.4113  627.9240  1.0049  …      │
│            std   0.0673  0.0288  0.0013   531.4613  849.9177  1.0124  …      │
│         ϵ_t[1]   0.4138  0.9513  0.0255  1382.5241  733.2219  0.9992  …      │
│         ϵ_t[2]   0.4181  1.0505  0.0292  1274.6781  760.7764  1.0024  …      │
│         ϵ_t[3]   0.3375  1.0141  0.0326   973.0411  731.1606  1.0066  …      │
│         ϵ_t[4]   0.3604  0.9699  0.0264  1359.9161  642.5146  1.0004  …      │
│         ϵ_t[5]   0.2523  0.9647  0.0287  1125.3162  638.8158  1.0002  …      │
│         ϵ_t[6]   0.2272  1.0128  0.0280  1325.2563  539.3352  1.0002  …      │
│         ϵ_t[7]   0.1688  1.1035  0.0292  1467.9360  742.3334  0.9998  …      │
│         ϵ_t[8]   0.0611  0.9845  0.0265  1361.8615  672.1448  0.9991  …      │
│         ϵ_t[9]   0.0996  1.0204  0.0292  1235.8168  724.6634  0.9994  …      │
│        ϵ_t[10]  -0.0225  0.9464  0.0272  1234.7844  742.3334  0.9995  …      │
│        ϵ_t[11]  -0.1070  0.9916  0.0265  1401.5964  694.8675  1.0004  …      │
│        ϵ_t[12]  -0.1474  1.0115  0.0268  1418.1949  681.9454  0.9991  …      │
│        ϵ_t[13]  -0.1875  0.9266  0.0253  1328.5189  598.5099  1.0011  …      │
│        ϵ_t[14]  -0.1202  0.9455  0.0260  1345.5672  605.4873  1.0045  …      │
│        ϵ_t[15]  -0.0838  0.9417  0.0264  1272.2568  637.4544  1.0011  …      │
│        ϵ_t[16]  -0.1587  0.9926  0.0278  1249.6822  899.6495  1.0010  …      │
│        ϵ_t[17]  -0.1548  0.9970  0.0290  1184.1123  593.3069  0.9996  …      │
│        ϵ_t[18]  -0.1705  0.9195  0.0257  1303.7022  758.4323  1.0020  …      │
│        ϵ_t[19]  -0.1462  0.9286  0.0231  1569.5769  848.7930  1.0035  …      │
│        ϵ_t[20]  -0.1642  1.0037  0.0302  1099.1335  691.3815  1.0009  …      │
│        ϵ_t[21]  -0.1299  0.9816  0.0288  1165.5310  696.2342  0.9992  …      │
│        ϵ_t[22]  -0.2083  0.9791  0.0283  1210.2773  682.7818  1.0006  …      │
│        ϵ_t[23]  -0.2731  0.9570  0.0256  1364.4246  765.2233  1.0047  …      │
│        ϵ_t[24]  -0.3200  0.9452  0.0239  1606.8942  558.7803  0.9999  …      │
│        ϵ_t[25]  -0.2778  0.9544  0.0283  1145.8356  742.3869  1.0002  …      │
│        ϵ_t[26]  -0.2583  0.9680  0.0277  1236.2507  592.8344  1.0044  …      │
│        ϵ_t[27]  -0.2380  0.9436  0.0269  1228.2835  644.1833  1.0000  …      │
│        ϵ_t[28]  -0.2504  0.9290  0.0262  1264.4395  525.5291  1.0007  …      │
│        ϵ_t[29]  -0.3242  0.9804  0.0271  1300.9582  743.7114  0.9998  …      │
│        ϵ_t[30]  -0.3677  0.9880  0.0284  1209.7731  592.8392  0.9995  …      │
│        ϵ_t[31]  -0.3777  0.9580  0.0254  1416.2652  698.4211  1.0023  …      │
│        ϵ_t[32]  -0.3684  0.9624  0.0255  1427.2808  579.3455  1.0004  …      │
│        ϵ_t[33]  -0.3686  0.9334  0.0270  1196.2696  765.2233  1.0046  …      │
│        ϵ_t[34]  -0.4318  1.0106  0.0279  1292.9683  695.1290  0.9992  …      │
│        ϵ_t[35]  -0.4884  0.9251  0.0286  1035.6160  647.1466  0.9998  …      │
│        ϵ_t[36]  -0.3977  0.9686  0.0243  1560.3753  845.3572  0.9991  …      │
│        ϵ_t[37]  -0.2430  0.9612  0.0304  1022.5991  543.2634  0.9990  …      │
│        ϵ_t[38]  -0.1444  0.9066  0.0278  1064.9688  748.1699  1.0004  …      │
│        ϵ_t[39]  -0.0147  1.0198  0.0282  1301.5166  704.3689  1.0016  …      │
│        ϵ_t[40]   0.1047  0.9866  0.0274  1311.2270  589.2542  0.9999  …      │
│        ϵ_t[41]   0.1954  0.9260  0.0282  1091.1772  608.1145  0.9997  …      │
│        ϵ_t[42]   0.2939  0.9731  0.0251  1496.9968  735.3889  0.9991  …      │
│        ϵ_t[43]   0.4236  0.9864  0.0301  1081.0791  595.5720  1.0005  …      │
│        ϵ_t[44]   0.4733  0.9553  0.0280  1161.1624  676.3202  1.0003  …      │
│        ϵ_t[45]   0.4118  0.9751  0.0269  1334.1593  643.5395  1.0026  …      │
│        ϵ_t[46]   0.2713  0.8982  0.0243  1362.9018  765.0269  1.0021  …      │
│        ϵ_t[47]   0.2282  0.9483  0.0272  1216.6848  696.2342  1.0004  …      │
│        ϵ_t[48]   0.2633  0.9553  0.0286  1126.0744  504.2653  1.0010  …      │
│        ϵ_t[49]   0.3154  0.8939  0.0286   976.3778  583.9306  1.0018  …      │
│        ϵ_t[50]   0.3277  0.9992  0.0273  1335.6960  717.7478  0.9994  …      │
│        ϵ_t[51]   0.3287  0.9564  0.0256  1401.3326  594.6697  1.0085  …      │
│        ϵ_t[52]   0.3033  0.9760  0.0257  1467.8331  659.3239  0.9991  …      │
│        ϵ_t[53]   0.1578  0.9176  0.0276  1090.0951  613.4144  0.9992  …      │
│        ϵ_t[54]   0.0074  0.9385  0.0266  1269.3886  601.7201  1.0020  …      │
│        ϵ_t[55]  -0.0013  0.9267  0.0282  1086.1605  779.4365  1.0036  …      │
│        ϵ_t[56]  -0.0754  0.9597  0.0264  1322.5275  734.3954  1.0002  …      │
│        ϵ_t[57]  -0.0582  0.9847  0.0278  1246.0810  566.6709  1.0000  …      │
│        ϵ_t[58]  -0.0049  0.9315  0.0260  1294.4487  757.8008  0.9992  …      │
│        ϵ_t[59]   0.1443  0.9752  0.0239  1654.5489  864.5422  0.9996  …      │
│        ϵ_t[60]   0.2428  0.9472  0.0294  1033.6271  699.6500  1.0012  …      │
│        ϵ_t[61]   0.2779  0.9750  0.0255  1435.9072  599.9956  1.0045  …      │
│        ϵ_t[62]   0.2356  0.9343  0.0238  1552.0618  762.7390  0.9994  …      │
│        ϵ_t[63]   0.0883  0.9791  0.0285  1171.3885  695.6665  1.0015  …      │
│        ϵ_t[64]   0.1077  1.0358  0.0278  1384.7093  635.7852  1.0001  …      │
│        ϵ_t[65]   0.0794  0.9594  0.0260  1347.4620  537.4728  0.9999  …      │
│        ϵ_t[66]   0.0091  0.9561  0.0258  1390.2073  679.8215  1.0012  …      │
│        ϵ_t[67]   0.0563  0.9791  0.0274  1283.1670  908.0965  1.0020  …      │
│        ϵ_t[68]   0.0231  1.0157  0.0271  1415.7095  591.4356  0.9995  …      │
│   init_incide…   4.6675  0.1021  0.0032   997.1552  757.8693  0.9999  …      │
│   cases.clust…   0.0954  0.0194  0.0006   883.2531  707.7849  0.9992  …      │
│   deaths.Asce…  -4.1985  0.1082  0.0035   949.6544  847.0356  1.0063  …      │
│   deaths.clus…   0.1054  0.0747  0.0022   757.5677  360.6878  1.0009  …      │
╰──────────────────────────────────────────────────────────────────────────────╯

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:

julia
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   , and it needs no new construct and no mode flag — it is the same 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.

julia
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}[383, 347, 329, 451, 768, 830, 897, 964, 799, 763  …  400, 390, 461, 418, 501, 480, 436, 491, 489, 577], deaths = Union{Missing, Int64}[missing, missing, missing, missing, missing, missing, missing, missing, missing, missing  …  17, 13, 5, 9, 9, 16, 12, 9, 5, 6]), expected_y_t = (cases = [341.32112110262716, 429.9990305186735, 538.2276990828364, 658.0046748504053, 776.8208764466424, 875.3341540211184, 939.7459953275818, 961.578826788701, 946.8274017951913, 915.2720800238344  …  418.47638906131294, 406.6674264079493, 407.54640993789894, 418.7117599053456, 439.2615480926819, 458.6839060807428, 475.5177182721477, 494.578485095735, 509.98717050154136, 519.7878240666469], deaths = [17.45940001077574, 17.41476068461592, 17.110536176968928, 16.6008154627586, 15.939744031979686, 15.181161878637347, 14.373439604499701, 13.551354439158839, 12.735127646508479, 11.937103287302696  …  12.146038722581077, 12.33339299862937, 12.333503729118796, 12.134101881623742, 11.752949820350999, 11.237223502058319, 10.654255872976861, 10.076382173998951, 9.568625728534132, 9.179945290735745]), I_t = [97.97293105845748, 57.04727261295996, 68.18099391181457, 150.94205352186108, 97.47643643707784, 106.12507877313858, 123.19132816787018, 173.8184472204117, 209.7543239361092, 236.02620844146676  …  430.7346391397248, 519.7112580209885, 556.629831695347, 460.884563853548, 554.9405443433717, 606.7665187431021, 483.17369788648364, 541.4827297762813, 681.3287596243031, 655.7955812435926], Z_t = [0.44898914273945834, -0.20886285285331585, -0.12954567893214824, 0.6362234719021933, 0.20920672386192235, 0.2188246983273437, 0.24924087807322978, 0.5185704799829001, 0.6464694826588746, 0.6532707224828829  …  0.1591275385013124, 0.32324024074152513, 0.33797698138820187, 0.07419251587301773, 0.17997632591976104, 0.21602699770237976, -0.047448596898510526, 0.02894315866526606, 0.2374394570657639, 0.1912491842890154])

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.

julia
(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.

julia
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 = 9230, old = 5203)

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:

julia
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 = 9738, old = 4209, total = 13794)

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.

julia
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.05
┌ Info: Found initial step size
└   ϵ = 9.094947017729283e-14
┌ 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/WteH7/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/WteH7/src/mcmc/hmc.jl:483

young, old, and total are not three independent counts: total is exactly young + old, so all three read the same one-stratum path through fixed, unequal weights rather than each pinning it independently. That collinearity makes the innovations mix more slowly than the two-stream parallel fit above — worth knowing before trusting any one tutorial's diagnostics at face value:

julia
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  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                          │
│                                                                              │
│ 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.2378  0.2978  0.2712    1.4402   24.5805  2.1274  …       │
│     ar_init[2]   0.4549  0.5543  0.5442    1.3194   10.8746  2.1263  …       │
│     damp_AR[1]   0.5584  0.2744  0.2713    1.3322   10.8746  2.1263  …       │
│     damp_AR[2]   0.3440  0.2240  0.2213    1.3202   10.8746  2.1263  …       │
│            std   0.7012  0.5914  0.5865    1.3188   10.8746  2.1263  …       │
│         ϵ_t[1]  -0.5812  0.7849  0.6620    1.4991   30.7343  2.1263  …       │
│         ϵ_t[2]  -0.6240  0.7346  0.2194   10.2778   24.9266  2.1274  …       │
│         ϵ_t[3]  -0.1531  0.9275  0.3922    7.6482   15.3647  2.1263  …       │
│         ϵ_t[4]  -0.2363  0.6608  0.4343    3.4588   34.4189  2.1263  …       │
│         ϵ_t[5]  -1.1425  0.8319  0.4879    3.9278   19.0737  2.1274  …       │
│         ϵ_t[6]   0.0891  0.4951  0.1448   24.9537   32.4580  2.1263  …       │
│         ϵ_t[7]   0.6839  0.4727  0.0853   26.0893   16.5521  2.1274  …       │
│         ϵ_t[8]   0.5591  0.7089  0.4972    2.7358   39.0760  2.1263  …       │
│         ϵ_t[9]  -0.6038  0.6363  0.1608   15.1001   16.5547  2.1263  …       │
│        ϵ_t[10]  -0.3605  0.5475  0.1167   21.6815   15.4628  2.1263  …       │
│        ϵ_t[11]   0.0424  0.8363  0.2915    8.8265   13.2276  2.1263  …       │
│        ϵ_t[12]   0.0896  0.8359  0.6218    2.3457   25.4524  2.1263  …       │
│        ϵ_t[13]  -0.6536  0.6674  0.5510    1.5067   32.5437  2.1274  …       │
│        ϵ_t[14]  -0.3614  0.7592  0.6344    1.4941   24.9326  2.1148  …       │
│        ϵ_t[15]  -0.6154  0.9605  0.6941    2.8351   12.6977  2.1274  …       │
│        ϵ_t[16]  -0.5571  0.7710  0.1481   32.2998   16.9663  2.1274  …       │
│        ϵ_t[17]   1.1628  0.9941  0.7686    1.8709   27.6260  2.1274  …       │
│        ϵ_t[18]   0.3055  0.6159  0.4410    1.8722   37.3625  2.1274  …       │
│        ϵ_t[19]   0.2085  0.8772  0.7226    1.6927   48.7788  2.1274  …       │
│        ϵ_t[20]  -0.7156  1.0046  0.8111    1.8072   37.1778  2.1274  …       │
│        ϵ_t[21]   0.6930  0.7589  0.6136    1.6121   26.1422  2.1274  …       │
│        ϵ_t[22]  -0.6807  0.5791  0.1904   13.0544   57.6907  2.1263  …       │
│        ϵ_t[23]   1.3123  0.7625  0.5949    2.3099   20.3136  2.1274  …       │
│        ϵ_t[24]   0.2940  0.8938  0.6467    2.6505   37.7794  2.1274  …       │
│        ϵ_t[25]  -0.1905  0.7734  0.6208    1.6876   36.3253  2.1263  …       │
│        ϵ_t[26]  -0.1194  0.5783  0.1085   26.0603   25.6278  2.1106  …       │
│        ϵ_t[27]   0.6887  0.6360  0.2300   20.3073   37.2283  2.1274  …       │
│        ϵ_t[28]   0.6228  0.5361  0.1757   24.7812   47.7696  2.1134  …       │
│        ϵ_t[29]  -0.3192  1.5106  1.3089    1.4277   21.2984  2.1274  …       │
│        ϵ_t[30]  -0.2425  1.3977  1.3485    1.3222   10.8746  2.1263  …       │
│        ϵ_t[31]  -0.5762  1.5956  1.4612    1.3191   10.8746  2.1263  …       │
│        ϵ_t[32]   0.4777  0.8604  0.6297    2.5343   14.7393  2.1274  …       │
│        ϵ_t[33]   0.6337  0.8409  0.2303   14.0622   21.9270  2.1134  …       │
│        ϵ_t[34]  -0.1975  1.1890  1.1018    1.3475   12.8450  2.1263  …       │
│        ϵ_t[35]   1.2086  1.0007  0.7061    2.0434   21.8310  2.1263  …       │
│        ϵ_t[36]   1.0796  0.9307  0.5588    3.7768   23.6151  2.1274  …       │
│        ϵ_t[37]  -0.0822  0.6514  0.4253    3.3149   15.4011  2.1263  …       │
│        ϵ_t[38]  -0.7167  1.0091  0.8371    2.0239   25.3018  2.1263  …       │
│        ϵ_t[39]   0.4726  0.8386  0.6773    1.6794   39.5762  2.1274  …       │
│        ϵ_t[40]   0.9384  0.7442  0.2628   14.8321   16.2864  2.1263  …       │
│        ϵ_t[41]   0.5967  1.0155  0.8865    1.5597   23.6469  2.1274  …       │
│        ϵ_t[42]   0.3061  0.8905  0.8263    1.3179   10.8746  2.1263  …       │
│        ϵ_t[43]   0.4817  0.7069  0.4296    3.4116   54.2416  2.1274  …       │
│        ϵ_t[44]  -0.6758  0.7890  0.6020    1.8846   31.7168  2.1263  …       │
│        ϵ_t[45]  -0.2980  0.5308  0.2391   10.7952   27.0728  2.1067  …       │
│        ϵ_t[46]   0.3255  0.7413  0.2807    9.4721   30.8400  2.1274  …       │
│        ϵ_t[47]   0.7263  0.6558  0.4843    2.0291   41.1942  2.0877  …       │
│        ϵ_t[48]   0.3246  0.6189  0.4066    2.2764   27.5704  2.1274  …       │
│        ϵ_t[49]   0.6041  1.1973  1.1272    1.3184   10.8746  2.1263  …       │
│        ϵ_t[50]  -0.0667  0.7361  0.5389    2.0792   37.1413  2.1238  …       │
│        ϵ_t[51]   0.3731  1.2802  1.2064    1.3193   10.8746  2.1263  …       │
│        ϵ_t[52]  -0.9818  0.7852  0.3605    4.1394   20.4563  2.1263  …       │
│        ϵ_t[53]   0.7867  1.2462  1.1545    1.3195   10.8746  2.1263  …       │
│        ϵ_t[54]   0.3341  0.5912  0.1477   15.6709   17.6685  2.1274  …       │
│        ϵ_t[55]  -0.5215  0.7987  0.6902    1.6664   15.5776  2.1274  …       │
│        ϵ_t[56]   1.2129  0.6357  0.1374   21.8753   12.7152  2.1265  …       │
│        ϵ_t[57]   0.2421  0.6769  0.3813    5.0387   21.6086  2.1263  …       │
│        ϵ_t[58]  -0.6253  0.7521  0.5824    1.8646   43.7091  2.1274  …       │
│        ϵ_t[59]   0.3340  0.5049  0.1066   23.5607   40.5532  2.1263  …       │
│        ϵ_t[60]   0.2761  0.9506  0.8793    1.3209   10.8746  2.1263  …       │
│        ϵ_t[61]  -0.4143  0.4850  0.1003   29.3589   35.6431  2.1274  …       │
│        ϵ_t[62]  -0.3486  0.4768  0.0915   27.3260   28.3015  2.1274  …       │
│        ϵ_t[63]   0.9110  0.4675  0.3846    1.7280   20.8225  2.1274  …       │
│        ϵ_t[64]   1.0364  0.5501  0.1435   12.7899   17.3724  2.1263  …       │
│        ϵ_t[65]   1.0470  0.7703  0.2460   12.1133   22.4758  2.1265  …       │
│        ϵ_t[66]   0.1925  0.7008  0.2002   12.7858   28.7281  2.1274  …       │
│        ϵ_t[67]   0.7246  1.2837  1.1730    1.3243   10.8746  2.1263  …       │
│        ϵ_t[68]   0.9390  0.9108  0.4337    7.3615   20.5094  2.1274  …       │
│   init_incide…   2.1416  2.4609  2.4405    1.3115   10.8746  2.1263  …       │
╰──────────────────────────────────────────────────────────────────────────────╯

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:

julia
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 path, read through three collinear weighted views of it, is enough to pin that path: 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 ​

  1. 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).