Vaccinations and Herd Immunity Using the SIR Disease Epidemic Model

Initializing live version
Download to Desktop

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

The spread of certain diseases through a population can be determined using a set of differential equations modeling the growth and decay of the number of sick and well people; this is known as the SIR model.


You can vary the initial number of infected individuals, disease duration, contact number (how many individuals interacted with a person in a day), percentage of the population vaccinated, and vaccination effectiveness. The Demonstration shows the change in the proportions of susceptible people , infectious people , recovered people , and people who have been successfully immunized using the vaccine (represented by black, red, green, and blue, respectively) over time, both graphically and by a representation of the population by 200 dots at three different times.

This Demonstration illustrates the concept of herd immunity by displaying the minimum proportion of vaccinated individuals needed to prevent an epidemic from occurring, based on your setting of the variables. There are also preset buttons that represent a very simplified account of actual epidemic outbreaks in the United States so that you can see what the necessary vaccination rate to move them from "epidemic " to "no epidemic" states would have been.


Contributed by: Tara Nenninger and Soumyaa Mazumder (July 2015)
Special thanks to the University of Illinois NetMath Program and the Mathematics Department at William Fremd High School
Based on programs by: Steve Strain and Keith Stroyan
With additional contributions by: Christopher Grattoni
Open content licensed under CC BY-NC-SA



Snapshot 1: example of output produced for some given user-chosen values

Snapshot 2: output produced upon pressing "CA measles" outbreak button

Snapshot 3: output produced upon pressing "NYC Hong Kong flu" epidemic button

This Demonstration shows the importance of vaccination and the effects of herd immunity on communities with an outbreak of highly infectious diseases. The specific disease model here is called the SIR model, which shows the spread of highly communicable diseases, such as measles or chickenpox, in populations.

The traditional SIR model assumes that an individual is always in one of three states: being susceptible to the disease, being infected with the disease, or having recovered from the disease or died. One is born susceptible; if a person catches the disease, he becomes infectious, then either recovers or dies and is not able to spread the disease or be infected again. This model works only for diseases like measles or chickenpox, where once someone has been infected and recovered, they cannot contract the disease again. This original SIR model shows the growth and decay of the number of each subpopulation of people, , , and :





where is usually assumed to be 0, is the recovery rate (the reciprocal of the infectious period of disease), and is the infection rate (the contact number divided by the infectious period of disease).

In this specific use of the SIR model, we changed the initial conditions of these differential equations to take into account how vaccination rates affect the spread of disease in a community. Adding the extra state of being vaccinated for an individual keeps the same population size and density but reduces the proportion of individuals who start out susceptible to the disease. We have also considered the effect of vaccine effectiveness. In our model, the percentage of individuals vaccinated multiplied by vaccine effectiveness gives the percent of the population that starts out immunized. Thus, it can be assumed that immunized individuals in the vaccinated category never interact with the rest of the SIR populations. Accordingly, the initial condition we used is:


again assuming .

We included vaccination rates and effectiveness in our SIR model to show the necessity of vaccinations and how the concept of herd immunity works with different diseases and in different environments. Herd immunity is the concept that a disease will die out or be contained and will not become an epidemic because a large enough percentage of the total population is vaccinated and thus will not spread the disease. This protects those who are either too young to be vaccinated or have autoimmune diseases and are thus unable to be vaccinated or are more susceptible to such diseases. If a large enough fraction of the population is vaccinated—so that the disease outbreak will not become an epidemic—those individuals who are unable to be vaccinated are then protected because it is less likely that the disease will spread to them. Our model uses the numbers that you choose to show whether there are enough people in the population vaccinated, given the other constraints, to prevent an epidemic from occurring. This lets you see that different vaccination rates are necessary for populations with different population densities, rates of infection, disease duration, and so on.

One of our preset values buttons is used to provide a highly simplified yet hopefully illustrative model for the recent 2014–2015 measles epidemic in California. We obtained the numbers for the infectious period of measles and contact number of the disease from the CDC, and also obtained vaccination rates from the Orange County Health Department (as Orange County tends to have the lowest vaccination rates in the state and experiences the most outbreaks), the effectiveness of the measles vaccine, and the contact number of individuals in a day. When you click this preset button, those values are input into the differential equations. If you only change the time variable, you can see through the change in distribution of the colored dots how the disease spreads throughout the population. We used this same idea for two more buttons, the California whooping cough epidemic of 2014–2015 and the New York City H3N2 epidemic of 1968–1969.


[1] R. Vajda and J. Karsai, Interesting Mathematical Problems in Sciences and Everyday Life [online], Szeged: University of Szeged, 2011.

[2] J. Chasnov, "Mathematical Biology: Lecture Notes for Math 4333", The Hong Kong University of Science and Technology, 2009, revised 2014.

[3] The Centers for Disease Control and the World Health Organization, "History and Epidemiology of Global Smallpox Eradication" [lecture notes].

Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.