Virus with Vaccinations and Immunity Time Final

No preview image

1 collaborator

Default-person Kay Ramey (Author)


(This model has yet to be categorized with any tags)
Model group LS426-2012 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0RC7 • Viewed 28702 times • Downloaded 167 times • Run 0 times
Download the 'Virus with Vaccinations and Immunity Time Final' 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 simulates the transmission and perpetuation of a virus in a human population.

Ecological biologists have suggested a number of factors which may influence the survival of a directly transmitted virus within a population. (Yorke, et al. "Seasonality and the requirements for perpetuation and eradication of viruses in populations." Journal of Epidemiology, volume 109, pages 103-123)


The model is initialized with 150 people, of which 10 are infected. People move randomly about the world in one of three states: healthy but susceptible to infection (green), sick and infectious (red), and healthy and immune (gray). People may die of infection or old age. When the population dips below the environment's "carrying capacity" (set at 700 in this model) healthy people may reproduce healthy and susceptible offspring.

Some of these factors are summarized below with an explanation of how each one is treated in this model.

The density of the population

Population density affects how often infected, immune and susceptible individuals come into contact with each other. You can change the size of the initial population through the PEOPLE slider.

Population turnover

As individuals die, some who die will be infected, some will be susceptible and some will be immune. All the new individuals who are born, replacing those who die, will be susceptible. People may die from the virus, the chances of which are determined by the slider CHANCE-RECOVER, or they may die of old age. In this model, people die of old age at the age of approximately 27 years. Reproduction rate is constant in this model. Each turn, every healthy individual has a chance to reproduce. That chance is set so that each person will on average reproduce four times if they live 27 years.

Degree of immunity

If a person has been infected and recovered, how immune are they to the virus? We often assume that immunity lasts a lifetime and is assured, but in some cases immunity wears off in time and immunity might not be absolutely secure. Nonetheless, in this model, immunity does last forever and is secure.

Infectiousness (or transmissibility)

How easily does the virus spread? Some viruses with which we are familiar spread very easily. Some viruses spread from the smallest contact every time. Others (the HIV virus, which is responsible for AIDS, for example) require significant contact, perhaps many times, before the virus is transmitted. In this model, infectiousness is determined by a slider.

Duration of infectiousness

How long is a person infected before they either recover or die? This length of time is essentially the virus's window of opportunity for transmission to new hosts. In this model, duration of infectiousness is determined by a slider.


Each "tick" represents a week in the time scale of this model.

The INFECTIOUSNESS slider determines how great the chance is that virus transmission will occur when an infected person and susceptible person occupy the same patch. For instance, when the slider is set to 50, the virus will spread roughly once every two chance encounters.

The DURATION slider determines the percent of the average life-span (which is 1500 weeks, or approximately 27 years, in this model) that an infected person goes through before the infection ends in either death or recovery. Note that although zero is a slider possibility, it produces an infection of very short duration (approximately 2 weeks) not an infection with no duration at all.

The CHANCE-RECOVERY slider controls the likelihood that an infection will end in recovery/immunity. When this slider is set at zero, for instance, the infection is always deadly.

The SETUP button resets the graphics and plots and randomly distributes 140 green susceptible people and 10 red infected people (of randomly distributed ages). The GO button starts the simulation and the plotting function.

Three output monitors show the percent of the population that is infected, the percent that is immune, and the number of years that have passed. The plot shows (in their respective colors) the number of susceptible, infected, and immune people. It also shows the number of individuals in the total population in blue.


The factors controlled by the three sliders interact to influence how likely the virus is to thrive in this population. Notice that in all cases, these factors must create a balance in which an adequate number of potential hosts remain available to the virus and in which the virus can adequately access those hosts.

Often there will initially be an explosion of infection since no one in the population is immune and the population density is at its maximum. This approximates the initial "outbreak" of a viral infection in a population, one that often has devastating consequences for the humans concerned. Soon, however, the virus becomes less common as the population dynamics change. What ultimately happens to the virus is determined by the factors controlled the sliders.

