{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

### Code Templates and Review

\n", "

The code below generates data for the measles example given in Calculus in Context.

\n", "

" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "starttime = 0\n", "stoptime = 1\n", "nsteps = 10\n", "S = 45400\n", "I = 2100\n", "R = 2500\n", "deltat = float((stoptime-starttime)/nsteps)\n", "S_sol = [S]\n", "I_sol = [I]\n", "R_sol = [R]\n", "tvals = [starttime]\n", "for step in range(nsteps):\n", " S_prime = -.00001*S_sol[-1]*I_sol[-1]\n", " I_prime = .00001*S_sol[-1]*I_sol[-1] - I_sol[-1]/14\n", " R_prime = I_sol[-1]/14\n", " S_sol.append(S_sol[-1] + deltat*S_prime)\n", " I_sol.append(I_sol[-1] + deltat*I_prime)\n", " R_sol.append(R_sol[-1] + deltat*R_prime)\n", " tvals.append(tvals[-1] + deltat)" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Run the code above (there will be no output).  See what the values of  t, S, I, R are by executing the following command:

" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "print(tvals[-1],S_sol[-1],I_sol[-1],R_sol[-1])" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Go ahead and see what happens if you change the ending time to 14 days.  Execute the code, and make a note of the new values of  t, S, I, R.  Then change the number of steps to 200 and execute the code again.  Why are the answers you get different?  Which set of answers is better (and why)?

\n", "

\n", "

Now we'll look at S, I, and R graphs all at the same time, on the same axes.

" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Splot = list_plot(zip(tvals,S_sol), color='blue', title='Time in days vs. Stuff')\n", "Iplot = list_plot(zip(tvals,I_sol), color='red')\n", "Rplot = list_plot(zip(tvals,R_sol), color='green')\n", "SIRplot = Splot + Iplot + Rplot\n", "SIRplot.show()" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

## Experiments

\n", "

\n", "

Probably the first thing you noticed when you looked at the graphs is that they don't tell you much.  That is, not a lot happens in the first five days.  Copy and paste some appropriate code down here (and rename variables so that you don't lose your old computations above) and get the computer to display graphs to help you answer the following questions. (The questions are in separate cells so you can create code and write responses between them easily.)

\n", "

\n", "

On what day is the peak of the epidemic?  What proportion of the population is infected at that time? (Do you think that this illness qualifies as an epidemic?)

\n", "

\n", "

" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

When is the epidemic over?  What criteria did you use to decide what \"over\" means?

" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

On what day is the size of the infected population increasing most rapidly? When is it decreasing most rapidly? How do you know?

" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

How many people caught the measles during the first 10 days?  (Hint: You can't answer this by looking at the I_sol graph.)

" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Quarantine!

\n", "

This time we will alter the model to reflect the idea that if we ask that people with measles isolate themselves so as to limit contact with healthy people, the transmission coefficient should be lower.  Again, copy/paste code to answer these questions.

\n", "

Suppose the effect of quarantine is to cut the transmission coeffient in half.  What is the effect on the epidemic?  Also, what does this mean in terms of the exposure of susceptible people to infected people?

\n", "

" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

How low does the transmission coefficient need to get in order to avoid having an epidemic?  (In order to answer this question, you will need to decide what it means to avoid an epidemic.)  Is this realistic?

" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Let's look at Sarah Lawrence.

\n", "

Pretend that the measles are arriving on campus.  There are about 2200 students and staff here.  What should S,I,R be set to initially in the code to reflect the new situation?

\n", "

" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

Using the original example (not with quarantine), run the code with your new  S,I,R and see what happens.  Describe the results. (You may wish to consult earlier questions to complete your analysis.)  Keep in mind that a semester is no more than 120 days long, and that the break between semesters will effectively end the spread of infection on campus.

" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

In the real world---what factors indicate that a measles epidemic would be likely/unlikely to happen on campus?

" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

\n", "

\n", "

\n", "

As you may know, influenza is an infectious disease that has as primary symptoms fever, achiness, malaise, sore throat, and a runny nose.  It leads to 250,000 to 500,000 deaths each year worldwide (3,000 to 50,000 deaths each year in the U.S.).  There is an annual influenza epidemic.  Let's investigate.

\n", "

\n", "

In order to create an S-i-R model, we need to first know what the parameters are; we need to know the transmission coefficient and the duration of the disease.

\n", "

\n", "

It turns out that transmission coefficient isn't measured by epidemiologists.  They measure something called R, and what we call the transmission coefficient is equal to R / (shedding duration times initial susceptible population). To be very clear, there are actually two parameters that are measured by epidemiologists---R0 and R.  R0 is an initial infectivity, and is measured for new infectious diseases.  R measures infectivity for a population in which the pathogen has already been circulating, so that there is some immunity in the population (from prior exposure or vaccination).

\n", "

\n", "

Every year the influenza epidemic is caused by a mix of different virus strains.  One of the more infectious strains is H3N2, and when this is prevalent an epidemic is worse than when not.  Someone who works at the CDC has estimated that for H3N2, R is around 1.4 or 1.5.  (This estimate was transmitted in a private email.) So, using these numbers will model a somewhat more severe flu epidemic than average.

\n", "

\n", "

The duration of shedding for influenza is 6 - 11 days with a dropoff after 3 - 5 days.  So, let us average this out to 8 days for the purpose of our model. (Source: http://www.cdc.gov/flu/professionals/acip/clinical.htm.)

\n", "

If R is 1.4, then what is the transmission coefficient?

\n", "

If R is 1.5, then what is the transmission coefficient?

\n", "

" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

It takes about 7 days to recover from influenza, on average.

\n", "

\n", "

A wealth of national data is available from http://www.cdc.gov/flu/weekly/ but you want to know what the situation is right here and right now.  Call over to Health services and ask for an estimate of how many influenza cases they have seen or diagnosed over the phone in the last week, and use this as your initial number of infecteds. Run code for an influenza epidemic on campus (use R=1.5) and produce graphs to help you answer the following questions.

\n", "

On what day will the influenza infection peak on campus?  What proportion of the campus will be infected at that time? Would you consider this an epidemic?  (Are you worried?)

" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

How much of a difference does a small change in R make? Run new influenza S-I-R code with R=1.4 and compare your new graphs to your old graphs.  How does this change the situation?

" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "

If you're feeling really ambitious, try to figure out by what proportion self-quarantining will reduce a transmission coefficient.  (What fraction of the normal number of people you have contact with over a day will you see if you stay home in bed?)  And then see how self-quarantinement affects the spread of influenza across campus.

" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/plain": [] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [] } ], "metadata": { "kernelspec": { "display_name": "SageMath 8.0", "language": "", "name": "sagemath" }, "language": "python", "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.13" } }, "nbformat": 4, "nbformat_minor": 2 }