Skip to content

Tutorials

These worked examples build complete models from the package's components and fit them with Turing. Most use real epidemic surveillance data and recreate published analyses; the Gaussian-process study instead fits data simulated from the model itself, where the point is to recover a known truth. Each one is self-contained and runs when the documentation is built, so the numbers you see are produced by the code on the page.

Sampling settings

To keep the documentation build to a sensible time, these tutorials draw moderate NUTS samples (250 draws across 2 chains for the multi-chain fits, 200-300 for the single-chain ones). The target acceptance rate (adapt_delta) has been raised across these tutorials to avoid divergent transitions. That is enough to demonstrate the models and produce stable figures; a real analysis would use more draws and check convergence diagnostics carefully.

They progress from a single renewal model to a layered observation process, a mechanistic compartmental model, and a flexible Gaussian-process latent:

  • Renewal model with negative-binomial reporting — a time-varying reproduction number driven by an autoregressive latent process, mapped to infections through the renewal equation and observed with overdispersed counts. This is the canonical renewal model of Cori et al. [1] and Mishra et al. [2].

  • Reporting delays and day-of-week effects — the same renewal core wrapped in an observation model that convolves infections through reporting delays and modulates them with a day-of-week reporting pattern, in the style of real-time estimation tools [3].

  • Real-time nowcasting: correcting right-truncation — the same renewal core fit to a right-truncated real-time snapshot, contrasting a naive fit (which shows the artefactual recent- down-turn) with a RightTruncate-corrected fit that removes it, again following real-time estimation practice [3].

  • Multiple observation streams: cases, deaths, and strata — one renewal infection process observed through several named streams with a single Split construct, covering parallel streams (cases and deaths off shared infections), a cascade (deaths downstream of reported cases, achieved by placing the split lower in the pipeline), and data-driven strata (one stream per age band), motivated by the differing biases of surveillance streams [4].

  • An SIR compartmental model — an alternative infection process where dynamics come from an ordinary differential equation solved by the SciML stack [5], following the Bayesian compartmental-inference example of Chatzilena et al. [6].

  • Declarative compartmental models with Catalyst — the same SIR dynamics declared as a Catalyst.jl reaction network [7] instead of a hand-written vector field, so the ODE system and its Jacobian are generated rather than maintained by hand.

  • A Gaussian-process latent process — plugs a Hilbert-space approximate Gaussian process [8] into the renewal model as the latent process, fits it under NUTS with Mooncake, and checks it against an exact GP and against the simulated latent.

  • Time-varying damping in an AR process — the same autoregressive latent process with its damping coefficient itself allowed to vary over time, so the amount of mean reversion in is learned rather than fixed.

  • Partial pooling across groups — a panel of groups sharing one infection process structure but with group-level parameters drawn from a common population distribution, so information is pooled across groups without forcing them to be identical.

  • Renewal modifiers: depletion and importation — one delayed renewal process compared against the same process extended with SusceptibleDepletion and ImportedCases, so each modifier's contribution is visible against a shared baseline.

Every example uses the same recipe: assemble components into a model, call as_turing_model (directly or through IDModel / IDProblem), simulate by passing missing data, and fit by passing observed data and sampling. Because the components share one interface, you swap a modelling assumption by swapping a struct — the Composable design page explains the mechanism.

References

The methods these tutorials recreate and adapt are described in the following works. Individual pages link back to the relevant entries here. 2. A. Cori, N. M. Ferguson, C. Fraser and S. Cauchemez. A new framework and software to estimate time-varying reproduction numbers during epidemics. American Journal of Epidemiology 178, 1505–1512 (2013).

  1. S. Mishra, T. Berah, T. A. Mellan, H. J. Unwin, M. A. Vollmer, K. V. Parag, A. Gandy, S. Flaxman and S. Bhatt. On the derivation of the renewal equation from an age-dependent branching process: an epidemic modelling perspective, arXiv preprint arXiv:2006.16487 (2020).

  2. S. Abbott, J. Hellewell, R. N. Thompson, K. Sherratt, H. P. Gibbs, N. I. Bosse, J. D. Munday, S. Meakin, E. L. Doughty, J. Y. Chun and others. Estimating the time-varying reproduction number of SARS-CoV-2 using national and subnational case counts. Wellcome Open Research 5, 112 (2020).

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

  4. C. Rackauckas and Q. Nie. DifferentialEquations.jl – a performant and feature-rich ecosystem for solving differential equations in Julia. Journal of Open Research Software 5 (2017).

  5. A. Chatzilena, E. van Leeuwen, O. Ratmann, M. Baguelin and N. Demiris. Contemporary statistical inference for infectious disease models using Stan. Epidemics 29, 100367 (2019).

  6. T. E. Loman, Y. Ma, V. Ilin, S. Gowda, N. Korsbo, N. Yewale, C. Rackauckas and S. A. Isaacson. Catalyst: Fast and flexible modeling of reaction networks. PLoS Computational Biology 19, e1011530 (2023).

  7. G. Riutort-Mayol, P.-C. Bürkner, M. R. Andersen, A. Solin and A. Vehtari. Practical Hilbert space approximate Bayesian Gaussian processes for probabilistic programming. Statistics and Computing 33, 17 (2023).

  8. K. Charniga, S. W. Park, A. R. Akhmetzhanov, A. Cori, J. Dushoff, S. Funk and others. Best practices for estimating and reporting epidemiological delay distributions of infectious diseases. PLoS Computational Biology 20, e1012520 (2024).

  9. A. Solin and S. Särkkä. Hilbert space methods for reduced-rank Gaussian process regression. Statistics and Computing 30, 419–446 (2020).