NetLogo banner

 NetLogo Publications
 Contact Us

 Modeling Commons

 User Manuals:


NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".

Try It in NetLogo Web


A model of an infectious disease within a community.

People move about randomly, and if they run into a person who is sick, they have a chance of getting sick themselves. The illness runs on average two weeks, and has a 1% death rate.
These processes are all stochastic, so somebody could die on day 2 of the illness, or could have it for a month

Here is what makes this model unique:

I have seen a couple of models online which illustrate the effects of social distancing on the spread of a disease, but they typically did this by social distancing the entire population, which to me seems like a bit of an unnecessary oversimplification. For this model, I'm interested in breaking down social distancing into two of its components:
1. How many people are distancing? Is it half the population? 75%? 10%?
2. How aggressively are they distancing? Are they literally staying in one place? or are they just being more cautious, going out less?

This model allows us to explore how varying 1 and 2 affect the outcome of the entire community. Is social distancing useless unless most people do it? Is social distancing useless unless it's extreme? Can we effect a meaningful change in outcome by having only a small proportion of citizens social distance?

Additionally, I've created a self-balancing mechanism which can be turned on or off.
This self-balancing mechanism is to help try to model how a society would eaase out of social distancing while the virus was still present.
A couple of new variables that the self-balancing uses:

[threshold] - this is the "acceptable" infected proportion of the population (ie, "the healthcare system can't handle more than 5% of the population sick with this thing at any one time, so we have to keep it under 5%")

[distance-step-ups] - when the proportion of people currently infected ([prop-infected]) nears the threshold, the proportion of the population social distancing increases. If the [prop-infected] rises above the threshold, or daily net new cases are too high (indicating rapid growth), the proportion of the population taking social distancing measures increases. So, for example, if 11% of the population is infected, the number of people taking social distancing measures would increase by ([distance-step-ups] * [num-people]) amount every day until prop-infected falls below 10%.

[distance-step-downs] - the same as the above, but for easing social distancing restrictions. Once prop-infected falls below ([threshold]*.75) and net new cases are negative, the proportion of people social distancing is decreased by ([distance-step-downs] * [num-people]).

What should the step-ups and step-downs be? That’s a good question. The granularity with which a society can adjust how many of its citizens are social distancing unclear and subject to political pressures. On one end of the spectrum, we could imagine a government announcing every morning which birthdays were allowed to leave the house. On the other end of the spectrum, we could imagine a government announcing at the start of the month that everyone must stay inside, and at the end of the month, letting everybody out. The most realistic course of action is probably somewhere in the middle. I think most citizens would get awfully fed up with a government micromanaging and making frequent adjustments, however, we probably want something more attentive than the second scenario. This is an added challenge — we want a self-balancing system that takes large enough steps so as not to require super frequent adjustments, but also keeps the virus at acceptable levels. To start, I’ve set the [distancing-step-ups] (by what percentage of the population do we increase the total number of people distancing) at 10%. I’ve done the same for [distancing-step-downs] (by how much do we decrease the number of people social distancing). We can imagine city governments being able to adjust social distancing behavior with this sort of granularity by taking steps such as expanding and contracting the list of “essential businesses”. (Note: I am well aware of the fact that opening and shuttering businesses adds a whole new level of economic stress and greatly impacts these business’s ability to plan. That being said, I think what we’re interested in here is the effect of slowly opening or closing the economy on the spread of a virus, not the economic difficulties and feasibility of opening and closing the economy.)

(what rules the agents use to create the overall behavior of the model)

I'll go through the variables and what is a good range for them to be set at:

num-people = This is the number of total people in the community, for this size grid, I think 1500 is a decent starting point. Less people -> disease has harder time spreading, more people -> disease spreads more easily

init-infected = This is how many initial cases the community has. You can set it as low as you want

num-people-social-distancing = of the total number of people, how many of them are socially distancing? Play around with this one, you start to be able to really see the impact once it's over 60% of the population. Also try it with zero! REMEMBER: this number must be lower than num-people

sociability-of-non-distancers = how much do non social distancers move around? The higher this number, the larger their movements. Try different numbers for this.

sociability-of-distancers = how much do social distancers move around? This number should be pretty low, I think generally, below 1. Play around with it, but just remember that it should be lower than sociability-of-non-distancers.

NOTE: the sociability of an individual does not change if he becomes infected. Distancers will continue to distance even if they become infected, but they will change color to red.

Once there are no more active infections in the community, people stop social distancing.


(suggested things for the user to notice while running the model)


(suggested things for the user to try to do (move sliders, switches, etc.) with the model)


(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)


(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)


(models in the NetLogo Models Library and elsewhere which are of related interest)


To begin building this, I modified code for an SIR model by Paul Smaldino

(back to the NetLogo User Community Models)