AN INTRODUCTION TO STOCHASTIC EPIDEMIC MODELS-PART I Linda J. S. Allen Department of Mathematics and Statistics Texas Tech University Lubbock, Texas U.S.A. 2008 Summer School on Mathematical Modeling of Infectious Diseases University of Alberta May 1-11, 2008
Outline of Presentation-PART I I. What is a Stochastic Model and What is the Difference Between a Deterministic and Stochastic Model? II. Some Stochastic Models are Illustrated Through Study of an SIS Epidemic Model. (a) Discrete Time Markov Chain DTMC (b) Continuous Time Markov Chain CTMC (c) Diffusion Process and Stochastic Differential Equations SDE III. Some Differences Between the Stochastic SIS and SIR Epidemic Models.
I. What is a Stochastic Model? A stochastic model is formulated in terms of a stochastic process. A stochastic process is a collection of random variables {X t (s) t T,s S}, where T is the index set and S is a common sample space. The index set often represents time, such as T = {0, 1, 2,...} or T = [0, ) Time can be discrete or continuous. The study of stochastic processes is based on probability theory.
How do Stochastic Epidemic Models Differ from Deterministic Epidemic Models? A deterministic model is often formulated in terms of a system of differential equations or difference equations. A stochastic model is formulated as a stochastic process with a collection of random variables. A solution of a deterministic model is a function of time or space and is generally uniquely dependent on the initial data. A solution of a stochastic model is a probability distribution for each of the random variables. One sample path over time or space is one realization from this distribution. Stochastic models are often used to show the variability inherent due to the demographics or environment variablility are particularly important when quantities in the processes are small- small population size or initial number of infectives.
The Following Graphs Illustrate the Dynamics of a Deterministic versus a Stochastic Epidemic Model 35 30 Number of Infectives, I(t) 25 20 15 10 5 0 0 500 1000 1500 2000 Time Steps
Whether the Random Variables Associated with The Stochastic Process are Discrete or Continuous Distinguishes Some of the Different Types of Stochastic Models. A random variable X(t) of a stochastic process assigns a real value to each outcome A S in the sample space and a probability, Prob{X(t) A} [0, 1]. The values of the random variable constitute the state space, X(t; S). For example, the number of cases associated with a disease may have the following discrete or continuous set of values for its state space: {0, 1, 2,...} or [0, N]. The state space can be discrete or continuous and correspondingly, the random variable is discrete or continuous. For simplicity, the sample space notation is suppressed and X(t) is used to denote a random variable indexed by time t. The stochastic process is completely defined when the set of random variables {X(t)} are related by a set of rules.
We will Study Stochastic Processes that have the Markov Property. A stochastic process with the Markov property is one where the future state of the process depends only on the current state, and not on the past. That is, for a discrete-time stochastic process, a d Prob{X(t + t) X(t),X(t t),...,x(0)} = Prob{X(t + t) X(t)}. At a fixed time t, each random variable X(t) has an associated probability distribution. Discrete: Prob{X(t) = i} = p i (t), i {0, 1,2...} Continuous: Prob{X(t) [a,b]} = b a p(x,t)dx
The Choice of Discrete or Continuous Random Variables with a Discrete or Continuous Index Set Defines the Type of Stochastic Model. Discrete Time Markov Chain (DTMC): t {0, t, 2 t,...} X(t) is a discrete random variable. X(t) {0,1, 2,...,N} The term chain implies that the random variable is discrete. Continuous Time Markov Chain (CTMC): t [0, ), X(t) is a discrete random variable. X t {0, 1,2,...,N} Diffusion Process, Stochastic Differential Equation (SDE): t [0, ), X(t) is a continuous random variable. X(t) [0,N]
II. Before we Formulate the Stochastic SIS Epidemic Models, we Review the Dynamics of the Deterministic SIS Epidemic Model. Deterministic SIS: S I ds dt di dt = β SI + (b + γ)i N = β SI (b + γ)i N where β > 0, γ > 0, N > 0 and b 0, S(t) + I(t) = N.
The Dynamics of the Deterministic SIS Epidemic Model Depend on the Basic Reproduction Number. The parameter values represent β = transmission rate b = birth rate = death rate γ = recovery rate N = total population size = constant. Basic Reproduction Number: R 0 = β b + γ If R 0 1, then lim t I(t) = 0. If R 0 > 1, then lim t I(t) = N (1 1R0 ).
We will Formulate the Three Types of Stochastic SIS Epidemic Models by Defining Relationships Among the Random Variables Assuming the Markov Property Holds. S(t) = random variable for the number of susceptible individuals. I(t) = random variable for the number of infected individuals. S(t) + I(t) = N = maximum population size. Discrete Time Markov Chain (DTMC): t {0, t, 2 t,...}, I(t) is a discrete random variable, I(t) {0, 1, 2,...,N} Continuous Time Markov Chain (CTMC): t [0, ), I(t) is a discrete random variable. I(t) {0, 1, 2,...,N} Diffusion Process, SDEs: t [0, ), I(t) is a continuous random variable. I(t) [0, N]
First, We Formulate a DTMC SIS Epidemic Model. Let I(t) denote the discrete random variable for the number of infected (and infectious) individuals with associated probability function p i (t) = Prob{I(t) = i} where i = 0,1, 2,...,N is the total number infected at time t. The probability distribution is p(t) = (p 0 (t), p 1 (t),...,p N (t)) T for t = 0, t, 2 t,.... Now we relate the random variables {I(t)} indexed by time t by defining the probability of a transition from state i to state j, i j, in time t as p ji ( t) = Prob{I(t + t) = j I(t) = i}.
Assume that t is Sufficiently Small, Such that the Number of Infectives Changes by at Most One in Time t. That is, i i + 1, i i 1 or i i. Either there is a new infection, birth, death, or a recovery. Therefore, the transition probabilities are p ji ( t) = βi(n i)/n t = b(i) t, j = i + 1 (b + γ)i t = d(i) t, j = i 1 1 [βi(n i)/n + (b + γ)i] t = 1 [b(i) + d(i)] t, j = i 0, j i + 1,i, i 1,
The Probability Distribution Associated with the Epidemic Process Over Time is Found by Repeated Multiplication of the Transition Matrix. Matrix P( t) = (p ji ( t)) is known as the transition matrix: p(t + t) = P( t)p(t), where p(t) = (p 0 (t),...,p N (t)) T is the probability distribution and P( t) is 1 d(1) t 0 0 0 1 [b(1) + d(1)] t d(2) t 0 0 b(1) t 1 [b(2) + d(2)] t 0 0 0 b(2) t 0...... 0 0 0 d(n) t 0 0 0 1 d(n) t Matrix P( t) is stochastic, the column sums equal one.
The Stochastic Process for the DTMC SIS Model is known as a Finite State Markov Chain with the Following Properties. The stochastic process {I(t)} for t {0, t, 2 t,...} is timehomogeneous (transition probabilities do not depend on time) and has the Markov property. The probability of no infections p 0 is an absorbing state. 0 1 2 N For any initial distribution p(0) = (p 0 (0),...,p N (0)) T, zero through a total of N infections lim p(t) = (1,0,...,0)T lim t p 0 (t) = 1. t
Three Sample Paths of the DTMC SIS Model are Compared to the Solution of the Deterministic Model. A sample path or stochastic realization of a stochastic process {I(t)} for t {0, t, 2 t,...} is an assignment of a possible value to I(t) for each value of t. R 0 = 2. 70 60 Number of Infectives 50 40 30 20 10 0 0 5 10 15 20 25 Time t = 0.01, N = 100, β = 1, b = 0.25, γ = 0.25, I(0) = 2, and p 2 (0) = 1.The MATLAB program is in the Appendix.
The Probability Distribution p(t) for the Number of Infected Individuals in the DTMC SIS Model can be Approximated. Probability 1 0.75 0.5 0.25 0 0 1000 50 0 Time, n 2000 100 State Probability distribution for the DTMC SIS model, t = 0.01, N = 100, β = 1, b = 0.25, γ = 0.25, R 0 = 2, I(0) = 2 and p 2 (0) = 1. MATLAB program is in the Appendix. Note: Asymptotically, lim t p 0 (t) = 1, the epidemic ends with probability one. But it may take a long time before p 0 1, if N and I(0) are large. In this example, p 0 (t) 1 R 0 «I(0) = 1 2 «2 = 1 4.
Next, We Formulate a CTMC SIS Model. This type of model is most often used to study stochastic epidemic processes, time is continuous, but the random variable for number of infected individuals is discrete. The discrete random variable I(t), t [0, ) has an associated probability function p i (t) = Prob{I(t) = i} The probability of a transition for small t satisfies p ji ( t) = where o( t) 0 as t 0. βi(n i)/n t + o( t) = b(i) t + o( t), j = i + 1 (b + γ)i t + o( t) = d(i) t + o( t), j = i 1 1 [βi(n i)/n + (b + γ)i] t + o( t) = 1 [b(i) + d(i)] t + o( t), j = i o( t), otherwise, i i + 1, i i 1, or i i.
A System of Differential Equations for the Probabilities Can be Derived Based on the Transition Probabilities. For small t, p i (t + t) = p i 1 (t)[b(i 1) t] + p i+1 (t)[d(i + 1) t] p i (t)[1 (b(i) + d(i)) t] + o( t) Subtracting p i (t), dividing by t, and letting t 0, dp i dt dp 0 dt = p i 1 b(i 1) + p i+1 d(i + 1) p i [b(i) + d(i)] = p 1 d(1) for i = 1, 2,...,N, where b(i) = βi(n i)/n, d(i) = (b + γ)i. These differential equations are known as the forward Kolmogorov differential equations.
The Epidemic Process is Captured by a System of Differential Equations Expressed in Matrix Form. In matrix notation, dp dt = Qp, where p(t) = (p 0 (t),...,p N (t)) T and Q is known as the generator matrix: Q = 0 1 0 d(1) 0 0 0 [b(1) + d(1)] d(2) 0 0 b(1) [b(2) + d(2)] 0 0 0 b(2) 0...... B C @ 0 0 0 d(n) A 0 0 0 d(n) b(i) = βi(n i)/n and d(i) = (b + γ)i
The DTMC Transition Matrix and CTMC Differential Equations are Closely Related when t is Small. In the DTMC Model, p(t + t) = P( t)p(t), where P( t) is the transition matrix. Letting t 0, we obtain the Kolmogorov differential equations for the CTMC model, p(t + t) p(t) t dp dt = P( t) I t = Qp p(t) where Q = lim t 0 P( t) I t. The Discrete-Time Process can be used to Approximate the Continuous- Time Process.
Because of the Markov Property, the Inter-Event Time in a CTMC Model Has an Exponential Distribution. The exponential distribution has what is known as the memoryless property. Let I(t) = n and T n denote the inter-event time, a continuous random variable for the time to the next event. Take the sum of all the probabilities of all possible events where there is a change in state, i i + 1, i i 1: and j=0,j n p jn ( t) = a(n) t + o( t) p nn ( t) = 1 a(n) t + o( t). Then the interevent time has an exponential distribution with parameter a(n), T n E(a(n)) Prob{T n t} = 1 exp( a(n)t).
For the SIS Epidemic Model, with I(t) = n, p jn ( t) = [b(n) + d(n)] t + o( t) j=0,j n = [βn(n n)/n + (b + γ)n] t + o( t) a(n) = β n(n n) + (b + γ)n N
To Numerically Simulate the Inter-Event Time in a CTMC Model, We Use a Uniform Random Variable. The inter-event time, waiting time until an event occurs, can be numerically computed using a uniform random variable and the cumulative distribution for T n. Let U be uniform random variable on [0,1] and F n (t) the cumulative distribution for T n Then F n (t) = Prob{T n t} = 1 exp(a(n)t). Prob{F 1 n (U) t} = Prob{F n(f 1 (U)) F n(t)} = Prob{U F n (t)} = F n (t) The inter-event time T n, given I(t) = n satisfies n T n = Fn 1 ln(1 U) (U) = a(n) = ln(u) a(n).
Three Sample Paths of the CTMC SIS Model are Compared to the Deterministic Solution. R 0 = 2 Number of Infectives 80 70 60 50 40 30 20 10 0 0 5 10 15 20 25 Time b = 0.25, γ = 0.25, β = 1, N = 100, I(0) = 2, R 0 = 2. For t small, the dynamics of the DTMC and the CTMC Models are Similar. The DTMC model can be used as an approximation for the CTMC model. MATLAB program is in the Appendix.
Next, We Formulate the Third Type of Stochastic Model, a SDE Model. The number of infectives, I(t), is continuous random variable and the time, t [0, ), is also continuous. The random variable I(t) has an associated probability density function (pdf), p(x,t), Prob{I(t) [a, b]} = b a p(x, t)dx. We can derive a system of differential equations satisfied by the pdf. This system of equations is also known as the forward Kolmogorov differential equations: p t = {[βx(n x)/n (b + γ)x]p} x + 1 2 {[βx(n x)/n + (b + γ)x]p} 2 x 2, x [0, N], t [0, ). The first term is known as the drift and second term diffusion.
The Stochastic Differential Equation (SDE) Depends on the Drift and Diffusion Terms. The Stochastic Differential Equation (SDE) follows directly from the differential equations, di dt = β r β I(N I) (b + γ)i + N N I(N I) + (b + γ)idw dt, where W(t) is a Wiener process (white noise), normally distributed, with mean zero and variance t: W(t) Normal(0, t), W(t + t) W(t) Normal(0, t). Sample paths for a Wiener process are continuous but not differentiable. 1 0.5 W(t) 0-0.5-1 -1.5 0 0.2 0.4 0.6 0.8 1 Time
The SDE Depends on Relationship Between Births and Deaths and Drift and Diffusion Let b(i) =births (new infection or birth) and d(i) =deaths (recovery or death). Then the probability density p(x, t), where Prob{I(t) [a, b]} = b p(x, t)dx satisfies the differential equation a p(x, t) t ([b(x) d(x)]p(x,t)) = x + 1 2 ([b(x) + d(x)]p(x,t)) 2 x 2 and the stochastic differential equation (SDE) satisfies di dt = b(i) d(i) + b(i) + d(i) dw dt = drift + diffusion
The Drift and Diffusion Terms Determine the Change in Number of Infections Over Time SDE: di dt = b(i) d(i) + b(i) + d(i) dw dt I(t) is approximately normally distributed with mean b(i) d(i)] t and variance, b(i) + d(i)] t : I(t) = I(t + t) I(t) Normal([b(I) d(i)] t,[b(i) + d(i)] t). The Wiener process W(t) (white noise) is normally distributed with mean 0 and variance t: W(t) = W(t + t) W(t) = t η Normal(0, t).
In General, the SDE is Expressed in Terms of the Parameters for Recovery, Transmission and Birth. SDE: di dt = β I(N I) (b + γ)i + N β N I(N I) + (b + γ)idw dt, where W(t) is a Wiener process (white noise), normally distributed, with mean zero and variance t: W(t) Normal(0, t), W(t + t) W(t) Normal(0, t).
Three Sample Paths for the SDE SIS Model are Computed Numerically and Compared to the Deterministic Solution. R 0 = 2 Number of Infectives 80 70 60 50 40 30 20 10 0 0 5 10 15 20 25 Time b = 0.25, γ = 0.25, β = 1, N = 100, I(0) = 2. MATLAB program is in the Appendix. Note: For large N and I(0), then the SDE model is a good approximation to the CTMC model. However, for small N or I(0), the CTMC model is a better model.
Some Advantages of the Stochastic Models Over the Deterministic Model for the SIS Epidemic Model: The SIS Deterministic Model Does Not capture (i) The Variability Inherent in the Transmission, Recovery, Birth, and Death Processes (ii) The Probability of No Epidemic Occurrence when R 0 > 1. The Stochastic Models Do Capture these Features.
III. The SIS is a Simple Epidemic Model Because the Dynamics Reduce to a Single Variable. This is not the Case for the SIR Epidemic Model. First, we review the dynamics of the deterministic SIR Epidemic model. Then we will illustrate some of the differences in the stochastic formulation for the SIS versus the SIR epidemic model. Deterministic SIR: S I R
Deterministic SIR: S(t) + I(t) + R(t) = N ds dt di dt dr dt = β SI + b(i + R) N = β SI (b + γ)i N = γi br Basic Reproduction Number: R 0 = β b + γ If R 0 > 1 and b > 0, then lim t I(t) = Ī > 0. If R 0 > 1 and b = 0, then lim t I(t) = 0. There is an epidemic if R 0 S(0) N > 1. If R 0 1, then lim t I(t) = 0.
Formulation of a DTMC SIR Epidemic Model Results In A Multivariate Process. S(t) + I(t) + R(t) = N = maximum population size. Let S(t) and I(t) denote discrete random variables for the number of susceptible and infected individuals, respectively. These two variables have a joint probability function p (s,i) (t) = Prob{S(t) = s,i(t) = i} where R(t) = N S(t) I(t). For this stochastic process, we define transition probabilities as follows: p (s+k,i+j),(s,i) ( t) = Prob{( S, I) = (k, j) (S(t), I(t)) = (s, i)} 8 βi(n i) t/n, (k, j) = ( 1, 1) γi t, (k, j) = (0, 1) >< bi t, (k, j) = (1, 1) = b(n s i) t, (k, j) = (1, 0) 1 [βi(n i)/n + γi + b(n s)] t, (k, j) = (0, 0) >: 0, otherwise
Three Sample Paths of the DTMC SIR Epidemic Model are Compared to the Solution of the Deterministic Model. 35 R 0 = 2, b = 0 R 0 S(0) N = 1.96. 30 Number of Infectives, I(t) 25 20 15 10 5 0 0 500 1000 1500 2000 Time Steps t = 0.01, N = 100, β = 1, b = 0, γ = 0.5, S(0) = 98, and I(0) = 2.
The SDE Model for the SIR Epidemic is a System of Two Itô SDEs. For example, in the case with b = 0, ds dt di dt = β N SI + B dw 1 11 dt = β N SI γi + B dw 1 21 dt dw 2 + B 12 dt + B 22 dw 2 dt where W 1 and W 2 are two independent Wiener processes and B = (B ij ) is the square root of the following covariance matrix, B = Σ, Σ = ( ) βsi/n βsi/n. βsi/n βsi/n + γi Notice that matrix V is positive definite and thus, has a unique positive definite square root, Σ = B.
Three Stochastic Sample Paths of the SDE SIR Epidemic Model Are Compared to the Deterministic Solution. R 0 = 2, b = 0 R 0 S(0) N = 1.96. 35 30 Number of Infectives 25 20 15 10 5 0 0 5 10 15 20 Time t = 0.01, N = 100, β = 1, b = 0, γ = 0.5, I(0) = 2.
To Summarize the Main Points: Stochastic epidemic models capture the variability inherent in the transmission, recovery, birth and death processes. Here we did not consider environmental variability. For small population sizes or small number of infected individuals, CTMC or DTMC models with discrete random variables more accurately capture the variability in the epidemic process than deterministic models. The DTMC model may be used to approximate the CTMC model when the time interval t is small. The SDE model may be used to approximate the CTMC model when the population size and initial values are large.
(Part II) Stochastic SIS and SIR Epidemic Models are Useful for Quantifying the Following: (a) Probability of No Epidemic (b) Stationary or Quasistationary Distribution (c) Final Size of an Epidemic (e) Expected Duration of an Epidemic
References and MATLAB programs: 1. Allen, L. J. S. 2003. An Introduction to Stochastic Processes with Applications to Biology. Prentice Hall, Upper Saddle River, N.J. 2. Allen, L. J. S. and A. Burgin. 2000. Comparison of deterministic and stochastic SIS and SIR models in discrete time. Mathematical Biosciences. 163: 1-33. 3. Andersson, H. and T. Britton. 2000. Stochastic Epidemic Models and Their Statistical Analysis. Lecture Notes in Statistics. Springer-Verlag, New York, Inc. 4. Daley, D. J. and J. Gani. 1999. Epidemic Modelling An Introduction. Cambridge Studies in Mathematical Biology, Vol. 15. Cambridge University Press, Cambridge. 5. Gard, T. C. 1988. Introduction to Stochastic Differential Equations. Marcel Dekker, Inc., New York and Basel. 6. Mode, C. J. and C. K. Sleeman. 2000. Stochastic Processes in Epidemiology. HIV/AIDS, Other Infectious Diseases and Computers. World Scientific, Singapore, New Jersey.
MATLAB Programs For: (1) Three Sample Paths for DTMC SIS Model (2) Probability Distribution for the DTMC SIS Model (3) Three Sample Paths for CTMC SIS Model (4) Three Sample Paths for the SDE SIS Model. (1) % Matlab Program % DTMC SIS Epidemic Model % Three Sample Paths clear set(0, DefaultAxesFontSize, 18) beta=1; g=0.25; b=0.25; N=100; init=2; dt=0.01; time=25; sim=3; for j=1:sim
i(1)=init; for t=1:time/dt r=rand; birth=beta*i(t)*(n-i(t))/n*dt; death=(b+g)*i(t)*dt; if r<=birth i(t+1)=i(t)+1; elseif r>birth & r<=birth+death i(t+1)=i(t)-1; else i(t+1)=i(t); end end if j==1 plot([0:dt:time],i, r-, LineWidth,2); hold on elseif j==2 plot([0:dt:time],i, g-, LineWidth,2); else plot([0:dt:time],i, b-, LineWidth,2 end end
% Euler s Method for Deterministic SIS Model y(1)=init; for k=1:time/dt y(k+1)=y(k)+dt*(beta*(n-y(k))*y(k)/n-(b+g)*y(k)); end plot([0:dt:time],y, k--, LineWidth,2); hold off xlabel( Time ); ylabel( Number of Infectives ); 70 60 Number of Infectives 50 40 30 20 10 0 0 5 10 15 20 25 Time
(2) % Matlab Program % Discrete Time Markov Chain % Stochastic SIS epidemic model % Transition matrix and Graph of Probability Distribution clear all set(gca, FontSize,18); set(0, DefaultAxesFontSize,18); time=2000; dtt=0.01; % Time step beta=1*dtt; b=0.25*dtt; gama=0.25*dtt; N=100; % Total population size en=50; % plot every enth time interval T=zeros(N+1,N+1); % T is the transition matrix, defined below v=linspace(0,n,n+1); p=zeros(time+1,n+1); p(1,3)=1; % Two individuals initially infected bt=beta*v.*(n-v)/n; dt=(b+gama)*v; for i=2:n % Define the transition matrix T(i,i)=1-bt(i)-dt(i); % diagonal entries T(i,i+1)=dt(i+1); % superdiagonal entries
T(i+1,i)=bt(i); % subdiagonal entries end T(1,1)=1; T(1,2)=dt(2); T(N+1,N+1)=1-dt(N+1); for t=1:time y=t*p(t,:) ; p(t+1,:)=y ; end pm(1,:)=p(1,:); for t=1:time/en; pm(t+1,:)=p(en*t,:); end ti=linspace(0,time,time/en+1); st=linspace(0,n,n+1); mesh(st,ti,pm); xlabel( number infected ); ylabel( time steps ); zlabel( probability of infection ); view(140,30); axis([0,n,0,time,0,1]);
1 0.75 Probability 0.5 0.25 0 0 1000 50 0 Time, n 2000 100 State
(3) % Matlab Program % Continuous Time Markov Chain % SIS Epidemic Model % Three Sample Paths Compared to the Deterministic Model clear set(0, DefaultAxesFontSize, 18); set(gca, fontsize,18); beta=1; b=0.25; gam=0.25; N=100; init=2; time=25; sim=3; for k=1:sim clear t s i t(1)=0; i(1)=init; s(1)=n-init; j=1; while i(j)>0 & t(j)<time u1=rand; u2=rand;
a=(beta/n)*i(j)*s(j)+(b+gam)*i(j); probi=(beta*s(j)/n)/(beta*s(j)/n+b+gam); t(j+1)=t(j)-log(u1)/a; if u2 <= probi i(j+1)=i(j)+1; s(j+1)=s(j)-1; else i(j+1)=i(j)-1; s(j+1)=s(j)+1; end j=j+1; end plot(t,i, r-, LineWidth,2) hold on end % Euler s Method Applied to the Deterministic SIS Epidemic Model dt=0.01; x(1)=n-init; y(1)=init; for k=1:time/dt x(k+1)=x(k)+dt*(-beta*x(k)*y(k)/n+(b+gam)*y(k)); y(k+1)=y(k)+dt*(beta*x(k)*y(k)/n-(b+gam)*y(k)); end plot([0:dt:time],y, k--, LineWidth,2);
axis([0,time,0,80]); xlabel( Time ); ylabel( Number of Infectives ); hold off Number of Infectives 80 70 60 50 40 30 20 10 0 0 5 10 15 20 25 Time
(4) % Matlab Program % SDE SIS Epidemic Model % Three Sample Paths using Euler s Method clear beta=1; b=0.25; gam=0.25; N=100; init=2; dt=0.01; time=25; sim=3; for k=1:sim clear i, t j=1; i(j)=init; t(j)=dt; while i(j)>0 & t(j)<25 mu=beta*i(j)*(n-i(j))/n-(b+gam)*i(j); sigma=sqrt(beta*i(j)*(n-i(j))/n+(b+gam)*i(j)); rn=randn; i(j+1)=i(j)+mu*dt+sigma*sqrt(dt)*rn; t(j+1)=t(j)+dt;
j=j+1; end plot(t,i, r-, Linewidth,2); hold on end % Euler s method applied to the deterministic SIS epidemic model. y(1)=init; for k=1:time/dt y(k+1)=y(k)+dt*(beta*(n-y(k))*y(k)/n-(b+gam)*y(k)); end plot([0:dt:time],y, k--, LineWidth,2); axis([0,time,0,80]); xlabel( Time ); ylabel( Number of Infectives ); hold off
Number of Infectives 80 70 60 50 40 30 20 10 0 0 5 10 15 20 25 Time