Contagion on a Grid

Contagion on a Grid preview image

2 collaborators

Default-person Darin England (Author)
Default-person Amanda Page (Team member)


(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.1 • Viewed 37 times • Downloaded 0 times • Run 0 times
Download the 'Contagion on a Grid' modelDownload this modelEmbed this model

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


This model is an implementation of best-response decision-making when players are arranged on either a line or a grid. Each agent can choose one of two possible actions:

action 0 or action 1. Each agent will attempt to maximize her own payoff by coordinating her action with the actions of her neighbors. The purpose of the model is to understand the conditions under which all agents end up taking action 1 (contagion).


Agents play a coordination game with each neighbor. When two neighbors each take action 0, the payoff to each is q. When two neighbors take action 1, the payoff to each is 1-q. The payoff for miscoordination is zero. In other words, each pair of agents that are connect by an edge play the following two-person game.


0 1


0 | q,q | 0,0 |

1 | 0,0 | 1-q,1-q |



Before taking an action, agents check to see how many of neighbors are taking action 1. Each agent then chooses the action (either 0 or 1) that will maximize her own total payoff. Initially all agents are set to take action 0. The user can select which agents will (at least initially) take action 1.

Contagion (when all agents end up taking action 1) only occurs under certain conditions. For example, for agents arranged along a line (1-dimension), contagion can only occur when q <= 1/2. In 1-dimension the threshold of 1/2 is called the contagion threshold, the largest value of q for which contagion is possible (please see the article by Morris that is referenced below). Contagion is also possible only when certain agent sets are intitially taking action 1. In 1 dimension, contagion will occur when two neighboring agents initially take action 1 (and q <= 1/2).

The color of an agent indicates which action is currently beging taken. Black indicates action 0 and white indicates action 1.


The q slider sets the payoff when agents coordinate on action 0. The DIMENSION chooser sets the grid to be either 1 or 2 dimensions.

The SELECT NODES button allows the user to select agents with the mouse. The selected agents will take action 1 (at least initially).

SETUP resets all agents to take action 0.

When GO ONCE is pressed, agents play the coordination game one time. Pressing GO causes the agents to play the game repeatedly (at each tick).


Under certain starting conditions that actions of all agents stop changing after some number of rounds. This means that agents have no incentive to switch their action. In other words, an equilibirium has been found. Under other conditions, equilibrium does not occur. We note that in this model agents are always allowed to switch their action. This differs from much of the literature where once an agent switches from action 0 to action 1, she is not allowed to switch back to action 0.


Try to find conditions under which contagion occurs. In 1 dimension, contagion will occur when two neighboring agents initially take action 1 (and q <= 1/2). Are there other configurations of agents initially taking action 1 that will lead to contagion. What about 2 dimensions.


For the 2 dimensional grid in this model, each agent has four neighbors. One could modify the grid so that the "diagonal" agents are also neighbors (each agent would have eight neighbors).

Try implementing the contagion model on a tree.

Try implementing the contagion model on other types of networks.


Networks are represented using turtles (nodes) and links. The user is able to use the mouse to select the agents that initially take action 1.


Language Change


This model is an implemetation of the example described in Morris (2000), "Contagion", Review of Economic Studies: Vol 67, pp 57-78.


If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

* England, D. and Page, A. (2020). NetLogo Contagion on a Grid.

Please cite the NetLogo software as:

* Wilensky, U. (1999). NetLogo. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.


Copyright 2020 Darin England

![CC BY-NC-SA 3.0](

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

; a model for contagion in 1 or 2 dimensions
; this model corresponds to the following article:
; Stephen Morris, Contagion, Review of Economic Studies, Vol 67, 2000

breed [nodes node]

nodes-own [
  action        ; action (either 0 or 1)
  orig-action   ; each person's initially assigned action
  action-1-sum  ; number of neigbors that will take action 1 (or based on beliefs)

to setup
  set-default-shape nodes "circle"
  ask patches [ set pcolor gray ]
  ifelse dimension = 1 [
  ] [

to make-nodes-1 ; create the nodes for a 1-dimensional lattice
  foreach (range -40 41 5) [ i ->
    create-nodes 1 [
      set xcor i
      set ycor 0
      set size 2
      set action 0
      set color black

to make-nodes-2 ; create the nodes for a 2-dimensional lattice
  foreach (range -40 41 5) [ i ->
    foreach (range -40 41 5) [ j ->
      create-nodes 1 [
        set xcor i
        set ycor j
        set size 2
        set action 0
        set color black

to distribute-actions ; initialize nodes to start with action 0
  ask nodes [
    set action 0
    set orig-action action

to create-network ; create links to neighbors
  ask turtles [
    let nbrs other turtles in-radius 5
    ; other omits the turtle itself
    create-links-with nbrs [ set color white ]
    ; only one undirected link between any two turtles is created

to update-color
  ; nodes that take action 0 are black, action 1 are white
  set color ifelse-value action = 0 [black] [white]

to go
  ; in the ask commands below the order of node exection is random, hence the separate steps
  ask nodes [ check-neighbors ] ; first all nodes note the actions of their neighbors (or form beliefs)
  ask nodes [ take-action ]     ; then all nodes take the action with the highest expected payoff
  ask nodes [ update-color ]

to check-neighbors
  set action-1-sum sum [action] of link-neighbors

to take-action
  ; an agent will take the action that maxmizes the sum of her payoffs
  ; from the interactions with each of her neighbors.
  ; action 1 is a best response to the actions of her neighbors if
  ; at least proportion q of her neighbors choose action 1.
  let num-neighbors count link-neighbors
  set action ifelse-value (action-1-sum / num-neighbors >= q) [1] [0]

to action-dbg  ; debugging, show actions of all nodes
  foreach sort-by[ [a b] -> [xcor] of a < [xcor] of b ] nodes [ i ->
    ask i [
      let num-neighbors count link-neighbors
      show (action-1-sum / num-neighbors)

to select-nodes ; use the mouse to select which nodes take action 1
  if mouse-down? [
    ask turtles with [distancexy mouse-xcor mouse-ycor < 2] [
      set action 1
      display ; update the display

There are 2 versions of this model.

Uploaded by When Description Download
Darin England 4 months ago Edit to info tab Download this version
Darin England 4 months ago Initial upload Download this version

Attached files

File Type Description Last updated
Contagion on a Grid.png preview Preview image 4 months ago, by Darin England Download

This model does not have any ancestors.

This model does not have any descendants.