SIR on Networks

Module 5: Complex Networks

The SIR (Susceptible-Infected-Recovered) model adds permanent immunity to SIS: once a node recovers, it cannot be infected again (Kermack and McKendrick 1927; Keeling and Rohani 2008). You met its ODE version in Compartmental Models. On a network, the final size of an SIR outbreak is closely related to bond percolation, and the mapping is exact when every infected node stays infectious for the same time (newman2002spread?). This links the page to Robustness and Percolation.

This page reuses the graph models and node attributes of the SIS pages and focuses on what is new:

What is the SIR Model?

  • States: Each node can be Susceptible (S), Infected (I), or Recovered (R).
  • Transitions:
    • \(S \to I\): a susceptible node becomes infected through infected neighbors.
    • \(I \to R\): an infected node recovers and becomes permanently immune.
  • Permanent immunity: \(R\) is an absorbing state (once recovered, always recovered).

Discrete-Time Update Rule

You simulate in discrete time steps \(t = 0, 1, 2, \dots\).

If a susceptible node has \(m\) infected neighbors, use the same “independent trials” rule as SIS (Keeling and Rohani 2008):

\[ \mathbb{P}(S \to I) = 1 - (1 - \beta)^m. \]

If a node is infected, it recovers with probability:

\[ \mathbb{P}(I \to R) = \mu. \]

Recovered nodes stay recovered:

\[ \mathbb{P}(R \to R) = 1. \]

In SIS, \(I \to S\) (you become susceptible again). In SIR, \(I \to R\) (you become immune). That single change alters the long-term behaviour.

Absorbing States

On a finite graph with \(\mu > 0\), the process reaches a time \(T\) such that there are no infected nodes (\(I(T)=0\)), and after that nothing can ever change (Keeling and Rohani 2008; Pastor-Satorras et al. 2015).

Each node can become infected at most once (because \(R\) is permanent), so there can be at most \(N\) infection events. Since recovery happens with positive probability, infections cannot persist forever.

This means SIR always ends in a “frozen” configuration containing only \(S\) and \(R\) nodes.

Imports and Parameters

import networkx as nx
import numpy as np
import matplotlib.pyplot as plt

SEED = 7

# Model parameters
beta = 0.20
mu = 0.10

# Simulation parameters
steps = 120
initial_infected = 5
N = 100

Choose a Network

Reuse the helper from SIS Model on Networks.

G = make_graph("random", n=N, seed=SEED)
print("N, E =", G.number_of_nodes(), G.number_of_edges())
N, E = 100 317

Initialize States

As in SIS, store states on the graph using a node attribute called state.

initialize_state(G, initial_infected=initial_infected, seed=SEED)
print(
    "Initial counts (S, I, R) =",
    sum(G.nodes[u]["state"] == "S" for u in G.nodes()),
    sum(G.nodes[u]["state"] == "I" for u in G.nodes()),
    sum(G.nodes[u]["state"] == "R" for u in G.nodes()),
)
Initial counts (S, I, R) = 95 5 0

What’s Next?

The next page implements the SIR update and plots the epidemic curve.

SIR Simulation

References

Daley, D. J., and D. G. Kendall. 1965. “Stochastic Rumours.” Journal of the Institute of Mathematics and Its Applications 1 (1): 42–55. https://doi.org/10.1093/imamat/1.1.42.
Keeling, Matt J., and Pejman Rohani. 2008. Modeling Infectious Diseases in Humans and Animals. Princeton University Press.
Kermack, William O., and Anderson G. McKendrick. 1927. “A Contribution to the Mathematical Theory of Epidemics.” Proceedings of the Royal Society A 115 (772): 700–721. https://doi.org/10.1098/rspa.1927.0118.
Pastor-Satorras, Romualdo, Claudio Castellano, Piet Van Mieghem, and Alessandro Vespignani. 2015. “Epidemic Processes in Complex Networks.” Reviews of Modern Physics 87 (3): 925–79. https://doi.org/10.1103/RevModPhys.87.925.