Skip to content

An SIR compartmental model ​

The renewal equation is one way to generate infections, but it is not the only one. Mechanistic compartmental models describe transmission with a system of ordinary differential equations (ODEs). DocumenterCitations.CitationSiteNode("chatzilena2019contemporary-cite-2")

showed how to embed such an ODE in a Bayesian model and infer its parameters, using a classic influenza outbreak in an English boarding school as their example.

This tutorial swaps the renewal infection process for an ODEProcess built from SIRParams, keeping the same composable observation machinery. Infections come from solving the SIR equations with the SciML stack [ DocumenterCitations.CitationSiteNode("rackauckas2017differentialequations-cite-2")

] rather than from a bespoke solver.

The model ​

, , are population proportions; is the transmission rate, the recovery rate, and the population size. The softplus link smoothly scales the infected proportion to expected counts while staying positive even if the solver returns a small negative value near zero.

The infection process ​

SIRParams declares priors for the transmission rate, recovery rate, and initial infected proportion, over a solver time span. We use weakly informative priors that keep the basic reproduction number   in a plausible range for influenza and bounded away from the   ( ) singularity.

julia
using ComposableTuringIDModels, Distributions, Random, Turing, LogExpFunctions
using ADTypes: AutoForwardDiff
using CSV, DataFrames
Random.seed!(1978)

N = 763          # children in the school

datapath = joinpath(pkgdir(ComposableTuringIDModels),
    "docs", "src", "tutorials", "data", "influenza_england_1978_school.csv")
influenza = CSV.read(datapath, DataFrame)
y_obs = influenza.in_bed            # children confined to bed each day
ts = collect(1.0:length(y_obs))     # observation times (days)
n = length(y_obs)

sir_params = SIRParams(
    tspan = (0.0, ts[end]),
    infectiousness = LogNormal(-0.5, 0.5),
    recovery_rate = Gamma(8, 0.03125),
    initial_prop_infected = Beta(2, 200))

DocumenterCitations.CitationSiteNode("chatzilena2019contemporary-cite-3")

fit this to a 1978 influenza outbreak in an English boarding school, taking the number of children "in bed" each day as a proxy for the infected compartment. Of the 763 children, 512 fell ill over 14 days.

ODEProcess composes those parameters with a solver and a sol2infs link that pulls the infected compartment out of the ODE solution. This is the standard SciML pattern — a problem definition composed with a solution method — specialised to probabilistically sampled parameters. The default solver switches between explicit and implicit methods, which keeps the solve robust when the sampler proposes stiff parameter values.

julia
# Pull the infected compartment from the ODE solution. A solve that fails under
# an extreme sampler proposal returns fewer than `n` saved points; map that to a
# series the observation likelihood rejects, so the sampler steps away rather
# than erroring on the shortened series.
function infected(sol)
    infs = sol[2, :]
    length(infs) == n ? infs : fill(eltype(infs)(Inf), n)
end

sir_process = ODEProcess(
    params = sir_params,
    sol2infs = infected,
    solver_options = Dict(:saveat => ts))

The observation model ​

The ODE returns the infected proportion ; we scale it to counts with the population size and a softplus transform using TransformObservationModel, then link to data with a PoissonError.

julia
observation = TransformObservationModel(PoissonError(), x -> softplus.(N .* x))

A compartmental model needs no time-varying latent process — the dynamics are fully determined by the ODE parameters — so the ODEProcess carries no latent process at all (its Z_t generated quantity is nothing). IDModel assembles the infection and observation parts exactly as in the renewal examples.

julia
model = IDModel(sir_process, observation)

Fit ​

Fitting recovers the SIR parameters from the observed "in bed" counts. This page differentiates with ForwardDiff, not the package's recommended Mooncake default: reverse-mode (Mooncake-driven) NUTS through the ODE solver is not available yet — a pre-existing Turing + Mooncake + SciMLSensitivity integration gap that affects every ODE infection model (tracked in issue #46). Forward-mode autodiff is a good fit here anyway, for a system this small. We draw four chains in parallel with MCMCThreads() so a cross-chain is available:

