In my last blog post I wrote about SIR models for epidemiology. What better application than simulating a zombie outbreak?

I will use the following assumptions for my model:

- 4 compartments: Survivors, Infected, Zombies, Dead.
- 10 milion people in the population. No births and natural deaths.
- Average contact rate between individuals is 7 (average number of people one is in direct contact with during a single day).
- Start with a single Infected.
- Infected do not pass the Zombie virus directly. They turn into a brain-hungry Zombie after 2 days of incubation.
- When a Zombie bites it turns a Survivor into an Infected with probability of 0.4.
- Zombies kill Survivors and Infected with probability of 0.4.
- Most Survivors hide from Zombies, but some are fighting back. They will kill a Zombie with probability of 0.7, but with a reduced contact rate to 40%.
- 10% of Survivors will also hunt down Infected and kill them with probability of 0.1.
- Zombies "starve" to death after 14 days (actually, they die of exhaustion).

Let us turn these into model equations. Survivors become infected with rate \(\tau\) after being bitten by a Zombie, or die as a result of the Zombie attack with probability \(\kappa_{ZS}\):

\[\frac{dS}{dt} = – \tau \cdot S \cdot \frac{Z}{N} – \kappa_{ZS} \cdot S \cdot \frac{Z}{N}\]

The number of infected increases at the rate of \(\tau\), while Zombies and some Survivors hunt down Infected with rates \(\kappa_{ZI}\) and \(\kappa_{SI}\) respectively. Infected turn into zombies with rate \(\iota\).

\[\frac{dI}{dt} = \tau \cdot S \cdot \frac{Z}{N} – \iota \cdot I – \kappa_{ZI} \cdot I \cdot \frac{Z}{N} – \kappa_{SI} \cdot I \cdot \frac{S}{N}\]

Zombies are killed by survivors at the rate of \(\kappa_{SZ}\) and die of starvation at rate \(\sigma\):

\[\frac{dZ}{dt} = \iota I – \kappa_{SZ} Z \frac{S}{N} – \sigma Z\]

The are multiple ways to become Dead in our simulation: begin killed by a Zombie, killed by a Survivor if you are Infected or starving to death while as a brain-hungry monster:

\[\frac{dD}{dt} = \kappa_{ZS} \cdot S \frac{Z}{N} + \kappa{ZI} \cdot I \cdot \frac{Z}{N} + \kappa_{SZ} \cdot Z \cdot \frac{S}{N} + \kappa{SI} \cdot I \cdot \frac{S}{N} + \sigma \cdot Z\]

The code in R:

```
library(deSolve)
library(ggplot2)
N <- 10000000 # 10M in total population
i0 <- 1 # Initial infected group
s0 <- N - i0 # Initial survivor group (whole population minus infected)
z0 <- 0 # No zombies at the beginning
d0 <- 0 # Everyone alive at the beginning
total_contact_rate <- 7
transmision_risk <- 0.4
parameters <- c(N = N,
transmision = total_contact_rate * transmision_risk,
ZkillS = total_contact_rate * 0.4,
ZkillI = total_contact_rate * 0.4,
SkillZ = (total_contact_rate * 0.4) * 0.7,
SkillI = (total_contact_rate * 0.1) * 0.1,
starveRate = 1/14,
incubation = 1/2)
state <- c(S = s0,I = i0, Z=z0, D = d0) # Initial state of variables
# Diff. Equations
SIZD <- function(t, state, parameters) {
with (as.list(c(state, parameters)), {
dS <- -transmision * S * (Z/N) - ZkillS * S * (Z/N)
dI <- transmision * S * (Z/N) - incubation * I - ZkillI * I * (Z/N) - SkillI * I * (S/N)
dZ <- incubation * I - SkillZ * Z * (S/N) - starveRate * Z
dD <- ZkillS * S * (Z/N) + ZkillI * I * (Z/N) + SkillZ * Z * (S/N) + SkillI * I * (S/N) + starveRate * Z
list(c(dS, dI, dZ, dD))
})
}
# Sampling time from 0 to 250 step each 1 day
times <- seq(0, 250, by = 1)
# Solve the equation
out <- ode(y = state, times = times, func = SIZD, parms = parameters)
```

Infected in orange, Zombies in black.

Survivors in green, Dead in red.

The plots above confirm what we already know from the movies: we are doomed to die in a zombie outbreak. There is however a way out – we just need to kill Zombies/Infected fast enough. By increasing the contact rate to 50% for Survivors killing Zombies we will keep the outbreak under control with approximately 70 casualties in total.

The dynamic of the model looks very simple with a very thin line between total apocalypse and survival. But on the other hand, isn’t this the reason why we love the Z-genre?

*Feature image cc-by Eneas De Troya*