Notice that viruses that are too successful at first (infecting almost everyone) may not survive in the long term. Since everyone infected generally dies or becomes immune as a result, the potential number of hosts is often limited. The exception to the above is when the DURATION slider is set so high that population turnover (reproduction) can keep up and provide new hosts.


Think about how different slider values might approximate the dynamics of real-life viruses. The famous Ebola virus in central Africa has a very short duration, a very high infectiousness value, and an extremely low recovery rate. For all the fear this virus has raised, how successful is it? Set the sliders appropriately and watch what happens.

The HIV virus which causes AIDS, has an extremely long duration, an extremely low recovery rate, but an extremely low infectiousness value. How does a virus with these slider values fare in this model?


Add additional sliders controlling the carrying capacity of the world (how many people can be in the world at one time) and the average lifespan of the people.

Build a similar model simulating viral infection of a non-human host with very different reproductive rates, lifespans, and population densities.

Add a slider controlling how long immunity lasts so that immunity is not perfect or eternal.


  • AIDS
  • Virus on a Network


We added the possibility of an individual becoming immune via vaccination, i.e. becoming immune without having to suffer through sickness. This is controlled through the VACCINATION-RATE slider, which determines the likelihood that an individual who is currently neither sick nor immune will go and get vaccinated during each tick. These rules mimic reality, because individuals who already have immunity (e.g. to chicken pox) will not go and get vaccinated, and also because many vaccines are effective only if administered prior to exposure.

Additionally, we added a time limit to control how long immunity lasts. This works in a binary way: during this period, immunity is perfect, but once the period is over, there is no immunity whatsoever.

One key observation with the introduction of vaccination is that small changes in the vaccination rate appear to yield outsized changes in the overall outcome. For example, with the parameters at [infectiousness = 15%, chance-recover = 2%, duration = 99 weeks, and immune-time = 100 weeks], having a vaccination rate of 0% yields a population size that is highly oscillating, frequently going between about 100 to 750. But changing the vaccination rate to just 2% yields a population size that stays maxed out at 750, of which about 25% are immune. Changing the vaccination rate to 5% increases the immunity rate to 60%.

Unlike vaccination, duration of immunity does not seem to have a large impact on the population dynamics. However, it does impact the speed of population oscillation as well as the average size of the population. For example, with the parameters at [infectiousness = 67%, chance-recover = 49%, duration = 48 weeks, and vaccination-rate = 0%], an immune-time of 100 weeks yields a population which slowly oscillates between the high 300s and low 400s. Changing the immune time to 2 weeks produces a population that oscillates slightly more rapidly between the low to mid 300s. Also, in the model with the longer immune-time, the number of healthy people and number of immune people are similar, while the number of sick people is consistently the largest group. In the model with the lower immune-time, sick people are still the largest group, but there are considerably fewer immune people than healthy.


If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:


Copyright 1998 Uri Wilensky.


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.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2001.

Comments and Questions

Vaccinating in 'Go'?

Hey guys, I like your additions! I made a similar model (with a few extra parameters) for an MSc/PhD course on evidence based medicine last year where, given a limited number of vaccines, students had to determine who to vaccinate (age groups, pregnant women, etc.) It was pretty cool, if you ask me, which you didn't, but I'll pretend you did. One thing: You are currently vaccinating in your Go procedure, which means that every tick, everybody has a chance of being vaccinated. The result is that everybody gets vaccinated eventually, even with a small chance.

Posted over 12 years ago

Click to Run Model

  [ sick?        ;; if true, the turtle is infectious
    immune?      ;; if true, the turtle can't be infected
    sick-count   ;; how long the turtle has been infectious
    immune-count ;; how long the turtle has been immune
    age ]        ;; how many weeks old the turtle is

  %infected            ;; what % of the population is infectious
  %immune              ;; what % of the population is immune
  lifespan             ;; the average lifespan of a turtle
  average-offspring    ;; the average number of offspring a turtle could have
  carrying-capacity    ;; the number of turtles that can be in the world at one time

