# Understanding epidemic curves by simulating an outbreak

## What are epidemic curves?

Epidemic curves, in the context of a virus outbreak, give us information relating to the speed and magnitude of the propagation. Those curves represent how many people are infected as a function of time. The time interval can be measured in days, weeks, months, etc...

Using such data, predicting models might be able to predict how the propagation of said virus will evolve.

Here are what an epidemic curve looks like: (Source)

## Epidemic curves obtained using the SIR and SEIR model

The SIR and SEIR models are a way of representing a virus spreading in the population. I already went over the SIR model in this article but I'll explain it again briefly.

The *SIR* and *SEIR* models are the two most basic models in what's known as *compartmental models*. The compartmental models takes a population and splits it into different compartments, (that's where the name comes from) and people in one compartment can move to another compartment, following some rules. Different compartmental models have different compartments. For example, the most basic one, the SIR model, has three compartments: **S**usceptible, **I**nfected and **R**ecovered. The rules in this one are that people can only move from the susceptible compartment to the infected compartment and from the infected compartment to the recovered compartment.

Of course, such a model must have a mathematical interpretation to be exploitable, and therefore, each compartment is described by a differential equation:

β being the infectivity constant and γ being the healing constant, you might have seen this model represented like so:

The basic idea behind this model is that by solving this system of differential equations, We'll be able to graph I(t) (which represents the number of infected people as a function of time), and we'll get an epidemic curve.

But before doing that, let's explain the SEIR model as well, which stands for **S**usceptible, **E**xposed, **I**nfected, and **R**ecovered. This model introduces a new compartment, the *exposed* compartment, which takes into account the fact that people can be exposed and infected to the virus without being contagious (there are way more variants, such as the SEIR model where people who recovered can go back to being susceptible, but we'll keep it simple here). We might represent this model like this:

Where σ can be the rate at which a person becomes Contagious. The equations then become:

Those systems of differential equations aren't easy to solve analytically, so I recommend reading my article on how to solve the SIR model by using Euler's method to understand how I'm able to graph the number of infected people as a function of time. And here are the results:

For the **SIR** model

And for the **SEIR** model

## Simulating a virus outbreak

The next step is to simulate each individual in a population and track how many people get infected to create an epidemic curve. But how should we do that? We can create a 2d grid where each individual is represented by a colored dot, they move randomly and can interact with each other (infect each other). Each dot will be colored depending on its state (susceptible, infected, or recovered), if the infected dots get close to susceptible dots, they have a certain chance of infecting them. The program will constantly count how many individuals (dots) are infected and yield an epidemic curve. Here's what such a simulation would look like:

## Curves obtained

I will probably write an article in the future regarding how to make such a simulation, but for the sake of not wasting time, for now, I'll only talk about the results. This is one of the graphs we can get from this simulation:

What's really interesting is that by setting up a simulation like this, we get a result resembling the SIR/SEIR model (SIR model in this case). We could also implement some behavior in the individuals to see how this behavior impacts the propagation of the virus (such as maintaining a distance or staying in a predetermined zone). But that's for another time.

In the meantime, thanks to anyone who read my article till here, and please consider subscribing to my newsletter, it's free and keeps me motivated!