Subscribe:

# Corona virus transmission simulation

Lee Phillips
April 13th, 2020

## What it is

At the bottom of this page you will find a machine for modeling the spread of an infection through a population. The machine implements a simple algorithm that models the world as an array of squares, like a chessboard. Each square is occupied by a person who can not move. A person can be an any of four states: normal, isolated, infected, or dead. Each day, each person interacts with all eight of his neighbors. What happens is partly determined by probabilities that can be set by the user. An isolated person never changes state; neither does a dead person. If an infected person and a normal person are neighbors (in contact), then the normal person may become infected; the likelihood of that happening each day is given by the probability of infection. An infected person may die, but only at the end of a certain number of days; how quickly the disease can kill is also a parameter that the user can set. At the end of this period, the infected person either dies or survives forever. Dead or isolated people can not spread infection, so their existence protects other people near them; a normal person who is completely surrounded by dead or isolated people can never become infected.

The initial proportions of the population that are infected and isolated, and the size of the population, are also set by the user. Each square is colored according to its state, with a legend shown below the arena.

Although it is obviously highly idealized, models such as this may be able to capture some of the dynamics of the spread of an infectious disease through a population, and may provide some insight into the effects of different initial conditions and probabilities on outcomes.

## How to use it

Enter the number of people you want included in the simulation, the population, in the large box above the big grey square. The actual population used will be the closest perfect square to your number, because all the people need to fit onto the square chessboard. Also, the maximum is 20,164 (1422), because much more than that starts to become too slow. The program runs in your browser, using your computer resources, so there are limits to what we can do. The minimum population is 4.

If you want to change the default settings for the parameters that influence the simulation, adjust the five sliders on the right. To make fine adjustments, it’s easier to use the arrow keys rather than trying to drag the sliders (and, while the program works on phones and tablets, it’s a bit easier to use, and probably faster, on a laptop or desktop). You can change the focus among the sliders using the tab key, if you want.

Here are the five parameters and what they do:

 isolation probability The probabilty, for each person, of being isolated on day 1. For large populations, will be close to the proportion of the population that is isolated. initial infection probability The probabilty, for each person, of being infected on day 1. For large populations, will be close to the proportion of the population that is initially infected. transmission probability The probability, on each day, of an infected person infecting each neighbor (enter “0.01” for a 1% infection probability). The higher this number, the faster the infection spreads. death rate The probability that an infected person will die after the number of days set in the next parameter. days until death This many days after becoming infected, the person either dies (with probability given by death rate, above) or survives; survivors will never die of the infection.

In addition to those, there are two parameters that you can adjust that do not affect the calculation, but simply how it is displayed. The `fast.....slow` slider inserts an optional delay between days, so you can watch the evolution of the infection more slowly. The `show day for....` slider pauses the initial state for a while so you can examine it before the calculation proceeds.

Click the `start` button at the top to start the calculation. To stop it before it’s done, you can click the `stop` button; clicking the `start` button will start a new calculation, rather than continuing the current one.

While the infection is spreading the program draws a graph showing you the levels of infection and of death vs. day. When the program believes the world to have reached a steady state, it stops, and displays what may be the most important bit of information, displayed on top of the graph: the percentage of the population that was protected, or prevented from becoming infected, by the existence of isolated people and people who died before transmitting the infection to all of their neighbors.

When the calculation stops, two buttons appear immediately above the graph. The `table` button displays the table of numbers represented in the graph, so that you can copy and paste it for further analysis. The `more controls` button brings up the two display control sliders, in case you want to adjust these before the next run.

## What to do with it

You can test hypotheses about the effects of different assumptions on the course of the pandemic and the ultimate levels of infection and fatality. For example, keeping all else constant, what is the effect of changing how long it takes the disease to kill susceptible people on the level of infection in the surviving population, or on the number of protected people? Is the progression of the infection more sensitive to the fatality rate or the isolation rate? What causes the initially exponential rise in the infection curve to start to become saturated, or transition to linear growth? Which combinations of parameters produce the best looking animations?

For students of statistics: how can we apply the language of conditional probability, frequency distribution, mean, median, standard deviation, etc.? How large a population should we use to get reliable results?

## How to embed it

You can embed this machine into your own web page by including the line

``````<script
src = 'https://lee-phillips.org/corona/infect-model.js'>
</script> ``````

``<infect-model></infect-model>``

where you want it to appear.

You can adjust the size of the machine relative to the other contents of your page with an optional parameter:

``<infect-model cl = 30></infect-model>``

where `cl` gives the width (and height) of the main arena in, roughly, character widths. The example shows the default of 30. At the moment, this parameter has a minimum of 24; you can enter smaller numbers, but that won’t have any effect.