julia
posterior = as_turing_model(model, y_obs, n)
chain = sample(
    posterior, NUTS(0.95; adtype = AutoForwardDiff()),
    MCMCThreads(), 250, 4; progress = false)
┌ Info: Found initial step size
└   ϵ = 0.025
┌ Info: Found initial step size
└   ϵ = 0.05
┌ Info: Found initial step size
└   ϵ = 0.003125
┌ Info: Found initial step size
└   ϵ = 0.025
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222

sample returns a FlexiChains chain, which summarystats summarises directly — no conversion step:

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 (3) ── AbstractPPL.VarName                                        │
│  Float64  β, γ, I₀                                                           │
│                                                                              │
│ 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      q5  …    │
│       β  15.2812  24.2569  13.0680    5.4452   35.4862  1.2287  1.7835  …    │
│       γ   0.4185   0.1024   0.0572    5.1107   23.3973  1.2188  0.2390  …    │
│      I₀   0.0096   0.0171   0.0090    5.2441   28.5206  1.2197  0.0004  …    │
╰──────────────────────────────────────────────────────────────────────────────╯

The posterior gives the transmission and recovery rates directly, and the basic reproduction number   is a deterministic function of them. Individual parameter draws are read by name with vec(chain[@varname(...)]), from which the derived is formed per draw:

julia
using Turing: @varname
using Statistics
β = vec(chain[@varname(β)])
γ = vec(chain[@varname(γ)])
R0 = β ./ γ
(β = mean(β), γ = mean(γ), R0 = mean(R0))
(β = 15.281243494098964, γ = 0.4185114721261557, R0 = 60.29398524572757)

Prior versus posterior ​

Sampling the same model with Prior gives a prior draw over the transmission rate , recovery rate and initial infected proportion . Overlaying it on the posterior with PairPlots.jl shows how sharply the boarding-school outbreak identifies the mechanistic parameters.

julia
using CairoMakie, PairPlots

prior_chain = sample(posterior, Prior(), 1000; progress = false)
pp_keys = [@varname(β), @varname(γ), @varname(I₀)]
pairplot(
    PairPlots.Series(chain[pp_keys]; label = "posterior"),
    PairPlots.Series(prior_chain[pp_keys]; label = "prior"))

All three parameters collapse from broad priors onto tight, correlated posteriors — and trade off along the   ridge that the 14 days of data constrain.

Posterior trajectories ​

A compartmental model has no time-varying (its generated quantity is nothing); the infection signal is the infectious proportion solved from the ODE. generated_observables recovers per draw, and the posterior-predictive in-bed counts come from predict on the model with the observations set to missing. Two small helpers reduce the per-draw trajectories to credible bands.

julia
gens = vec(generated_observables(posterior, y_obs, chain).generated)
It = credible_bands(reduce(hcat, (g.I_t for g in gens)))

pred = predict(as_turing_model(model, fill(missing, n), n), chain)
yt = predictive_bands(pred, n)

fig = Figure(; size = (760, 620))
ax1 = Axis(fig[1, 1]; ylabel = "Infectious proportion I(t)")
ci_ribbon!(ax1, ts, It; color = :purple, label = "posterior median")
axislegend(ax1; position = :rt)
ax2 = Axis(fig[2, 1]; xlabel = "Day", ylabel = "Children in bed")
ci_ribbon!(ax2, ts, yt; color = :teal, label = "posterior predictive")
scatter!(ax2, ts, y_obs; color = :black, markersize = 7, label = "observed")
axislegend(ax2; position = :rt)
fig

The mechanistic infectious-proportion curve peaks mid-outbreak, and the posterior-predictive in-bed counts bracket the observed epidemic curve — the SIR dynamics, scaled by the population and Poisson observation model, reproduce the boarding-school outbreak.

Adding a stochastic ascertainment process ​

The deterministic model assumes the SIR equations describe the data exactly up to Poisson counting noise. Real outbreaks rarely oblige: the compartmental model is an approximation, and reporting intensity drifts over time. DocumenterCitations.CitationSiteNode("chatzilena2019contemporary-cite-4")

