powered by NetLogo


In this Infection-Protection Game, I send a virus through an evolutionary cooperative model. Infection status affects the payoffs for protective action. Individuals can only learn from the last move and only from their immediate neighbors. Can such myopic individuals learn to cooperate, to protect themselves and others from infection? I compare several variants of learning & evolution. In one variant, individuals only compare benefits and costs of cooperating, learning only from their neighbors what worked best. In another variant, neighbors only see health as an outcome and see which neighbors are healthy and whether or not they took protective action. They also consider how many healthy neighbors one has. Individuals learn whether or not neighors ended up living in contact with many sick persons or healthy persons. A very different approach has individuals estimate their specific risk, based on number of neighbors infected and the probability of infection per encounter, but also the risk of taking action (e.g. side effects of vaccination). I compare these variants of learning the local situation with learning the global situation, specifically using a global overall proportion infected as a threshold for action. Try comparing these different learning approaches.

By cooperation I mean taking health protective action of several types: an infected person “containing” their illness from a healthy person, a healthy person “shielding” their self from an infected person, or vaccination. We can define many health behaviors as combinations of shielding and containing. For example, a sick person can contain their infection, with a certain efficacy, by washing before encountering a healthy person. A sick person also can contain their infection by wear a surgical mask to protect healthy persons they encounter. A healthy person can shield their self from an infected person, by washing after encountering the sick person, or wear a very protective mask, e.g. an N95 masks that protects the wearer from others with infection.

All those behaviors have some cost proportional to the number of times they must carry out the shielding or containing. To protect the healthy, the sick person must contain, e.g., wash in proportion to the number of healthy persons they encounter, e.g. must wash in proportion to the number of healthy persons they meet. To protect themselves, the healthy person shields themselves from each of their infected contacts.

When a healthy person meets an infected person, there are four combinations of shielding and containing, corresponding to both cooperating, both defecting (not taking protective action), or just one taking protective action.

Each protective behavior has a level of efficacy in protecting against infection, e.g. 100% is perfectly protective, whereas 50% works in half of the encounters. The most interesting situations are when efficacy is less than 100% because then 2 or more cooperators, multiple persons taking protective action, will together have a lower chance of transmitting the infection than if just one person cooperates. For this reason, even when their is only a benefit for health, an individual can increase their chances of a higher payoff if both cooperate. Yet because their is a cost to cooperating, their also is an incentive to defect.

Once the disease dies out, it does not return. Once cooperation dies out, it likewise does not return. Disease only spreads by contact between neighbors, in this case the 8 neighbors in the lattice network. Analogously, cooperation spreads by imitation of neighbors. Individuals will only copy cooperation if they both see it practiced among their neighbors and then only if it yields the highest payoff.

To keep the model as simple as possible, so that we can study thoroughly the interaction of cooperative protective behaviors and infection, I have immunity turned off as a default. Infected persons can be reinfected after they recover, but while infected have no risk of infection (affecting the estimated payoffs). Once we have understood our dynamics with simply varying infection as a yes/no variable, we can turn to exploring the effects of immunity.

See my book, Chapter 3 for details.


Set the proportion of cooperators. Cooperators perform the selected health protective behaviors. Switch on the protective behaviors you wish to see implemented. Try first healthy persons shielding themselves from infection, then add sick persons containing their illness. There are then four combinations of those, e.g. both a sick and healthy person cooperating by shielding and containing respectively, or both not taking protective action. Vaccination is slightly less interesting because it is a one-time behavior (in my simplified model), the effects last. and is not depend so much on interaction with others. By contrast the shielding and containing are like washing or hiding (social distancing) and are a function of time because one can quit these behaviors at any time. Also these behaviors are a function of the number of contacts, sick and healthy one has. All protective behaviors have some cost, which you can adjust, but these are also a function of time, and encounters with sick or healthy persons.

I have designed these protective behaviors so that they can, in their various combinations, represent a great variety of health behaviors. For example surgical mask protects others from the wearer who is sick = sick-contain. By contrast an N95 mask protects the healthy wearer from sick others = healthy-shield. Set a healthy person washing after encountering a sick person as healthy-shield. Set a sick person isolating himself, or washing before seeing a healthy person as sick-contain.

