Skip to content

EpiModel: Stochastic Network Epidemiology for Social Contagion Simulation

By Jeff 3 views
EpiModel simulation workflow architecture showing TERGM fitting, netdx validation, and netsim ensemble stages
EpiModel simulation workflow architecture showing TERGM fitting, netdx validation, and netsim ensemble stages

EpiModel is an open-source R package that provides a unified framework for simulating the spread of infectious diseases and social contagions across dynamic contact networks. Unlike compartmental ODE models that treat populations as homogeneous mixing pools, EpiModel explicitly represents individuals as nodes in a network whose edges—representing social contacts—form and dissolve over time according to user-specified statistical models. This network-centric approach captures the heterogeneous mixing patterns that drive real-world epidemic dynamics, making it an essential tool for researchers studying HIV transmission, sexually transmitted infections, COVID-19 spread, and behavioral contagion in social systems.

Core Architecture: Separating Network Formation from Disease Dynamics

EpiModel's design separates two distinct simulation layers: network formation and epidemic propagation. Network structure is estimated using Exponential Random Graph Models (ERGMs) via the statnet suite, specifically the tergm package for temporal ERGMs. Users specify network statistics—degree distribution, concurrency, assortative mixing by age or race, triangle closure—and tergm fits a model that reproduces those statistics in simulated networks that evolve over discrete time steps.

Once the network model is fitted, EpiModel's epidemic simulation engine propagates disease states across the dynamic network. At each time step, the engine:

  1. Simulates network evolution (edge formation and dissolution) using the fitted TERGM parameters
  2. Identifies discordant partnerships (susceptible–infected dyads)
  3. Applies transmission probabilities per act and per partnership
  4. Updates individual disease states (e.g., S→E→I→R) and vital dynamics (births, deaths, arrivals, departures)

This separation allows researchers to independently validate network structure against empirical contact data before coupling it to disease dynamics—a critical workflow advantage over monolithic ABM frameworks.

Defining Custom Epidemic Modules

EpiModel ships with built-in modules for SI, SIR, SIS, and SEIR models, but its modular architecture allows practitioners to inject custom R functions at any simulation stage. Each module is a plain R function with a standardized signature:

my_infection_module <- function(dat, at) {
  # dat: master data object (network, attributes, parameters, epi trackers)
  # at: current time step

  active   <- which(dat$attr$active == 1)
  status   <- dat$attr$status
  inf.prob <- dat$param$inf.prob

  # Identify susceptible nodes with infected partners
  el <- get_edgelist(dat, network = 1)
  disc <- el[status[el[,1]] == "s" & status[el[,2]] == "i", , drop = FALSE]

  # Bernoulli transmission per discordant edge
  transmit <- rbinom(nrow(disc), 1, inf.prob)
  newly_infected <- unique(disc[transmit == 1, 1])

  dat$attr$status[newly_infected] <- "i"
  dat$attr$infTime[newly_infected] <- at
  dat <- set_epi(dat, "si.flow", at, length(newly_infected))
  return(dat)
}

Custom modules can implement staged infection (acute vs. chronic HIV), treatment cascades (diagnosis → linkage → ART → viral suppression), behavioral interventions (condom use, PrEP uptake), and co-infection dynamics. The EpiModelHIV extension package, developed at Emory University, demonstrates this extensibility with a full HIV/STI transmission model incorporating PrEP, ART, and rectal gonorrhea co-infection across a dynamic MSM network.

Stochastic Simulation and Ensemble Analysis

Because network formation and transmission events are stochastic, EpiModel runs multiple independent simulations (typically 100–500 replicates) and aggregates results. The netsim() function accepts a nsims argument and returns an netsim object containing per-replicate time series for all tracked epidemic compartments and flows.

param  <- param.net(inf.prob = 0.08, act.rate = 1.2, rec.rate = 0.02)
init   <- init.net(i.num = 50)
control <- control.net(type = "SIR", nsims = 200, nsteps = 520,
                       ncores = 8, save.network = FALSE)

sim <- netsim(est, param, init, control)
plot(sim, y = c("s.num", "i.num", "r.num"), mean.smooth = TRUE,
     qnts = 0.5, legend = TRUE)

The qnts parameter controls the quantile envelope plotted around ensemble means, providing uncertainty bounds that reflect both network stochasticity and transmission randomness. For policy analysis, summary.netsim() extracts time-averaged incidence rates, peak prevalence, and final epidemic size across replicates.

Network Diagnostics and Model Validation

A common pitfall in network epidemiology is fitting a TERGM that reproduces target statistics in cross-sectional snapshots but fails to maintain them over longitudinal simulation. EpiModel addresses this with netdx(), which runs the fitted TERGM forward in time and computes diagnostics comparing simulated network statistics to targets:

dx <- netdx(est, nsims = 10, nsteps = 1000,
            nwstats.formula = ~edges + nodematch("race") + concurrent)
plot(dx, type = "formation")   # formation statistics over time
plot(dx, type = "duration")    # mean partnership duration vs. target
plot(dx, type = "dissolution") # dissolution rate diagnostics

Passing netdx diagnostics before coupling the network to disease dynamics is a non-negotiable validation step. Systematic drift in mean degree or concurrency over simulation time indicates model misspecification that will bias epidemic projections.

Scaling and Computational Considerations

EpiModel's ncores parameter enables parallel simulation across CPU cores using the doParallel backend. For populations exceeding ~50,000 nodes, memory pressure from storing full network edge lists at each time step becomes limiting. Practitioners can mitigate this by:

  • Setting save.network = FALSE to discard per-step network snapshots (retaining only epidemic trackers)
  • Using save.other selectively to retain only required node attributes
  • Employing the EpiModel resim_nets() workflow to decouple network simulation from epidemic simulation for very large populations

For national-scale simulations (millions of nodes), EpiModel's R-based engine is typically replaced by custom C++ implementations that use EpiModel's conceptual framework but exploit sparse matrix representations of the contact network.

Practical Applications

EpiModel has been used in peer-reviewed research to:

  • HIV prevention trials: Estimate the population-level impact of PrEP scale-up among MSM in Atlanta, accounting for network concurrency and assortative mixing by race
  • COVID-19 household transmission: Model within-household SEIR dynamics on empirically calibrated household size distributions
  • Behavioral contagion: Simulate the spread of health behaviors (vaccination uptake, smoking cessation) through social influence networks using SI-type models with behavior-specific transmission probabilities
  • STI co-infection: Quantify syndemic interactions between HIV and gonorrhea/chlamydia in dynamic sexual networks

Getting Started

EpiModel is available on CRAN and GitHub. The recommended installation sequence:

install.packages(c("EpiModel", "tergm", "ergm"))
# For HIV-specific extensions:
remotes::install_github("EpiModel/EpiModelHIV-p")

The EpiModel Gallery repository provides worked examples covering custom modules, multi-group models, and open population dynamics. The EpiModel Workshop materials offer a structured introduction to TERGM fitting and epidemic simulation workflows.

Further Reading

EpiModel SIR ensemble: 200 stochastic replicates with IQR uncertainty bands (N=10,000)

Dynamic contact network evolution across three time points showing disease state transitions

EpiModel netdx() TERGM diagnostics: mean degree, concurrency rate, and partnership duration vs. targets

Tags: EpiModel network epidemiology agent-based modeling TERGM social contagion