therefore also consider a stochastic variant in which a latent autoregressive process on the log scale modulates the expected counts, absorbing variation the mechanistic part cannot explain:

Setting   for all recovers the deterministic model, so the two are nested. In this package the process is exactly the AR latent model already used for in the renewal examples — here it modulates the observation process rather than infections. An Ascertainment modifier wraps the Poisson link and carries that latent process; the population TransformObservationModel is re-applied on the outside. No part of the infection model changes. The priors are weakly informative: damping near zero (highly autocorrelated increments), an initial state near zero (no baseline adjustment), and a small innovation standard deviation.

julia
ascertainment = AR(
    damp = [HalfNormal(0.005)],
    init = [Normal(0, 0.001)],
    ϵ_t = HierarchicalNormal(std = HalfNormal(0.02)))

stochastic_obs = TransformObservationModel(
    Ascertainment(model = PoissonError(), latent_model = ascertainment),
    x -> softplus.(N .* x))

stochastic_model = IDModel(sir_process, stochastic_obs)

Swapping the deterministic observation model for the stochastic one is a single structural change — the SIR infection process is reused untouched — and the composed model is fit exactly as before. The ascertainment process adds latent parameters, so we raise the NUTS target acceptance rate a little to keep the sampler stable through the ODE solve.

julia
stochastic_chain = sample(
    as_turing_model(stochastic_model, y_obs, n),
    NUTS(0.95; adtype = AutoForwardDiff()),
    MCMCThreads(), 250, 4; progress = false)
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Info: Found initial step size
└   ϵ = 0.0015625
┌ Info: Found initial step size
└   ϵ = 0.0015625
┌ Info: Found initial step size
└   ϵ = 0.0015625
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Warning: Verbosity toggle: init_NaN
│  First function call produced NaNs. Exiting. Double check that none of the initial conditions, parameters, or timespan values are NaN.
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:193
┌ Warning: Verbosity toggle: dt_epsilon
│  At t=0.0, dt was forced below floating point epsilon 5.0e-324. Aborting. There is either an error in your model specification or the true solution is unstable (or it cannot be represented in ForwardDiff.Dual{ForwardDiff.Tag{DynamicPPL.DynamicPPLTag, Float64}, Float64, 10} precision).
│ 
│ Diagnostics:
│ 
│ State Analysis:
│   All 3 state variables are non-finite (NaN/Inf)
│ 
│ Error Analysis:
│   step error estimate EEst = NaN (a step is accepted when EEst <= 1)
│   3 of 3 weighted residuals are non-finite (NaN/Inf)
│   largest contributors to EEst = internalnorm(atmp), where atmp is the tolerance-weighted local error per state component:
│     atmp[1] = NaN, u[1] = NaN, uprev[1] = 0
│     atmp[2] = NaN, u[2] = NaN, uprev[2] = 1
│     atmp[3] = NaN, u[3] = NaN, uprev[3] = 0
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/Vzzme/src/check_error.jl:20
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Warning: Verbosity toggle: dt_epsilon
│  Initial timestep too small (near machine epsilon), using default: dt = 1.0e-6
└ @ OrdinaryDiffEqCore ~/.julia/packages/OrdinaryDiffEqCore/luSGN/src/initdt.jl:222
┌ Info: Found initial step size
└   ϵ = 9.765625e-5

The SIR parameters keep their flat names (β, γ, I₀); the ascertainment process contributes its own block, prefixed Ascertainment. because modifiers that introduce a named sub-process prefix their variables to keep them distinct. summarystats shows both blocks, including the ascertainment innovation scale (Ascertainment.std), which quantifies how much observation-level noise the latent process absorbed:

