← Back to Disease Modeling

Agent-Based Modeling: Measles Transmission in Schools

by Veronica Scerra

Moving beyond population-level compartmental models to capture spatial structure, contact networks, and vaccination clustering effects in disease dynamics.

After building compartmental (ODE) models for HIV/AIDS in Cuba and yellow fever in Senegal, I wanted to tackle a fundamentally different type of modeling challenge - one where individual heterogeneity and spatial structure aren't just details to abstract away, but critical drivers of epidemic dynamics. School-based measles outbreaks provided the perfect case study. When unvaccinated students cluster in specific classrooms, when contact networks are structured by grade level, and when stochastic fadeout can determine whether an outbreak explodes or fizzles - these are precisely the phenomena where agent-based models (ABMs) excel.

Why Agent-Based Modeling?

Compartmental models treat populations as well-mixed pools - everyone in the "Susceptible" compartment has equal probability of contacting anyone in the "Infectious" compartment. This works remarkably well for large, homogeneous populations with random mixing. But schools aren't like that. A third-grader in Classroom A spends most of their day with 24 specific classmates, not randomly sampling from 450 students. Vaccination rates can vary from 100% in one classroom to 60% in another due to clustered beliefs or access barriers. One infected student doesn't equally expose the entire school - they expose their immediate social network.

What ABM Captures That ODEs Can't:

This isn't to say ABMs are "better" - they're computationally expensive, harder to fit to data, and can obscure big-picture trends in individual-level noise. But for structured populations with heterogeneous mixing, they reveal dynamics that population models miss entirely.

Model Design and Architecture

School Structure

I modeled a realistic elementary school with 6 grades (1-6), 3 parallel classrooms per grade, and 25 students per classroom (450 students total). This isn't arbitrary: it matches typical U.S. elementary school sizes and creates enough structure to show spatial effects without becoming computationally prohibitive.

Each student is an individual agent with:

Key Design Decision: Individual-level tracking with classroom structure
  • Each student is a Python object with explicit state and attributes
  • Students organized hierarchically: School → Grade → Classroom → Individual
  • Contact networks defined by classroom membership and spatial proximity
  • Enables visualization of spatial spread patterns

Contact Networks and Transmission

The core of any ABM is the contact structure. I implemented a two-tier contact system:

Contact TypeDaily ContactsTransmission ProbabilityRationale
Within-Classroom ~20 β = 0.08 Close, prolonged contact with same classmates
Between-Classroom ~5 β = 0.005 Hallway, playground, lunchroom mixing

Why These Values? Within-classroom transmission is 16× stronger than between-classroom because students spend 6-7 hours/day in close quarters with classmates but only brief periods (recess, lunch, transitions) mixing with other grades. The contact counts come from social network studies in schools (Stehlé et al., 2011; Read et al., 2008), and transmission probabilities were calibrated to produce realistic R₀ values (~12-15 for measles in susceptible populations).

Implementation Detail: Stochastic Contact Generation
  • For each infectious student, sample Nwithin ~ Poisson(20) classmate contacts
  • Sample Nbetween ~ Poisson(5) contacts from other classrooms/grades
  • Each contact has probability β of transmission if susceptible
  • Newly exposed students enter latent period before becoming infectious

Disease Progression Dynamics

Measles follows classic SEIR dynamics with well-characterized parameters:

ParameterValueMeaningSource
Latent Period (1/σ) 10 days Time from infection to becoming infectious Guerra et al. (2017)
Infectious Period (1/γ) 8 days Duration of infectiousness Clinical literature
Basic R₀ ~13-16 Secondary infections per case Combined from contact rates and β values
Vaccine Efficacy 97% Protection with 2-dose MMR CDC/WHO

Progression through disease states uses stochastic transitions: at each time step (1 day), exposed individuals have probability 1 - exp(-σ·dt) of becoming infectious, and infectious individuals have probability 1 - exp(-γ·dt) of recovering. This creates realistic, exponentially-distributed durations rather than fixed lockstep transitions.

Vaccination Implementation and Clustering

The most critical modeling decision was how to implement vaccination. Real-world vaccination coverage isn't uniformly distributed - it clusters. Communities with strong anti-vaccine sentiment, limited healthcare access, or religious exemptions create pockets of susceptibility.

Two Vaccination Scenarios

