COVID-19 VIRUS SPREAD preview image

1 collaborator

Img_3285 Nich Martin (Author)



Tagged by Nich Martin 8 months ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.0.2 • Viewed 1735 times • Downloaded 37 times • Run 0 times
Download the 'COVID-19 VIRUS SPREAD' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


COVID-19 Virus Spread Model is an Agent-Based-Model built from the skeleton of an SIR model developed by Paul Smaldino currently (2020) at the Cognitive and Information Sciences Department at the University of California, Merced; and was further developed by Nich Martin at the University of Florida, Department of Entomology and Nematology as a tool to help educate the public on how interaction models concerning the current COVID-19 pandemic are used to make predictions and recommendations to the public.


An initial population of agents (blue-colored humanoids) are randomly placed in the model space with an initial population of infected individuals (red). As time moves forward, agents move randomly through the model space according to specified parameters such as number of stationary individuals and mobility. Infected individuals transmit the virus to susceptible individuals by coming within a certain distance of each other. Whether the susceptible individual becomes infected is determined by a random probability, the likelihood of which increases as transmission rate increases. The model can be run with and without immune individuals; when ran with immunity, infected individuals will become immune (color changes to gray) according to a random probability, the liklihood of which increases with increasing recovery rate. Mortality rate can be adjusted. The ability of hospitals to cope with the proportion of infected individuals can be adjusted as well. Once the proportion of infected individuals is greater than health care capacity mortality increases an order of magnitude, as predicted by other current models.


After adjusting the parameters, described below, simply click the setup button and click go. The model will continue to run until there are either no more infected individuals or no more susceptible individuals.

Initial Population

Control population size by adjusting the init-population slider.

Initial Number of Infected Individuals

Controls initial number of infected using the init-infected slider.

Transmission Rate

Current estimates are between 0.50 and 0.70. Set transmission rate by moving the transmission.rate slider.

Number of Stationary Individuals

The stationary slider allows the user to control the number of individals not moving (represents physical/social distancing) in the model space.


The mobility slider allows the user to set how much distance non-stationary individuals move throughout the model space.

Recovery Rate

Set the recovery.rate slider low for longer recovery time and high for quick recovery. Suggested recovery rate for the current virus is 0.15.


Activate individuals' ability to recover from infection by turning on the immunity? switch.

Initial Number of Immune Individuals

Use the init-immune slider to adjust the number of individuals immune to the virus before the model runs.

Mobilize the Immune

By activating the mobilize-immune? switch, individuals who were once stationary are allowed to move throughout the model space once they become immune.

Quarantine Effort

By adjusting the quarantine.effort slider, users can control infected individuals' ability to infect susceptibles.

Health Care Capacity