julia
summarystats(stochastic_chain)
╭─FlexiSummary (9 statistics) ─────────────────────────────────────────────────╮
│   iter    collapsed                                                          │
│   chain   collapsed                                                          │
│ ↓ stat  = [mean, std, mcse, ess_bulk, ess_tail, rhat, q5, q50, q95]          │
│                                                                              │
│ Parameters (20) ── AbstractPPL.VarName                                       │
│  Float64  β, γ, I₀, Ascertainment.init[1], Ascertainment.damp,               │
│           Ascertainment.ρ, Ascertainment.std, Ascertainment.ϵ_t[1],          │
│           Ascertainment.ϵ_t[2], Ascertainment.ϵ_t[3], Ascertainment.ϵ_t[4],  │
│           Ascertainment.ϵ_t[5], Ascertainment.ϵ_t[6], Ascertainment.ϵ_t[7],  │
│           Ascertainment.ϵ_t[8], Ascertainment.ϵ_t[9], Ascertainment.ϵ_t[10], │
│           Ascertainment.ϵ_t[11], Ascertainment.ϵ_t[12],                      │
│           Ascertainment.ϵ_t[13]                                              │
│                                                                              │
│ 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  …      │
│              β   1.5773  0.5099  0.2855     4.5495   13.8421  1.2530  …      │
│              γ   1.7291  2.1593  1.2077     3.6014   30.8763  1.4316  …      │
│             I₀   0.0373  0.0637  0.0356     4.3468   12.6441  1.2717  …      │
│   Ascertainme…   0.0000  0.0009  0.0000  1213.2149  502.4650  1.2654  …      │
│   Ascertainme…   0.1159  0.1926  0.1077     4.7658   20.5080  1.2345  …      │
│   Ascertainme…   0.1159  0.1926  0.1077     4.7658   20.5080  1.2345  …      │
│   Ascertainme…   0.0693  0.0469  0.0282     2.9746   12.3724  1.6579  …      │
│   Ascertainme…  -0.4734  0.9985  0.3572     9.5369  112.8379  1.1069  …      │
│   Ascertainme…   0.3864  1.1358  0.5385     4.3381   20.8945  1.3121  …      │
│   Ascertainme…  -0.3603  0.7695  0.0952    62.6367   70.6476  1.2402  …      │
│   Ascertainme…   0.4935  0.8487  0.3752     5.5820   92.3189  1.3539  …      │
│   Ascertainme…   0.4401  1.0528  0.5089     4.6716   56.1899  1.3039  …      │
│   Ascertainme…  -0.8236  0.9674  0.2631    16.6421  177.6660  1.0582  …      │
│   Ascertainme…   0.6758  0.9003  0.1483    40.3833   56.8411  1.3417  …      │
│   Ascertainme…   1.0580  0.9026  0.1427    40.6356   55.6398  1.0903  …      │
│   Ascertainme…   0.7913  0.8632  0.2424    14.1637   31.9695  1.0879  …      │
│   Ascertainme…   0.3089  0.8469  0.1256    54.1469  120.0722  1.1724  …      │
│   Ascertainme…  -0.6736  0.9812  0.3812     8.4704  111.7247  1.1880  …      │
│   Ascertainme…  -0.5572  0.9190  0.1609    34.0533  140.1080  1.0193  …      │
│   Ascertainme…  -0.8765  1.0718  0.4834     5.3132   43.7398  1.3060  …      │
╰──────────────────────────────────────────────────────────────────────────────╯

The basic reproduction number is recovered as before — a derived quantity formed per draw from the sampled and — and the fitted ascertainment scale is small:

julia
βs = vec(stochastic_chain[@varname(β)])
γs = vec(stochastic_chain[@varname(γ)])
asc_std = vec(stochastic_chain[@varname(Ascertainment.std)])
(R0 = mean(βs ./ γs), ascertainment_sigma = mean(asc_std))
(R0 = 2.9378227630007054, ascertainment_sigma = 0.06930074016201421)

Because the deterministic model is the   special case, the two fits are directly comparable on this real outbreak:

julia
(deterministic_R0 = mean(R0), stochastic_R0 = mean(βs ./ γs))
(deterministic_R0 = 60.29398524572757, stochastic_R0 = 2.9378227630007054)

The SIR model is an approximation to the real transmission dynamics, so here the stochastic ascertainment process soaks up systematic departures from the SIR mean, guarding the mechanistic against that bias — the reason DocumenterCitations.CitationSiteNode("chatzilena2019contemporary-cite-5")

introduce it.

References ​

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

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