1. Random Vaccination (Ideal Case): Select coverage % of students at random across the entire school. This represents perfect vaccine distribution (what you'd get if every family made independent, random vaccination decisions).

2. Clustered Vaccination (Realistic Case): Vary coverage by classroom using a Beta distribution, creating heterogeneity where some classrooms have high coverage (95%+) and others have low coverage (60-70%). This models real-world patterns where vaccination attitudes cluster geographically or socially.

Clustering Implementation:
  • For each classroom, draw coverage from Beta(α, β) centered around target mean
  • Clustering factor controls variance: 0 = uniform, 1 = extreme clustering
  • Within each classroom, randomly select students to vaccinate at that coverage
  • Vaccinated students have 97% chance of protection (efficacy), placed in Recovered state

Results: Baseline and Vaccination Scenarios

Baseline: No Vaccination

Starting with one infected student in Grade 3, a fully susceptible population shows measles' frightening contagiousness:

MetricValue
Attack Rate100% (all 449 susceptible students infected)
Peak Infectious83 students (Day 77)
Epidemic Duration~100 days

The spatial visualizations reveal how disease spreads: starting in one Grade 3 classroom, it rapidly saturates that room, then spreads to adjacent classrooms via hallway/recess contacts, eventually reaching all grades. This creates visible "waves" of infection moving through the school structure.

Vaccination Coverage Analysis

I tested four coverage levels representing different public health scenarios:

ScenarioCoverageAttack RatePeak InfectiousOutbreak Contained?
No Vaccination0%100.0%83
Low Coverage70%53.8%12
Medium Coverage85%30.0%6
High Coverage95%2.9%2

Key Finding: The ~93-95% Threshold. Attack rates drop dramatically above 93% coverage, consistent with theoretical herd immunity threshold HIT = 1 - 1/R₀ ≈ 93% for R₀=15. Below this threshold, outbreaks still occur but with reduced severity. Above it, most introductions self-limit before spreading widely.

The Clustering Effect

At identical overall coverage (85%), clustering makes a massive difference:

Vaccination PatternAttack RatePeak InfectiousDifference
Random (85%)30.0%6Baseline
Clustered (85%)42.3%9+41% more cases

When unvaccinated students cluster in specific classrooms, those rooms become amplification hotspots - pockets of dense susceptibility where transmission chains can sustain themselves before spreading to better-protected classrooms. This demonstrates why coverage distribution matters as much as coverage level.

Sensitivity Analysis and Model Robustness

To verify that findings weren't artifacts of specific parameter choices, I ran systematic sensitivity analysis varying vaccination coverage from 0% to 95% in 5% increments, with 5 stochastic replicates at each level.

Results:

This sensitivity analysis serves dual purposes: it confirms robustness to parameter uncertainty and provides actionable policy insights by quantifying the coverage-outcome relationship across the full range.

Key Insights and Methodological Decisions

When to Use ABM vs. ODE Models

Contact Network Calibration

Stochastic vs. Deterministic

Computational Efficiency Decisions

Public Health Implications

This modeling work has direct policy relevance:

1. Vaccination Coverage Requirements Are Real

The theoretical herd immunity threshold (93-95%) isn't just math, it's the actual coverage needed to protect communities. Schools falling below this threshold face substantial outbreak risk, even if "most" students are vaccinated. Policy should target ≥95% coverage to ensure reliable protection.

2. Clustering Defeats Coverage

A school with 85% average coverage sounds good, but if that 15% unvaccinated population clusters in two classrooms, those become outbreak epicenters. Public health interventions must address not just how many are vaccinated, but where the gaps are. Targeted outreach to undervaccinated communities is essential.

3. School Structure Matters for Containment

Visualizing spatial spread revealed actionable intervention points. If an outbreak is detected early (1-2 cases), closing the affected classroom could contain spread before it reaches other grades. This is testable in future ABM work—add classroom closure as an intervention parameter.

4. Small Outbreaks Are Unpredictable

At high coverage (>90%), stochastic fadeout becomes likely. This creates uncertainty for outbreak response: "Will this case spark an outbreak?" is genuinely probabilistic. Public health planning should account for this uncertainty, not assume deterministic trajectories.

Limitations and Extensions

Current Limitations

Future Extensions

High Priority:

Lower Priority But Interesting:

What I Learned

This project marked a significant expansion of my modeling toolkit. Moving from compartmental ODEs to agent-based models required fundamentally different thinking:

Individual-Level Coding Is Different. Instead of writing differential equations, I'm managing object-oriented class hierarchies (Student → School), tracking state transitions for hundreds of individuals, and thinking about contact network algorithms. The code architecture matters more. Modular design is essential when complexity scales with population size.

Visualization Becomes Central. In ODE models, I plot S(t), E(t), I(t), R(t) curves. In ABM, the power is seeing disease spread across classrooms, watching clusters form, observing spatial patterns emerge. Animation and heatmaps aren't optional extras, they're primary analytical tools.

Stochasticity Changes Interpretation. With ODEs, I report "the outbreak peaks at day 42." With ABM, I report "the outbreak peaks at day 42±7 (mean±SD across replicates)." Embracing uncertainty means acknowledging that real outbreaks have irreducible randomness.

Computational Efficiency Is Non-Negotiable. A 120-day simulation that takes 5 minutes isn't usable for sensitivity analysis requiring 100+ runs. I learned to profile code, optimize bottlenecks, and design algorithms that scale. For agent-based work, computational thinking is as important as epidemiological thinking.

The Right Tool for the Right Question. This project crystallized when to use which modeling approach. ABM doesn't replace compartmental models—it complements them. For policy questions about structured populations with heterogeneous interventions, ABM is often the only approach that captures the relevant mechanisms. For population-level parameter estimation and long-term trend projection, ODEs remain superior.

Broader Context

Agent-based modeling has a rich history in epidemiology, from early work on smallpox (Halloran et al., 2002) through pandemic influenza planning (Ferguson et al., 2006) to modern COVID-19 response (Kerr et al., 2021). This project builds on that tradition while focusing on a specific, policy-relevant context: school-based outbreaks of vaccine-preventable diseases.

The model's structure - individual agents in spatial containers with network-based contacts - is generalizable beyond measles. The same framework could model influenza in offices, tuberculosis in prisons, or STIs in sexual networks. What changes are the parameters (R₀, infectious period), not the fundamental architecture.

View Source Code