You can set the efficacy of protective behaviors. First try setting efficacy to 100% to see the pure dynamics. However, more interesting as well as realistic are situations when efficacy is significantly less than 100%. For example, if each of two persons cooperate by shielding and containing, and each of these have an efficacy 50%, then the total chance of protection is 75%. So even if the infectiousness is 100%, the actual chance of transmission is only 25% if both persons cooperate by shielding and containing.

Protective behaviors are all “cooperative.” So a cooperative person initiall will execute the protective behaviors you select.

The default is an initial 50% cooperators, randomly distributed throughout the space. Use the chooser if you want to select 70% cooperators, or a cooperative block (don’t try this until you’ve first experimented with the 50% or 70% random distribution of cooperators).

After that initial distribution of cooperators, agents can adjust their behavior based on the results they observe and consider. You can compare different types of criteria for choosing to cooperate or not (after the the very first choice). Whatever you choose, agents will use repeatedly, sometimes learning, adapating in a way which not only benefits their selves, but also reduces the collective risk, lowering the overall infection.

Several of the criteria have agents consider benefits and also costs. Each cooperative act also has a cost, which you can set with a slider. Individual agents can then compute payoffs in different ways, which you can set with the menu, “criteria-for-action.” Agents then use that criteria to compute payoffs, which they then use to decide whether or not to cooperate. Select “Risks & benefits for action vs none” and individuals calculate their risk based on total number of infected neighbors, and the risk of infection per contact. They also take into consideration the perceived risk of the action itself, which may be high in the case of vaccine (you can set this high in this case) or negligible for many other behaviors. This calculation more complex with this criteria. Not taking protection action yields payoff that varies with local infection.
However, efficacy of protective action depends on number of contacts. Efficacy & cost of many behaviors depend on number of contacts & their condition. If an infected person meets healthy person, either can take action to reduce healthy person’s chances of infection by a probability, the Efficacy of the Protection Action, shielding or containing.

See the book, chapter 3, for more details.

Other criteria are much simpler, requiring individual agent’s do much less work in estimating payoffs. Select “Health benefit & cost, spatial” and individuals calculate Payoff for protecting based on a benefit for being healthy, having healthy neighbors & a cost for protecting (shielding or containing). The payoff for defecting is computed in the same way, a benefit for health of self and neighbors, except the defector pays no cost of protecting.

For example, a person healthy with 5 healthy neighbors, doesn’t pay cost of protecting, so has a payoff of 6b (one benefit for self and 5 for the healthy neighbors). A protecting infected person with two healthy neighbors sees a benefit for each, but pays the cost of cooperating with each of those healthy persons = 2b minus 2c.

A somewhat similar criteria, but just as simple, “Cooperation benefit & cost, spatial,” does consider health as a benefit, but rather calculates only a set benefit received from each protector, and a cost for protection to each neighbor. As in all the models, cooperative behaviors are health protective, and so apply between healthy and infected neighbors. With this criteria, individual’s know exactly what benefits and costs are associated with cooperation, although they can only learn cooperation if local neighbors are suceeding with cooperation.

By contrast, when benefits are associated with health of self and neighbors, benefits and costs are not directly linked to protection and defection, but rather those behaviors can lead to different health outcomes, which in turn yield the payoff. Individuals essentially learn cooperation or defection after observing results. More precisely cooperation or defection may evolve as a function of the viral dynamics interacting with the protective behaviors in the network.

Use the Infectiousness slider to set the liklihood that an infected person infects a neighboring susceptible person another at a given encounter, when are next to each other. Each person has 8 neighbors. For example, set the slider is set to 50%, and the infection will spread in half the encounters between eligible neighbors.

Us the duration slider to show the number of days an infection lasts, per person. After this duration, an individual who was infected either becomes healthy again (if allow-immunity is off), or becomes immune.

The % recovery slider shows, and allows you to adjust, the likelihood an infection will end in recovery.

