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.025
┌ Info: Found initial step size
└   ϵ = 0.0125
┌ Info: Found initial step size
└   ϵ = 0.00625
┌ 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/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 5 divergent transitions. Consider reparameterising your model or using a smaller step size. For adaptive samplers such as NUTS and HMCDA, consider increasing `target_accept`.
└ @ Turing.Inference ~/.julia/packages/Turing/4sXd9/src/mcmc/hmc.jl:483
┌ Warning: There were 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 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 20 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

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  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.0312  0.1976  0.0059  1127.2130  577.8214  1.0018  …      │
│        init[2]   0.2941  0.1357  0.0045   889.8416  963.9832  1.0039  …      │
│        damp[1]   0.7897  0.0428  0.0015   801.4896  773.1527  1.0022  …      │
│        damp[2]   0.0891  0.0390  0.0012   911.3080  490.5608  1.0004  …      │
│            std   0.0703  0.0298  0.0013   545.0376  744.6797  1.0015  …      │
│         ϵ_t[1]   0.4169  0.9560  0.0292  1068.7674  657.6783  1.0026  …      │
│         ϵ_t[2]   0.3802  0.9381  0.0261  1290.9751  878.5280  1.0015  …      │
│         ϵ_t[3]   0.4385  0.9679  0.0278  1230.5764  670.8929  1.0010  …      │
│         ϵ_t[4]   0.3549  0.9959  0.0269  1350.7626  784.9236  0.9995  …      │
│         ϵ_t[5]   0.2715  0.9854  0.0283  1226.3736  755.5872  1.0020  …      │
│         ϵ_t[6]   0.1953  0.9779  0.0260  1436.2952  710.7882  0.9991  …      │
│         ϵ_t[7]   0.1666  0.9990  0.0258  1495.4679  835.4673  1.0070  …      │
│         ϵ_t[8]   0.1494  1.0271  0.0308  1117.5526  767.6360  1.0035  …      │
│         ϵ_t[9]   0.1088  1.0038  0.0257  1521.7526  563.6450  0.9994  …      │
│        ϵ_t[10]   0.0011  0.9755  0.0281  1200.7520  634.0382  1.0080  …      │
│        ϵ_t[11]  -0.1238  0.9770  0.0275  1269.8430  677.9194  0.9997  …      │
│        ϵ_t[12]  -0.1410  0.9332  0.0281  1093.6777  695.6964  1.0019  …      │
│        ϵ_t[13]  -0.1724  0.9968  0.0240  1709.5595  600.7115  0.9995  …      │
│        ϵ_t[14]  -0.1671  0.9517  0.0255  1399.9846  646.8239  1.0007  …      │
│        ϵ_t[15]  -0.1404  0.9411  0.0261  1308.7754  569.3061  1.0021  …      │
│        ϵ_t[16]  -0.1706  0.9753  0.0248  1557.5368  738.9525  0.9992  …      │
│        ϵ_t[17]  -0.1206  0.9411  0.0255  1382.2962  597.9713  0.9994  …      │
│        ϵ_t[18]  -0.1427  0.9515  0.0285  1117.7639  570.5559  1.0013  …      │
│        ϵ_t[19]  -0.1603  0.9385  0.0257  1338.3461  785.8980  1.0015  …      │
│        ϵ_t[20]  -0.0632  0.9536  0.0263  1345.7687  579.5341  0.9998  …      │
│        ϵ_t[21]  -0.1790  1.0007  0.0264  1418.7807  628.1641  1.0067  …      │
│        ϵ_t[22]  -0.2307  0.9804  0.0239  1690.7036  629.6763  0.9998  …      │
│        ϵ_t[23]  -0.2668  0.9114  0.0253  1296.9434  843.5736  1.0021  …      │
│        ϵ_t[24]  -0.3124  0.9590  0.0271  1286.9799  679.4965  1.0031  …      │
│        ϵ_t[25]  -0.2689  0.9616  0.0250  1481.2779  898.2763  1.0006  …      │
│        ϵ_t[26]  -0.2083  1.0115  0.0281  1298.7021  697.0083  1.0013  …      │
│        ϵ_t[27]  -0.2408  0.9606  0.0274  1225.2250  688.9930  0.9993  …      │
│        ϵ_t[28]  -0.3025  0.9679  0.0288  1152.1084  617.7654  0.9999  …      │
│        ϵ_t[29]  -0.3346  0.9662  0.0233  1571.6879  705.9028  0.9990  …      │
│        ϵ_t[30]  -0.3575  0.9423  0.0245  1476.6402  767.7336  1.0002  …      │
│        ϵ_t[31]  -0.2802  1.0255  0.0311  1262.6374  556.6010  0.9991  …      │
│        ϵ_t[32]  -0.3341  0.9556  0.0256  1366.5011  736.5419  1.0067  …      │
│        ϵ_t[33]  -0.3868  0.9387  0.0262  1292.2572  651.4141  1.0023  …      │
│        ϵ_t[34]  -0.4517  0.9250  0.0238  1528.2559  844.5899  0.9993  …      │
│        ϵ_t[35]  -0.4282  0.9073  0.0252  1299.8254  793.0973  0.9993  …      │
│        ϵ_t[36]  -0.4150  0.9251  0.0277  1101.9173  654.4549  1.0012  …      │
│        ϵ_t[37]  -0.2317  0.9598  0.0250  1461.2540  907.7013  1.0006  …      │
│        ϵ_t[38]  -0.1349  0.9707  0.0253  1475.3243  570.5176  1.0023  …      │
│        ϵ_t[39]  -0.0543  0.9890  0.0252  1538.6770  809.1238  0.9993  …      │
│        ϵ_t[40]   0.0922  0.9488  0.0250  1441.1376  709.5762  0.9998  …      │
│        ϵ_t[41]   0.2228  0.9104  0.0239  1431.4232  905.5232  0.9995  …      │
│        ϵ_t[42]   0.3279  0.9552  0.0277  1166.6558  683.1035  1.0032  …      │
│        ϵ_t[43]   0.4247  0.9454  0.0276  1194.9183  756.6521  1.0001  …      │
│        ϵ_t[44]   0.4737  0.9284  0.0248  1421.8246  456.5060  1.0001  …      │
│        ϵ_t[45]   0.3472  0.9173  0.0267  1180.2258  743.4487  1.0017  …      │
│        ϵ_t[46]   0.2795  0.9942  0.0253  1564.8734  660.0767  1.0054  …      │
│        ϵ_t[47]   0.2002  0.9626  0.0252  1494.8119  718.8779  0.9994  …      │
│        ϵ_t[48]   0.2867  1.0299  0.0270  1469.8045  679.3456  0.9993  …      │
│        ϵ_t[49]   0.3146  0.9534  0.0281  1154.9638  785.8980  1.0006  …      │
│        ϵ_t[50]   0.3605  0.9715  0.0293  1094.4896  679.1482  1.0006  …      │
│        ϵ_t[51]   0.3981  0.9016  0.0241  1405.0840  872.8882  1.0012  …      │
│        ϵ_t[52]   0.2927  0.9583  0.0277  1213.3493  678.5899  1.0014  …      │
│        ϵ_t[53]   0.1375  0.9458  0.0248  1433.9268  790.8805  0.9993  …      │
│        ϵ_t[54]  -0.0235  0.9989  0.0269  1371.4853  618.2343  1.0017  …      │
│        ϵ_t[55]  -0.0852  1.0072  0.0260  1482.2072  689.2627  0.9995  …      │
│        ϵ_t[56]  -0.0757  0.9229  0.0276  1120.2503  661.0658  1.0021  …      │
│        ϵ_t[57]  -0.1213  0.9171  0.0263  1215.4784  740.6951  1.0000  …      │
│        ϵ_t[58]  -0.0023  0.9543  0.0270  1232.4542  819.5146  0.9995  …      │
│        ϵ_t[59]   0.1648  0.9440  0.0245  1492.5497  745.5694  1.0002  …      │
│        ϵ_t[60]   0.2286  0.9610  0.0264  1341.7978  604.8106  1.0006  …      │
│        ϵ_t[61]   0.2170  0.9670  0.0259  1390.4680  534.0687  1.0033  …      │
│        ϵ_t[62]   0.2179  0.9483  0.0239  1578.6915  645.4776  1.0016  …      │
│        ϵ_t[63]   0.1125  0.9947  0.0274  1321.5486  720.5976  1.0008  …      │
│        ϵ_t[64]   0.0952  1.0317  0.0288  1257.1241  738.0266  1.0028  …      │
│        ϵ_t[65]  -0.0101  1.0230  0.0269  1443.3472  768.4978  0.9991  …      │
│        ϵ_t[66]  -0.0020  0.9919  0.0263  1423.6353  561.4009  0.9998  …      │
│        ϵ_t[67]   0.0040  1.0131  0.0284  1245.4663  726.3208  1.0026  …      │
│        ϵ_t[68]   0.0413  1.0209  0.0285  1283.2441  534.3843  0.9990  …      │
│   init_incide…   4.6617  0.1002  0.0035   818.4278  532.2620  0.9995  …      │
│   cases.clust…   0.0935  0.0198  0.0007   846.8558  690.6421  1.0002  …      │
│   deaths.Asce…  -4.1861  0.1027  0.0033  1002.9586  667.6912  1.0018  …      │
│   deaths.clus…   0.1046  0.0806  0.0024   614.6377  273.3758  1.0007  …      │
╰──────────────────────────────────────────────────────────────────────────────╯

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}[76, 72, 60, 69, 66, 71, 62, 46, 46, 50  …  61, 82, 63, 61, 76, 68, 84, 90, 86, 86], deaths = Union{Missing, Int64}[missing, missing, missing, missing, missing, missing, missing, missing, missing, missing  …  1, 3, 0, 2, 0, 1, 3, 1, 1, 1]), expected_y_t = (cases = [75.53059845577076, 72.44929725908295, 69.92288327324468, 67.95719680096136, 66.23523286089522, 64.42851736453831, 62.49544408093108, 60.47576001981976, 58.18250975128724, 55.980231209181426  …  64.63232837947915, 66.88221842964651, 69.59856713167973, 72.4695311197853, 75.39665393344198, 78.68832044145, 82.8346591507756, 88.88308678615209, 96.72087893974384, 104.97289041883072], deaths = [1.178497060321164, 1.1407977091182842, 1.1053536824055297, 1.071938289122182, 1.0404586455237261, 1.0116915367183719, 0.9874223037358283, 0.9697770693161261, 0.960226697324335, 0.9589120767728494  …  1.089858873114468, 1.0983089769499856, 1.1109245375189378, 1.1278410634210507, 1.148525252384327, 1.1723448357899462, 1.1991294408795437, 1.2292772287703064, 1.2634772367736475, 1.3023457786428807]), I_t = [113.30421443691378, 106.82968869917647, 106.18237385570397, 112.15670832320137, 92.94825873829538, 92.57431980561839, 82.7041194465945, 87.80794116051, 71.9785627876843, 85.39007765551665  …  81.807600552076, 81.17677723596945, 85.86204133897627, 92.89058733268088, 98.58007449113917, 125.76289301812933, 127.23451353757879, 131.68647258400281, 138.83188030260231, 146.43831325605967], Z_t = [0.17259244977107174, 0.06970139686157353, 0.022542067915055593, 0.04971034951598992, -0.1490756066790227, -0.15443781883360352, -0.2510687657770778, -0.15220429564275473, -0.29738249331586714, -0.07166464912115547  …  0.19879069380148912, 0.15019044422228722, 0.1588521599312567, 0.19279721594984672, 0.21178553278647555, 0.4095317467611087, 0.362061148891969, 0.3090814741046563, 0.26077230897298154, 0.22655433567418015])

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 = 3818, old = 2089)

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 = 2595, old = 1172, total = 3853)

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.0015625
┌ Info: Found initial step size
└   ϵ = 4.8828125e-5
┌ Warning: There were 115 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 13 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 128 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

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  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.0533  0.1341  0.0278  334.4891   26.4487  2.4620  …       │
│        init[2]  -0.1271  0.0590  0.0346    3.4581   28.6452  2.2916  …       │
│        damp[1]   0.7829  0.0298  0.0040  120.8181   40.2327  2.4620  …       │
│        damp[2]   0.4353  0.3410  0.3375    1.2314       NaN  2.4620  …       │
│            std   0.0742  0.0662  0.0656    1.2678       NaN  2.4328  …       │
│         ϵ_t[1]   0.7910  1.0237  0.8433    1.8519   24.0768  2.2916  …       │
│         ϵ_t[2]  -0.6684  1.0417  0.7620    2.0331   42.3223  2.2916  …       │
│         ϵ_t[3]   0.4355  0.8738  0.5553    3.2756   35.7641  2.2916  …       │
│         ϵ_t[4]  -0.7113  0.9383  0.7609    1.6608   11.7031  2.4620  …       │
│         ϵ_t[5]   0.0871  0.6826  0.0345  346.4496   37.3388  2.4620  …       │
│         ϵ_t[6]  -0.8072  1.0441  0.8303    1.7674    1.4546  2.2916  …       │
│         ϵ_t[7]  -0.2318  0.7983  0.1394  219.3628   27.3336  2.4620  …       │
│         ϵ_t[8]   0.6349  0.9047  0.6414    2.6824   34.7500  2.2916  …       │
│         ϵ_t[9]   0.6315  0.8950  0.6917    1.9459   28.0057  2.2916  …       │
│        ϵ_t[10]  -0.2365  0.7353  0.1685  331.4545   23.8562  2.4620  …       │
│        ϵ_t[11]  -0.3251  0.7208  0.3740   13.8161   52.5757  2.4620  …       │
│        ϵ_t[12]   0.8004  1.0454  0.8338    1.9329   30.1022  2.2916  …       │
│        ϵ_t[13]   0.8720  1.1916  1.0303    1.4366   33.9533  2.2916  …       │
│        ϵ_t[14]   0.0426  0.7252  0.0341  362.2749   25.6309  2.4620  …       │
│        ϵ_t[15]   0.2839  0.7901  0.4373    4.7197   26.8222  2.4620  …       │
│        ϵ_t[16]   0.6623  1.1761  0.9987    1.4611   25.3163  2.2916  …       │
│        ϵ_t[17]  -0.3302  0.7334  0.2111   48.4169   22.0563  2.4620  …       │
│        ϵ_t[18]  -0.9174  0.9215  0.7466    1.7056    1.4311  2.2916  …       │
│        ϵ_t[19]  -0.2458  0.6884  0.0311  280.8451   28.1511  2.4620  …       │
│        ϵ_t[20]  -0.2534  0.7253  0.0292  450.2633   35.5182  2.4620  …       │
│        ϵ_t[21]   0.2725  0.7911  0.4319    5.7766   28.0198  2.4620  …       │
│        ϵ_t[22]  -0.9366  1.1180  0.9408    1.6595    1.4085  2.2916  …       │
│        ϵ_t[23]  -0.0822  0.7153  0.0276  491.3797   24.7931  2.4620  …       │
│        ϵ_t[24]  -0.0853  0.7426  0.0344  400.0443   20.2648  2.4620  …       │
│        ϵ_t[25]   0.4186  0.8546  0.5709    2.6788   21.9694  2.4620  …       │
│        ϵ_t[26]   0.9478  1.2036  1.0741    1.3463   25.6498  2.2916  …       │
│        ϵ_t[27]  -0.3629  0.7199  0.3696    4.1774   27.3252  2.4620  …       │
│        ϵ_t[28]  -0.9231  1.1798  0.9935    1.5362    1.3764  2.2916  …       │
│        ϵ_t[29]  -0.4443  0.9028  0.4156    7.4860   27.3539  2.4620  …       │
│        ϵ_t[30]  -0.2816  0.7994  0.3924    6.9880   24.7333  2.4620  …       │
│        ϵ_t[31]   0.9555  1.1476  1.0231    1.3506   41.9024  2.2916  …       │
│        ϵ_t[32]   0.4918  0.9257  0.6269    2.8427   41.1899  2.2916  …       │
│        ϵ_t[33]   0.0276  0.6155  0.0250  457.4934   31.4550  2.4620  …       │
│        ϵ_t[34]   0.0440  0.7386  0.0377  219.9130   22.8347  2.4620  …       │
│        ϵ_t[35]   0.3049  0.6823  0.2733   17.4012   35.8544  2.4620  …       │
│        ϵ_t[36]   0.5698  0.8952  0.6938    1.9827   27.1211  2.4620  …       │
│        ϵ_t[37]   0.0386  0.7036  0.0302  451.6206   34.7152  2.4620  …       │
│        ϵ_t[38]  -0.9317  1.0594  0.9185    1.3820    7.1742  2.4620  …       │
│        ϵ_t[39]  -0.0245  0.6725  0.0336  379.9781   23.7321  2.4620  …       │
│        ϵ_t[40]  -0.4966  0.8583  0.5866    2.8976   23.3143  2.4620  …       │
│        ϵ_t[41]  -0.3273  0.7859  0.3719    6.7663   48.6509  2.4620  …       │
│        ϵ_t[42]  -0.7094  1.0396  0.8314    2.0205   28.5576  2.4620  …       │
│        ϵ_t[43]   0.6000  0.9018  0.5687    2.9778   22.5676  2.4620  …       │
│        ϵ_t[44]  -0.3112  0.7400  0.3937    6.5334   37.4754  2.4620  …       │
│        ϵ_t[45]   0.5698  0.8732  0.5618    2.2451   42.9092  2.4620  …       │
│        ϵ_t[46]  -0.7188  1.1291  0.9830    1.4557    1.3455  2.2916  …       │
│        ϵ_t[47]   1.0408  1.1384  0.9358    1.5588   34.8877  2.4620  …       │
│        ϵ_t[48]   0.2814  0.6124  0.0306  308.1362   28.7718  2.4620  …       │
│        ϵ_t[49]   0.6118  0.8277  0.5435    2.8457   34.4132  2.4620  …       │
│        ϵ_t[50]   0.2147  0.6958  0.0952  148.3108   27.8624  2.4620  …       │
│        ϵ_t[51]  -0.6931  0.9400  0.7727    1.6900   12.1316  2.4620  …       │
│        ϵ_t[52]  -0.6434  0.9048  0.6945    1.9033   14.3231  2.4620  …       │
│        ϵ_t[53]  -0.3911  0.6992  0.3584    5.7891   32.7163  2.4620  …       │
│        ϵ_t[54]   0.5582  0.8046  0.4532    5.5923   20.5028  2.4620  …       │
│        ϵ_t[55]  -0.4594  0.8516  0.6465    1.8980    1.4900  2.2916  …       │
│        ϵ_t[56]  -0.5848  0.8934  0.7246    1.8388    1.4663  2.2916  …       │
│        ϵ_t[57]   0.6137  0.8618  0.5514    2.9887   28.0136  2.2916  …       │
│        ϵ_t[58]  -0.8736  1.1572  0.9907    1.4035    1.3258  2.2916  …       │
│        ϵ_t[59]  -0.9698  1.2441  1.1032    1.2586    1.2791  2.3201  …       │
│        ϵ_t[60]   0.4297  0.8293  0.5624    2.9256   19.1204  2.4620  …       │
│        ϵ_t[61]   0.1087  0.7233  0.0646  225.5944   32.2354  2.4620  …       │
│        ϵ_t[62]  -0.3598  0.7125  0.4261    4.5775   43.3768  2.4620  …       │
│        ϵ_t[63]  -0.0894  0.7012  0.0324  401.9320   31.1354  2.4620  …       │
│        ϵ_t[64]   0.5280  0.8422  0.6103    2.1336   28.0399  2.2916  …       │
│        ϵ_t[65]   0.7775  1.1545  0.9771    1.4836   22.4896  2.2916  …       │
│        ϵ_t[66]   0.2816  0.7458  0.3275    9.6922   29.4872  2.4620  …       │
│        ϵ_t[67]  -0.4567  0.8062  0.5478    2.8833   25.8418  2.2916  …       │
│        ϵ_t[68]   0.7771  1.1124  0.9318    1.4989   41.0708  2.2916  …       │
│   init_incide…   1.6945  2.8920  2.8684    1.2632    5.6456  2.4328  …       │
╰──────────────────────────────────────────────────────────────────────────────╯

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