Difference between revisions of "Epidemiology: The SIR model"

From JSXGraph Wiki
Jump to navigationJump to search
Line 33: Line 33:
<form><input type="button" value="clear and run a simulation of 100 days" onClick="clearturtle();run()">
<form><input type="button" value="clear and run a simulation of 100 days" onClick="clearturtle();run()">
<input type="button" value="stop" onClick="stop()">
<input type="button" value="stop" onClick="stop()">
<input type="button" value="stop" onClick="continue()"></form>
<input type="button" value="continue" onClick="continue()"></form>
<div id="box" class="jxgbox" style="width:600px; height:450px;"></div>
<div id="box" class="jxgbox" style="width:600px; height:450px;"></div>
<script language="JavaScript">
<script language="JavaScript">
Line 106: Line 106:
function continue() {
function continue() {
   if (t>0) {
   if (t>0) {
     if (!active) {
     if (active==null) {
       active = setTimeout(loop,10);
       active = setTimeout(loop,10);

Revision as of 14:26, 22 January 2009

Simulation of differential equations with turtle graphics using JSXGraph.

SIR model without vital dynamics

The SIR model measures the number of susceptible, infected, and recovered individuals in a host population. Given a fixed population, let [math]S(t)[/math] be the fraction that is susceptible to an infectious, but not deadly, disease at time t; let [math]I(t)[/math] be the fraction that is infected at time [math]t[/math]; and let [math]R(t)[/math] be the fraction that has recovered. Let [math]\beta[/math] be the rate at which an infected person infects a susceptible person. Let [math]\gamma[/math] be the rate at which infected people recover from the disease.

A single epidemic outbreak is usually far more rapid than the vital dynamics of a population, thus, if the aim is to study the immediate consequences of a single epidemic, one may neglect birth-death processes. In this case the SIR system can be expressed by the following set of differential equations:

[math] \frac{dS}{dt} = - \beta I S [/math]
[math] \frac{dR}{dt} = \gamma I [/math]
[math] \frac{dI}{dt} = -(\frac{dS}{dt}+\frac{dR}{dt}) [/math]

Example Hong Kong flu

  • initially 7.9 million people,
  • 10 infected,
  • 0 recovered.
  • estimated average period of infection: 3 days, so [math]\gamma = 1/3[/math]
  • infection rate: one new person every other day, so [math]\beta = 1/2[/math]

Thus S(0) = 1, I(0) = 1.27E-6, R(0) = 0, see [1].

The lines in the JSXGraph-simulation below have the following meaning:

* Blue: Rate of susceptible population
* Red: Rate of infected population
* Green: Rate of recovered population (which means: immune, isolated or dead)

The underlying JavaScript code

<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<form><input type="button" value="clear and run a simulation of 100 days" onClick="clearturtle();run()"></form>
<div id="box" class="jxgbox" style="width:600px; height:450px;"></div>
var brd = JXG.JSXGraph.initBoard('box', {originX: 20, originY: 300, unitX: 20, unitY: 250});

var S = brd.createElement('turtle',[],{strokeColor:'blue',strokeWidth:3});
var I = brd.createElement('turtle',[],{strokeColor:'red',strokeWidth:3});
var R = brd.createElement('turtle',[],{strokeColor:'green',strokeWidth:3});
var xaxis = brd.createElement('axis', [[0,0], [1,0]], {});
var yaxis = brd.createElement('axis', [[0,0], [0,1]], {});
var s = brd.createElement('slider', [[0,-0.3], [30,-0.3],[0,0.03,1]], {name:'s'});
brd.createElement('text', [40,-0.3, "initially infected population rate"]);
var beta = brd.createElement('slider', [[0,-0.4], [30,-0.4],[0,0.5,1]], {name:'&beta;'});
brd.createElement('text', [40,-0.4, "&beta;: infection rate"]);
var gamma = brd.createElement('slider', [[0,-0.5], [30,-0.5],[0,0.3,1]], {name:'&gamma;'});
brd.createElement('text', [40,-0.5, "&gamma;: recovery rate = 1/(days of infection)"]);

var t = 0; // global

brd.createElement('text', [40,-0.2, 
        function() {return "Day "+t+": infected="+brd.round(7900000*I.pos[1],1)+" recovered="+brd.round(7900000*R.pos[1],1);}]);

function clearturtle() {

function run() {
  delta = 1; // global
  t = 0;  // global
function turtleMove(turtle,dx,dy) {
function loop() {
  var dS = -beta.Value()*S.pos[1]*I.pos[1];
  var dR = gamma.Value()*I.pos[1];
  var dI = -(dS+dR);
  t += delta;
  if (t<100.0) {