;; The setup is divided into three subroutines

to setup

;; We create a variable number of turtles of which 10 are infectious,
;; and distribute them randomly

to setup-turtles
  set-default-shape turtles "person"
  crt people
    [ setxy random-xcor random-ycor
      set age random lifespan
      set sick-count 0
      set immune? false
      set size 1.5  ;; easier to see
      get-healthy ]
  ask n-of 10 turtles
    [ get-sick ]

to get-sick ;; turtle procedure
  set sick? true
  set immune? false
  set color red

to get-healthy ;; turtle procedure
  set sick? false
  set immune? false
  set sick-count 0
  set color green

to become-immune ;; turtle procedure
  set sick? false
  set sick-count 0
  set immune? true 
  set immune-count 0
  set color gray

to become-unimmune ;; turtle procedure
  set sick? false
  set sick-count 0
  set immune? false
  set color green

to setup-constants
  set lifespan 100
  set carrying-capacity 750
  set average-offspring 4

to go

to update-global-variables
  if count turtles > 0
    set %infected (count turtles with [sick?]) / (count turtles) * 100
    set %immune (count turtles with [immune?]) / (count turtles) * 100

;;Turtle counting variables are advanced.

to get-older
  ask turtles
    set age age + 1
    if sick?
      [ set sick-count (sick-count + 1) ]
    if immune?
      [ set immune-count (immune-count + 1) ]
    ;; Turtles die of old age once their age equals the
    ;; lifespan (set at 1500 in this model).
    if age > lifespan
      [ die ]

;;Turtles move about at random.

to move
  ask turtles
  [ rt random 100
    lt random 100
    fd 1 ]

;; A healthy turtle has a certain chance of getting vaccinated
;; at each interval. Sick or immune turtles never get vaccinated
;; (sick turtles because the vaccine doesn't work once you're sick,
;; and immune turtles because the vaccine is unnecessary if you're
;; already immune).

to vaccinate
  ask turtles with [not sick? and not immune?]
    if (random-float 100) < vaccination-rate [ become-immune ]

;; If a turtle is sick, it infects other turtles on the same patch.
;; Immune turtles don't get sick.

to infect
  ask turtles with [sick?]
    [ ask other turtles-here with [ not immune? ]
        [ if (random-float 100) < infectiousness
            [ get-sick ] ] ]

;; Once the turtle has been sick long enough, it
;; either recovers (and becomes immune) or it dies.

to recover
   ask turtles with [sick?]
     [ if (random sick-count) > (lifespan * (duration / 100))  ;; If the turtle has survived past the virus' duration, then
         [ ifelse ((random-float 100) < chance-recover)        ;; either recover or die
             [ become-immune ]
             [ die ] ] ]

;; Once the turtle has been immune for a certain amount of time, it 
;; loses immunity.

to lose-immunity
  ask turtles with [immune?]
  [ if immune-count > immune-time    ;; If the turtle has survived past the immunity's
    [ become-unimmune ]              ;; duration, then lose immunity

;; If there are less turtles than the carrying-capacity
;;  then turtles can reproduce.
;; The probability of reproduction depends on average number
;;  of offspring per life.  In this model it is 4 per life (e.g.
;;  4 per 100 weeks.  The chance, therefore, for a turtle to
;;  reproduce at any given turn is 0.04 (if the population
;;  is below carrying-capacity).

to reproduce
  ask turtles with [not sick?]
    [ if (count turtles) < carrying-capacity
         and (random lifespan) < average-offspring
       [ hatch 1
           [ set age 1
             lt 45 fd 1
             get-healthy ] ] ]

; Copyright 1998 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created over 12 years ago by Kay Ramey.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.