The healthcare.capacity slider changes the proportion of infected individuals hospitals can provide care for. Once the proportion of infected individuals exceeds health care capacity (which I'm told should realistically be set at least below 0.30) mortality rate increases one order of magnitude from where it was initially set.

Mortality Rate

The infected.mortality slider changes the base-line mortality rate for those infected. Estimates for mortality rate range from 1 to 10%, averaging around 3.6 when not accounting for health care capacity.


You can watch the model space and individuals moving throughout it to see how disease spreads throughout a population.

The model has two plot outputs. The first shows the number of susceptible, infected, and immune individuals through time. This same figure also shows a line for health care capacity.

The plot below the first shows the total number of individuals who have died as the model moves through time.

There are also a number of indicator values including the maximum propotion of individuals infected, the proportion uninfected, the number of people who have died, and the current population size.


Try adjusting the init-population slider to see how more sparse, rural areas are affected vs. densely populated cities.

Adjust the stationary slider to see how many people "social distancing" it takes to "flatten the curve".

Adjust the init-immune slider to see what outcomes would look like if a vaccine was available, and how many individuals getting vaccinated it would take to see the effects of "herd immunity".

By adjusting the quarantine.effort you can see what the effects of isolating individuals already infected has on the dynamics of the system.


If you have any suggestions for things to add or change in the model feel free to contact me at I (Nich Martin) am not an epidemiologist, so if there are epidemiologists out there who feel the model needs drastic improvement, please contact me. But please also bear in mind, this was developed as an educational tool so changes will likely only be made if they serve an educational benefit. Netlogo users are encouraged to adjust the code as they see fit; I would be delighted if you send me your updates; I am new to agent-based modeling and would like useful feedback.


This model is based off an initial model by Paul Smaldino "SIR Model with random movement"


CREATIVE COMMONS LICENSE This code is distributed by Nich Martin under a Creative Commons License: Attribution-ShareAlike 4.0 International (CC 4.0)

Comments and Questions

Error init-population (Question)

I can't run the program. I get ERROR nothing named init-population has been defined

Posted about 1 month ago

RE: Error init-population

Hi Neil, Did you download the complete model, or copy the code script and paste it into Netlogo running on your desktop? If you did the latter, the code does not have an interface with which to interact and the variables of the model will be undefined. Are you able to run the model in NetLogo Web?

Posted about 1 month ago

Thanks. That was my mustake.

Thanks. That was my mustake. Where do I get the model?

Posted about 1 month ago

Found it.

Found it. Thanks for your patience.

Posted about 1 month ago

Code language (Question)

Can I get this code in Python language to implement on a micro:bit device?

Posted about 1 month ago

Re: Code language

Hi Pranav, sorry to say I have not programmed this model in Python. Right now, I'm learning to write ABModels in base R, and once I have that figured out, I plan to extend them to other programming languages (e.g., Python). Thanks for the interest.

Posted about 1 month ago

Click to Run Model

;;SIR Model with random movement
;;Agents move around at random.
;;They are either Susceptible, Infected, or Recovered (or, equivalently, removed)

globals [max-infected]


to setup
  set max-infected (count turtles with [infected?])

to setup-turtles
  create-turtles init-population [
    set color blue
    set shape "person"
    set size 2
    set infected? false
    set immune? false
    set stationary? false
    setxy random-pxcor random-pycor

to setup-infected
  ask n-of init-infected turtles [
   set color red
   set infected? true

to setup-stationary
  ask n-of stationary turtles[
  set stationary? true

to setup-immune
  ask n-of init-immune turtles[
    set immune? true
    set color grey

to go
  ;;stop if everyone or noone is infected
  if (count turtles with [infected?] = 0)
  or (count turtles with [infected?] = init-population)


to infect-susceptibles ;; S -> I
  ask turtles [
    let infected-neighbors (count other turtles with [color = red] in-radius 1 * (1 - quarantine.effort))
    if (random-float 1 <  1 - (((1 - transmission.rate) ^ infected-neighbors)) and not immune?)
    [set infected? true]

to recolor
  ask turtles with [infected?]
  [ set color red]

to move
  ask turtles
    if (stationary? = false)
      right random 360 ;;get a new random heading
      forward random-normal mobility 0.01]
    ifelse mobilize-immune?
    [if (stationary? = true and immune? = true)
      [set stationary?  false]]
      [if (stationary? = true and immune? = true)
      [set stationary?  true]

to recover-infected ;;I -> R
  ask turtles with [infected?]
    if random-float 1 < recovery.rate
      set infected? false
      ifelse immunity?
        set immune? true
        set color gray
        set color blue

to-report prop-infected
  report (count turtles with [infected?] / count turtles)

to kill-susceptibles
  ask turtles with [infected?]
  [ifelse prop-infected < healthcare.capacity
  [if (random-float 1000 < (infected-mortality))
  [if (random-float 1000 < (10 * infected-mortality))

to-report num-dead
  report (init-population - count turtles)

to-report population
  report (count turtles)

to calculate-max-infected
  let x (count turtles with [infected?])
  if x > max-infected
  [set max-infected x]

to-report max-infected-prop
  report max-infected / init-population

to-report prop-uninfected
  report (count turtles with [not infected? and not immune?]) / init-population

There is only one version of this model, created 8 months ago by Nich Martin.

Attached files

File Type Description Last updated
COVID-19 VIRUS SPREAD.png preview Preview for 'COVID-19 VIRUS SPREAD' 8 months ago, by Nich Martin Download

This model does not have any ancestors.

This model does not have any descendants.