21.06.2014 Views

SIR Model: The Boarding School Example - SAMSI

SIR Model: The Boarding School Example - SAMSI

SIR Model: The Boarding School Example - SAMSI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>SIR</strong> <strong>Model</strong>:<br />

<strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong><br />

Cammey Cole Manning<br />

Meredith College<br />

May 17, 2011<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 1/8


<strong>SIR</strong> <strong>Model</strong>: Equations<br />

SI<br />

N<br />

S I R<br />

I<br />

dS<br />

dt<br />

dI<br />

dt<br />

dR<br />

dt<br />

= − βSI<br />

N<br />

= βSI<br />

N − γI<br />

= γI<br />

N = S + I + R<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 2/8


<strong>Boarding</strong> <strong>School</strong> <strong>Example</strong>:<br />

<strong>The</strong> Data<br />

Time<br />

Number Infected<br />

1 3<br />

2 6<br />

3 25<br />

4 73<br />

5 222<br />

6 294<br />

7 258<br />

8 237<br />

9 191<br />

10 125<br />

11 69<br />

12 27<br />

13 11<br />

14 4<br />

From Influenza in a boarding school, British Medical Journal, March 4, 1978, p. 587.<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 3/8


Experiment with Values of β and γ<br />

time=[1:1:14];<br />

Infected=[3 6 25 73 222 294 258 237 191 125 69 27 11 4];<br />

beta= % Choose values for beta and gamma<br />

gamma =<br />

N=763;<br />

YInit=[760 3 0];<br />

options=[ ];<br />

[t,PredY]=ode15s(@<strong>SIR</strong>ode, time, YInit, options, beta, gamma, N);<br />

PredI=PredY(:,2);<br />

figure<br />

plot(time, Infected, ’*’, t, PredI, ’-’)<br />

xlabel(’Time (in Days)’)<br />

ylabel(’Number Infected’)<br />

legend(’Data’, ’<strong>Model</strong>’)<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 4/8


Least Squares:<br />

Sum of Squares of Residuals<br />

Minimize the sum of the squares of the residuals between<br />

the measured y (the data) and the y calculated in the linear<br />

model.<br />

S r =<br />

=<br />

=<br />

n∑<br />

i=1<br />

e 2 i<br />

n∑<br />

(y i,measured − y i,model ) 2<br />

i=1<br />

n∑<br />

(DataI i − PredI i ) 2<br />

i=1<br />

This criterion has a number of advantages:<br />

• Positive differences do not cancel negative differences.<br />

• Small differences become smaller, and large<br />

differences are magnified.<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 5/8


<strong>Boarding</strong> <strong>School</strong> <strong>Example</strong>:<br />

MATLAB Cost Code<br />

function [Cost]=<strong>SIR</strong>Cost(param, t,Infected, YInit, N)<br />

% param: 2x1 vector of beta and gamma<br />

% t: time data % Infected: infected data<br />

% Cost: value of sum of squared errors<br />

beta=param(1);<br />

gamma=param(2);<br />

options=[];<br />

[t,PredY]=ode15s(@<strong>SIR</strong>ode, t, YInit, options, beta, gamma, N);<br />

PredInfected=PredY(:,2);<br />

DiffY=PredInfected’-Infected;<br />

DiffYsq=(DiffY).ˆ2;<br />

Cost=sum(DiffYsq);<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 6/8


<strong>Boarding</strong> <strong>School</strong> <strong>Example</strong>:<br />

Script Using Fminsearch and ODE<br />

time=[1:1:14];<br />

Infected=[3 6 25 73 222 294 258 237 191 125 69 27 11 4];<br />

N=763;<br />

%Initial Conditions: Susceptible 760, Infected: 3, Recovered: 0<br />

YInit=[760 3 0];<br />

options=[ ];<br />

ParamInit=[0.01 0.1]; % Choose initial guesses for β and γ<br />

[ParamOpt] = fminsearch(@<strong>SIR</strong>Cost,ParamInit,options, time,Infected, YInit, N)<br />

betaOpt=ParamOpt(1);<br />

gammaOpt=ParamOpt(2);<br />

[t,PredY]=ode15s(@<strong>SIR</strong>ode, time, YInit, options, betaOpt, gammaOpt, N);<br />

PredInfected=PredY(:,2);<br />

figure<br />

plot(time,Infected, ’*’, t, PredInfected, ’-’)<br />

xlabel(’Time (in Days)’)<br />

ylabel(’Number Infected’)<br />

legend(’Data’, ’<strong>Model</strong>’)<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 7/8


<strong>Boarding</strong> <strong>School</strong> <strong>Example</strong>: MATLAB Plot<br />

β = 1.6923, γ = 0.4485<br />

300<br />

Data<br />

<strong>Model</strong><br />

250<br />

200<br />

Number Infected<br />

150<br />

100<br />

50<br />

0<br />

0 2 4 6 8 10 12 14<br />

Time (in Days)<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 8/8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!