1. Home
  2. Explore
  3. Mathematics
  4. Bayesian Modeling Introduction

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bayesian Modeling Introduction

Introduction to Epidemic Modeling

This set of notes covers mechanistic models of disease transmission, focusing on how mathematical and statistical models are used to understand and predict the spread of infectious diseases. These models are built from biological mechanisms, not off-the-shelf statistical methods.

Mechanistic vs. Statistical Models

Statistical models (e.g., linear regression, GLMs) are mathematically derived and applied to many systems; their parameters have a mathematical interpretation (e.g., "change in response per unit change in predictor"). Mechanistic models (transmission models) are built with the biological or ecological mechanisms in mind. Their parameters are directly interpretable in a biological way:

  • Infectious period – how long an individual is infectious

  • Contact rate – how often encounters happen that could transmit disease

  • Transmission rate – the rate at which disease spreads through the population

This interpretability is a major advantage, especially at the start of an epidemic, because parameters can often be estimated piecemeal from separate studies (e.g., literature on infectious period, experiments on transmission). These models are primarily used for simulation – forecasting future cases or testing control strategies (e.g., "what if we vaccinate 30% of the population?"). Risk factor assessment (e.g., "is my covariate significant?") is secondary.

Key difference from standard statistical models: non-independence of infection events. In survival analysis for cancer, your risk doesn't depend on who else has cancer. In infectious diseases, your risk depends on how many infectious individuals are around – infection drives infection via feedback.

Disease surveillance methods (e.g., change-point detection, spatial-temporal disease mapping) are related but not the focus here.


Population-Level Models (Homogeneous Models)

These assume that all individuals are essentially the same – no age, gender, or geographic effects – and that everyone mixes randomly. These are the simplest but still extremely useful models.

The SIR Model

The most common non-trivial compartmental model divides the population into three states or compartments:

  • Susceptible (S) – can get the disease but hasn't yet

  • Infectious (I) – has the disease and can transmit it

  • Removed (R) – no longer susceptible or infectious (recovered with immunity, died, or quarantined; often called "recovered" but "removed" is more general)

Transitions: Susceptible → Infectious (via transmission rate β\betaβ) and Infectious → Removed (via removal rate γ\gammaγ). The average infectious period is 1/γ1/\gamma1/γ.

Let S(t)S(t)S(t), I(t)I(t)I(t), R(t)R(t)R(t) be the number in each compartment at time ttt, with total population N=S+I+RN = S + I + RN=S+I+R (assuming no births, deaths, or migration). In discrete time, the model uses difference equations:

S(t+1)=S(t)−I∗(t)S(t+1) = S(t) - I^*(t)S(t+1)=S(t)−I∗(t)
I(t+1)=I(t)+I∗(t)−R∗(t)I(t+1) = I(t) + I^*(t) - R^*(t)I(t+1)=I(t)+I∗(t)−R∗(t)
R(t+1)=R(t)+R∗(t)R(t+1) = R(t) + R^*(t)R(t+1)=R(t)+R∗(t)

Where I∗(t)I^*(t)I∗(t) = new infections at time ttt, R∗(t)R^*(t)R∗(t) = new removals at ttt.

Stochastic mechanism: A stochastic SIR model introduces randomness, capturing real-world uncertainty. New infections follow a binomial distribution:

  • Maximum possible new infections = S(t)S(t)S(t)

  • Infection probability: πt=1−e−βI(t)/N\pi_t = 1 - e^{-\beta I(t) / N}πt​=1−e−βI(t)/N

  • So I∗(t)∼Binomial(S(t),πt)I^*(t) \sim \text{Binomial}(S(t), \pi_t)I∗(t)∼Binomial(S(t),πt​)

New removals also follow a binomial:

  • Maximum = I(t)I(t)I(t)

  • Removal probability: 1−e−γ1 - e^{-\gamma}1−e−γ

  • So R∗(t)∼Binomial(I(t),1−e−γ)R^*(t) \sim \text{Binomial}(I(t), 1 - e^{-\gamma})R∗(t)∼Binomial(I(t),1−e−γ)

The infection probability depends on the number of infectious individuals (feedback), while removal probability is constant.

Key takeaway: The SIR model captures the dynamics of an epidemic: susceptibles decrease, infectious rise then fall, removals accumulate. Stochasticity allows for early extinction or varied outbreak sizes.

Deterministic vs. Stochastic

The deterministic equivalent uses ordinary differential equations (continuous time) and gives the same output each time. It's useful for mean behavior but misses the realistic variability seen in actual epidemics (e.g., some die out by chance). Statisticians prefer stochastic models to quantify uncertainty.

Bayesian Inference for the SIR Model