Once you set the slider, switches, and selectors as you wish, hit SETUP to execute. Distributions are randomly assigned to spaces (with the exception of set cooperative block). Then hit GO button to initiate the infection and the learning process, a simple evolutionary process.

Global summaries appear in the plot, as a function of time, and are updated continuously in the monitors.

You can compare what happens when individual’s use any of these local criteria, payoffs based on the local situation, versus a global criteria based on total level of infection. For the latter, an agent will only take protective action when the proportion infected in the total population reaches a certain threshold, which you can adjust. You will see then that the infection will not fall lower than that global threshold, and when near that threshold, behaviors will continuously alternate from cooperative to uncooperate behaviors. By contrast, a local threshold is much more effective, as well as less costly (requiring less useless global protection).

Nonetheless, even a local threshold could result in oscillations if it is too high. Infection drops, population grows, infection rises above threshold again. Such oscilaltions are much higher when the threshold is a global level of infection, largely because of the delay feedback mechanism, the time between taking action and seeing global results.

In general, delays in feedback between action and result, even locally produces oscillations. Even when individuals react to local conditions it may take time to see local changes. When individuals calculate payoffs and decide whether or not to cooperate based on health status, it takes time to see the effects on health of self and neighbors. We see the infection rising first, then cooperation following, then the resulting recoveries, which in turn result in less cooperation, resulting in cycles unless the disease is wiped out.

Infection –> cooperation (mask) –> more recoveries –> less cooperation

Vaccination is a considerably simpler behavior than the containment and shielding between infected and healthy persons, because vaccination is a one-time behavior and the immunity lasts (in this simplified model, and approximately in the real world).

By contrast the containment and shielding, e.g. washing before and after encounters, wearing masks, hiding or isolating oneself, are all temporary and must be repeated or prolonged depending on the local risk and immediate situation. The latter are flexible, just in time, local behaviors. In the graphical interface of the model, you can easily see the spatial dynamics. Individuals make many errors at first, but sometimes begin to learn to cooperate, e.g. shield and contain, especially shield. After some time we see healthy individuals near infected ones “learning” to wash, following remaining infection & killing it. Essentially the cooperators of healthy persons surround an infected person, and the disease is wiped out.

Once the infection is wiped out, at least locally, we then see healthy persons “learn” that washing doesn’t pay off. When all infection is wiped out, shielding completely dies out as now this is only a cost and yields no benefit. Individual agents, learning from neighbors’ strategies, adapt to changing conditions, the changing level of infection.

Even vaccination is less effective when responding to a global threshold for action as compared to responding to a local infection threshold.

Most effective of all is local behavior in which individuals calculate their risk based on total number of infected neighbors, and the risk of infection per contact. Individuals next to many infected persons (high risk) have a much lower than average payoff for not taking protective action. Individuals taking action based on such local risk is effective in halting infections even when these are at low levels. Individuals can react to local infections very effectively, and wipe out the disease. By contrast, reacting only to global levels, is not effective when below threshold levels of % infected. That mechanism doesn’t wipe out the infection. If agents looked at global infection levels, few or none would cooperate when very low risk, infection would remain higher.

Individuals likely use not only global but local info, e.g. local contacts infected to calculate risk of infection and risks, efficacies and costs. See chapter 3, in Modeling Behavior, by Chris Keane.


Dr. Chris Keane designed the program and underlying concepts (Keane 2012, 2013), including the elemental categories of health protective behaviors, containment and shielding, and the schema for combining evolutionary cooperative dynamics with spread of infection. Dr. Keane studied the basic evolutionary game mechanics described by Nowak and others in numerous studies and simulations. Dr Keane’s basic notion was to send a virus through an evolutionary cooperative model (Keane 2013). Infection status affects the payoffs for protective action. All this I describe in detail ni Chapter 3 in Keane (2013). Modeling Behavior in Complex Public Health Systems. Springer.

As usual, the Netlogo interfaces, suggested procedures, graphics and general approach is an invaluable resource and inspiration. See Nelogo, at the Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL: http://ccl.northwestern.edu/netlogo/models/Virus.