Skip to content

Infectious disease models ​

Many infectious disease models are recurrences and convolutions. Each table maps model features to the code that builds them, with the tutorial that uses each. Three towns, step by step builds a renewal process, a reporting delay, a coupling and depletion into one model. is infections, the reproduction number and the generation interval on lag .

Transmission ​

Model featureMathsCodeTutorial
Renewal process Recurrence(g), called as r(R; history)Three towns
Control measure from to cutting transmission by     , or any multiplier as the gain R .* measureThree towns ramps the reduction in over six days
Imported cases   add = ι, or Transform(+, TimeVarying(ι)) after depletionImported cases
Instantaneous or effective reproduction number from a runthe infections over the pressure, as the call table givesy ./ pressure(r, y; history), with pressureThe reproduction number from a run
Log reproduction number as a latent process  Recurrence([φ])(; history, add = ϵ)Latent processes driving R_t
Behavioural response to incidence–Transform, before DepletionLatent processes driving R_t

Random walks and autoregressions are recurrences, and moving averages are convolutions.

Susceptible depletion and vaccination ​

Model featureMathsCodeTutorial
Susceptible depletionthe depletion formsDepletion(N), or Depletion(N, Floor())Renewal then delay
Doses or places used up in full ,   Depletion(Truncate(); pools = (S = b,)), or Truncate(κ) for a smooth minimumTruncate docstring
All-or-nothing vaccination, efficacy , doses a share of doses leaves :    Depletion(N, Hazard(; weights = (S = 1, V = 0)), Flow(:S => :V, TimeVarying(η .* d); form = Truncate()); pools = (:S, :V))Vaccination
Leaky vaccination, efficacy , doses infections from   , doses move from to Depletion(N, Hazard(; weights = (S = 1, V = 1 - η)), Flow(:S => :V, TimeVarying(d); form = Truncate()); pools = (:S, :V))Vaccination
Waning protection at rate  ,     after each day's infections, before the day's dosesthe leaky Depletion with Flow(:V => :S, ω) beside the doses' flowVaccination
Births into a changing population   , the hazard divides by Depletion(TimeVarying(N), Hazard(), Flow(0 => :S, TimeVarying(b); form = Truncate()))Depletion in practice
Vaccine doses from a weekly budget , with refilled by each weekDepletion(Flow(0 => :Z, TimeVarying(b); form = Truncate()), Truncate(; overflow = :stratum); pools = (:Z,)), with b the weekly grantsDepletion in practice

Within one step a hazard flow acts before a count flow, so waning comes before the day's doses.

Reporting and clinical delays ​

Model featureMathsCodeTutorial
Reporting delay  Convolution(w)Three towns
Clinical transitions, each with probability  , one Convolution per transitionConvolution(w)(O; gain = h), chainedClinical outcomes
Delay that changes over time  or  Convolution(TimeVarying(W)), or TimeVarying(W, Primary())Time-varying delays and kernels
Delay from a hazard on the logit scale,     Increments(1 - Survival(Derived(LogisticSum(), a, TimeVarying(γ)))) in TimeVarying(·, Primary()), with a local rule for LogisticSumLocal rules for maps
Hazard read a day late and held past the data change points TimeVarying(Pair.([1; 2:(n + 1)], vcat(h[1], h))) inside Survival or a Derived kernel: the last value holds, so no padding is neededTimeVarying docstring

Places and groups ​

Model featureMathsCodeTutorial
Mixing between places or groups Recurrence(g; coupling = K)Spatial models
Generation interval per group or pair or PerStratum(W), Pairwise(A)Spatial models
Transmission routes, such as community and funeral contacts Recurrence(Pairwise(K₁ => g₁, K₂ => g₂))Spatial models
Importation between patchesa share of patch 's infections occurs in patch , with      for a movement matrix with column sums Redistribute(K, ε)Spatial models
Districts sharing a patch total fixed elsewhere  , with district 's own new infections before the splitAllocate(groups, TimeVarying(PerStratum(Ī)))Spatial models
Each district's imported cases within a fixed patch total, the part of placed by an import pattern from a share of ; summed over patch it is Allocate(groups, Ī; imports = (φ, P), trace_imports = Val(true)) named split, read as trace.modifiers.split.imports with record = (:split,)Allocate with imports
A gain that also scales an added input , such as infections seeded from outside the model , read before any other modifierTransform(*, TimeVarying(PerStratum(γ))) first in the modifiers, with add = a and no gainSpatial models

Branching processes and isolation ​

Model featureMathsCodeTutorial
Multi-type offspring, mean matrix  , growth per generation tends to the spectral radius of Recurrence([1.0]; coupling = K)Branching processes
Isolation   a thinned kernel g .* (1 .- p * b .* F)Branching processes
Isolation delay set by type    for infector type Recurrence(PerStratum(W); coupling = K)Branching processes
Contact tracing, traced and untraced types (an approximation)a share of infectees is traced and uses the thinned kernelRecurrence(Pairwise(A))Branching processes
Isolation that starts on a set day, by infection day  ,        Recurrence(TimeVarying(W, Primary())), seeded with start = m + 1Time-varying delays and kernels
Branching-process extinction by generation ,  , with the offspring probability generating functionRecurrence([1.0]; modifiers = (Transform(G, θ),)), called as r(; history = [0.0], stop)Branching processes

Hospital occupancy and capacity ​

Model featureMathsCodeTutorial
Bed occupancy, survival of the length of stay ; for a geometric stay,    and    Convolution(S)(A); for a geometric stay, Recurrence([1 - δ])(; history, add = A)Occupancy and capacity
Patients moving between the pools of a ward  ,     Recurrence([1.0]; modifiers = (Depletion(Flow(:U => :Q, c), Flow(:U => 0, r), Flow(:Q => 0, d); pools = (:U, :Q)),))Occupancy and capacity
Bed cap, geometric stay Transform(clamp, 0, B)Occupancy and capacity
Bed cap, any stay   admitted,   turned away,  Recurrence([0.0]; modifiers = (Transform(min, (B - Recent(S[2:end])) / S[1]),))(; history = [0.0], add = A), then Convolution(S)Occupancy and capacity
Isolation beds with overflow    of the admissions asked for, , admitted and   left in the communityDepletion(B, Flow(:O => 0, δ; form = Share()), Truncate(; into = :O, overflow = :stratum); pools = (:O,))Depletion in practice

Seeding and forecasting ​

Model featureMathsCodeTutorial
Seed days returned with the run then the renewalr(R; history, include_history = true)What a call returns
Seed on an exponential growth path , at a given rate per stepexponential_history(I0, r, L)Renewal then delay
Forecast after a fitcontinue from the fitted daysr(R; history, record = (:state,)), then r(R; state)Forecasting