The likelihood is simple if we observe I∗(t)I^*(t)I∗(t) and R∗(t)R^*(t)R∗(t) at each time point – it's a product of binomial mass functions:

log⁡L=∑t[I∗(t)log⁡(πt)+(S(t)−I∗(t))log⁡(1−πt)]+∑t[R∗(t)log⁡(1−e−γ)+(I(t)−R∗(t))log⁡(e−γ)]\log L = \sum_t \left[ I^*(t) \log(\pi_t) + (S(t)-I^*(t)) \log(1-\pi_t) \right] + \sum_t \left[ R^*(t) \log(1-e^{-\gamma}) + (I(t)-R^*(t)) \log(e^{-\gamma}) \right]logL=∑t​[I∗(t)log(πt​)+(S(t)−I∗(t))log(1−πt​)]+∑t​[R∗(t)log(1−e−γ)+(I(t)−R∗(t))log(e−γ)]

Maximum likelihood estimation is possible, but Bayesian methods are preferred for several reasons:

  1. Interpretable posterior – a probability distribution, no need for repeated sampling (epidemics are unique events).

  2. Data augmentation – epidemic data are often incomplete (e.g., infection time unobserved, only symptom onset known). The Bayesian framework treats missing data as random variables, jointly estimating them with parameters. This is harder in maximum likelihood.

  3. Prior information – parameters (e.g., infectious period) are interpretable, so priors can be elicited from experts or previous studies. This helps identifiability and cuts off unrealistic parameter space.

Typical priors: positive rate parameters like β\betaβ and γ\gammaγ get gamma priors (or half-normal, uniform, half-t). Often a prior is placed on the mean infectious period 1/γ1/\gamma1/γ for easier elicitation.

Posterior inference: Markov Chain Monte Carlo (MCMC) is used. Packages like Nimble (built on BUGS/JAGS) compile MCMC in C++ for speed and allow flexible sampler choices. Trace plots are checked for stationarity; after burn-in, the chain approximates the posterior.

Example: True β=0.6\beta=0.6β=0.6, γ=0.2\gamma=0.2γ=0.2 (infectious period 5 days). With a moderately informative prior on γ\gammaγ (mean infectious period between 4–6 days), posterior means were close to truth and credible intervals captured true values.

Basic Reproduction Number R0R_0R0​

R0R_0R0​ (R-naught) is the expected number of direct infections caused by a single infection in a wholly susceptible population. It's a key metric because neither β\betaβ nor γ\gammaγ alone capture epidemic strength. For the SIR model:

R0=βγ=β×1γR_0 = \frac{\beta}{\gamma} = \beta \times \frac{1}{\gamma}R0​=γβ​=β×γ1​
  • If R0>1R_0 > 1R0​>1: epidemic tends to take off (each infected infects more than one on average).

  • If R0<1R_0 < 1R0​<1: epidemic tends to die out.

  • R0=1R_0 = 1R0​=1: threshold; may persist or die out by chance.

Public health measures aim to reduce R0R_0R0​ below 1 (flattening the curve or extinguishing the outbreak).


Extensions of Population-Level Models

Changing the Compartment Structure

  • SI model: Only susceptible and infectious (no removal). Useful for diseases with long infectious periods (e.g., HIV) over short observation times.

  • SEIR model: Adds an Exposed (E) compartment for a latent period where an individual is infected but not yet infectious. Movement from E to I occurs at rate σ\sigmaσ, and from I to R at γ\gammaγ. This adds an extra binomial component.

  • SIS / SIRS models: Allow re-infection after recovery (immunity wanes). Individuals move back from R to S at rate λ\lambdaλ. Useful for diseases like influenza or common cold.

Time-Varying Transmission Rate

β\betaβ captures both pathogen infectivity and contact rate. Both can change over time due to:

  • Government interventions (lockdowns, mask mandates)

  • Behavioral changes

  • Pathogen evolution

Common approach: change-point models – let β\betaβ take different values before and after key dates. For example, during the 2014–2015 Ebola outbreak in Sierra Leone, β\betaβ changed after UN policy for case isolation and again after reaching near-100% coverage.

Vaccination and Heterogeneous Populations

  • Vaccinated individuals may go straight to removed (if vaccine is 100% effective) or have reduced susceptibility/transmissibility.

  • Models can include separate compartments for vaccinated vs. unvaccinated (e.g., IvI_vIv​ and IuI_uIu​) with different rates.

  • Asymptomatic cases: an additional compartment for infected but symptomless individuals – they may still transmit but at a different rate. Data augmentation helps impute unknown asymptomatic counts.


Individual-Level Models (ILMs)

Population-level models assume homogeneous mixing. Reality is heterogeneous: geography, contact networks, genetics, vaccination history, lifestyle, etc. Individual-level models (also called individual-based models) incorporate these factors.

Framework Components

The infection rate for a susceptible individual iii at time ttt (discrete time version):

βit=ΩS(i)×(∑j∈I(t)ΩT(j)⋅κ(i,j))+ε(i,t)\beta_{it} = \Omega_S(i) \times \left( \sum_{j \in I(t)} \Omega_T(j) \cdot \kappa(i,j) \right) + \varepsilon(i,t)βit​=ΩS​(i)×(∑j∈I(t)​ΩT​(j)⋅κ(i,j))+ε(i,t)
  • ΩS(i)\Omega_S(i)ΩS​(i): Susceptibility function – risk factors for getting infected (age, genetics, vaccination status, prior infection, etc.)

  • ΩT(j)\Omega_T(j)ΩT​(j): Transmissibility function – risk factors for passing on the disease (may be same or different factors)

  • κ(i,j)\kappa(i,j)κ(i,j): Infection kernel – connectivity between susceptible iii and infectious jjj (spatial distance, network adjacency)

  • ε(i,t)\varepsilon(i,t)ε(i,t): Sparks term – allows for infections from outside the observed population (often constant or proportional to epidemic strength)

The probability that susceptible iii becomes infected at time ttt:

pit=1−e−βitp_{it} = 1 - e^{-\beta_{it}}pit​=1−e−βit​

Infectious period is usually modeled the same as before (e.g., geometric distribution), though it could also depend on covariates.

Spatial Models

Example: kernel κ(i,j)=dij−δ\kappa(i,j) = d_{ij}^{-\delta}κ(i,j)=dij−δ​, where dijd_{ij}dij​ is distance and δ>0\delta > 0δ>0. Closer individuals have much higher risk. Simulating from such a model produces wave-like spatial spread (e.g., infection across a grid of crops or farms). Parameters estimated from data.

Network Models

Kernel κ(i,j)=1\kappa(i,j) = 1κ(i,j)=1 if individuals iii and jjj are connected (e.g., friends, housemates, sexual partners), 0 otherwise. Networks capture social structure: some individuals highly connected (hubs), others isolated. Disease spreads only along edges. Weights and directionality can be added (e.g., different transmission probabilities each way).

Example application: modeling H1N1 influenza spread in a Pennsylvania elementary school using a social network of friendships, with node attributes (gender, class) as covariates for susceptibility/transmissibility.

Likelihood for ILMs

The likelihood has two components:

  1. Infection component: For each time step, for each individual, a Bernoulli-like product over all susceptible individuals: those who remain susceptible contribute (1−pit)(1-p_{it})(1−pit​); those newly infected contribute pitp_{it}pit​.

  2. Infectious period component: The duration of infectiousness for each infected individual follows a specified distribution (e.g., geometric).

This likelihood is conceptually simple but computationally heavy for large populations, as probabilities change with each infection/removal and differ across individuals.

Bayesian Inference for ILMs

Same advantages as population-level models: data augmentation for missing infection times, prior information for interpretable parameters. Priors are typically positive (gamma, half-normal). Spatial parameters (e.g., δ\deltaδ) are harder to elicit, so weakly informative priors are common. MCMC can be slow; efficient coding and packages help.


Resources and Packages

  • Population-level models: Book Epidemics: Models and Data using R by Ottar Bjørnstad (focus on maximum likelihood). More advanced: Handbook of Infectious Disease Data Analysis (math-focused).

  • Nimble: User manual, CRAN page, YouTube tutorials for learning MCMC in a Bayesian framework.

  • R packages for ILMs:

    • simInf (discrete time) – for simulating and fitting spatial and network models with MCMC. Includes documentation with examples.

    • EpiILM (continuous time) – similar functionality.

  • ASA community website has introductory Bayesian talks.

Practical Advice

  • For multiple pathogen strains: build in cross-immunity (full protection against same strain, partial against others) via changes to transmission rates or infectious periods.

  • For communicating stochasticity: simulate epidemics from the posterior distribution and present probabilities of exceeding thresholds (e.g., "probability that peak exceeds X cases").

  • For randomized controlled trials (RCTs) in infectious disease: these models can estimate intervention effectiveness (e.g., vaccinating children in households and measuring transmission to others).


Summary

Mechanistic epidemic models, from simple SIR to complex individual-level spatial/network models, are powerful tools for understanding and predicting disease spread. The Bayesian framework is especially suited due to its handling of missing data, interpretable posterior, and ability to incorporate prior knowledge. The field emphasizes simulation and forecasting over significance testing, with parameters directly mapped to biological reality. These concepts extend beyond human diseases to livestock, plants, invasive species, computer viruses, and even social phenomena like meme propagation or financial contagion.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent