You are on page 1of 53

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

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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
{Xt(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.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

The Following Graphs Illustrate the Dynamics of a


Deterministic versus a Stochastic Epidemic Model
35

Number of Infectives, I(t)

30
25
20
15
10
5
0
0

L.J.S. Allen, TTU

500

1000
Time Steps

1500

2000

Stochastic Epidemic Models - I

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.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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} = pi(t), i {0, 1, 2 . . .}
Rb
Continuous: Prob{X(t) [a, b]} = a p(x, t)dx
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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, 2t, . . .} 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.
Xt {0, 1, 2, . . . , N }
Diffusion Process, Stochastic Differential Equation (SDE): t [0, ), X(t) is
a continuous random variable.
X(t) [0, N ]
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

II. Before we Formulate the Stochastic SIS Epidemic


Models, we Review the Dynamics of the Deterministic SIS
Epidemic Model.
Deterministic SIS:

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 .


L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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:

R0 =

b+

If R0 1, then limt I(t) = 0.




If R0 > 1, then limt I(t) = N 1 R10 .


L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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, 2t, . . .}, 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 ]
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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
pi(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) = (p0(t), p1(t), . . . , pN (t))T
for t = 0, t, 2t, . . . . 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
pji(t) = Prob{I(t + t) = j|I(t) = i}.

L.J.S. Allen, TTU

Stochastic Epidemic Models - 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

i(N i)/N t = b(i)t,

(b + )it = d(i)t,
1 [i(N i)/N + (b + )i]t =
pji(t) =

1 [b(i) + d(i)]t,

0,

L.J.S. Allen, TTU

j =i+1
j =i1
j=i
j 6= i + 1, i, i 1,

Stochastic Epidemic Models - I

The Probability Distribution Associated with the Epidemic


Process Over Time is Found by Repeated Multiplication of
the Transition Matrix.
Matrix P (t) = (pji(t)) is known as the transition matrix:
p(t + t) = P (t)p(t),
where p(t) = (p0(t), . . . , pN (t))T is the probability distribution and P (t) is

1
d(1)t
0
0 1 [b(1) + d(1)]t
d(2)t

0
b(1)t
1 [b(2) + d(2)]t

0
0
b(2)t
.
..
..
.

0
0
0
0
0
0

..

.
0

..

d(N )t
1 d(N )t

Matrix P (t) is stochastic, the column sums equal one.


L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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, 2t, . . .} is timehomogeneous (transition probabilities do not depend on time) and has the
Markov property.
The probability of no infections p0 is an absorbing state.
0

For any initial distribution p(0) = (p0(0), . . . , pN (0))T , zero through a


total of N infections
lim p(t) = (1, 0, . . . , 0)T

L.J.S. Allen, TTU

lim p0(t) = 1.

Stochastic Epidemic Models - I

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, 2t, . . .} is an assignment of a possible value to I(t) for each value
of t.
R0 = 2.
70

Number of Infectives

60
50
40
30
20
10
0
0

10

15

20

25

Time

t = 0.01, N = 100, = 1, b = 0.25, = 0.25, I(0) = 2, and p2(0) = 1.The


MATLAB program is in the Appendix.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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

0
1000

50
2000 100

Time, n

State

Probability distribution for the DTMC SIS model, t = 0.01, N = 100, = 1, b = 0.25,
= 0.25, R0 = 2, I(0) = 2 and p2(0) = 1. MATLAB program is in the Appendix.

Note: Asymptotically, limt p0(t) = 1, the epidemic ends with probability


one. But it may take a long time before p0 1, if N and I(0) are large. In this
example,
p0(t)

L.J.S. Allen, TTU

1
R0

I(0)

2
1
1
= .
=
2
4

Stochastic Epidemic Models - I

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
pi(t) = Prob{I(t) = i}
The probability

pji(t) =

of a transition for small t satisfies


i(N i)/N t + o(t) = b(i)t + o(t),
(b + )it + o(t) = d(i)t + o(t),
1 [i(N i)/N + (b + )i]t + o(t)
= 1 [b(i) + d(i)]t + o(t),
o(t),

j =i+1
j =i1
j=i
otherwise,

where o(t) 0 as t 0.
i i + 1, i i 1, or i i.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

A System of Differential Equations for the Probabilities Can


be Derived Based on the Transition Probabilities.
For small t,
pi(t + t) = pi1(t)[b(i 1)t] + pi+1(t)[d(i + 1)t]
pi(t)[1 (b(i) + d(i))t] + o(t)

Subtracting pi(t), dividing by t, and letting t 0,


dpi
dt
dp0
dt

= pi1b(i 1) + pi+1d(i + 1) pi[b(i) + d(i)]


= p1d(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.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

The Epidemic Process is Captured by a System of


Differential Equations Expressed in Matrix Form.
In matrix notation,
dp
= Qp,
dt
where p(t) = (p0(t), . . . , pN (t))T and Q is known as the generator matrix:
0
0
B0
B
B0
B
B
Q = B0
B ..
B.
B
@0
0

d(1)
[b(1) + d(1)]
b(1)
0
...
0
0

0
d(2)
[b(2) + d(2)]
b(2)
...
0
0

...

0
0 C
C
0 C
C
C
0 C.
C
...
C
C
d(N ) A
d(N )

b(i) = i(N i)/N and d(i) = (b + )i

L.J.S. Allen, TTU

Stochastic Epidemic Models - 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
p(t)
t

= Qp

where
P (t) I
Q = lim
.
t0
t
The Discrete-Time Process can be used to Approximate the ContinuousTime Process.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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 Tn 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:

pjn(t) = a(n)t + o(t)

j=0,j6=n

and
pnn(t) = 1 a(n)t + o(t).

Then the interevent time has an exponential distribution with parameter a(n),
Tn E(a(n))
Prob{Tn t} = 1 exp(a(n)t).
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

For the SIS Epidemic Model, with I(t) = n,

pjn(t) = [b(n) + d(n)]t + o(t)

j=0,j6=n

= [n(N n)/N + (b + )n]t + o(t)

a(n) =

L.J.S. Allen, TTU

n(N n) + (b + )n
N

Stochastic Epidemic Models - I

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
Tn. Let U be uniform random variable on [0, 1] and Fn(t) the cumulative
distribution for Tn
Fn(t) = Prob{Tn t} = 1 exp(a(n)t).
Then
1

Prob{Fn (U ) t}

Prob{Fn(Fn (U )) Fn(t)}

Prob{U Fn(t)}

Fn(t)

The inter-event time Tn, given I(t) = n satisfies


Tn = Fn1(U ) =

L.J.S. Allen, TTU

ln(U )
ln(1 U )
=
.
a(n)
a(n)

Stochastic Epidemic Models - I

Three Sample Paths of the CTMC SIS Model are


Compared to the Deterministic Solution.
R0 = 2
80

Number of Infectives

70
60
50
40
30
20
10
0
0

10

15

20

25

Time

b = 0.25, = 0.25, = 1, N = 100, I(0) = 2, R0 = 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.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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]} =

p(x, t)dx.
a

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
{[x(N x)/N (b + )x]p}
=
t
x
1 2 {[x(N x)/N + (b + )x]p}
+
,
2
2
x
x [0, N ], t [0, ). The first term is known as the drift and second term
diffusion.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

The Stochastic Differential Equation (SDE) Depends on the


Drift and Diffusion Terms.
The Stochastic Differential Equation (SDE) follows directly from the differential
equations,

dI
= I(N I) (b + )I +
dt
N

dW

I(N I) + (b + )I
,
N
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.5

-1

-1.5

0.2

0.4

0.6

0.8

Time

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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
Rb
Prob{I(t) [a, b]} = a p(x, t)dx satisfies the differential equation
p(x, t)
([b(x) d(x)]p(x, t)) 1 2([b(x) + d(x)]p(x, t))
=
+
t
x
2
x2
and the stochastic differential equation (SDE) satisfies
p
dW
dI
= b(I) d(I) + b(I) + d(I)
= drift + diffusion
dt
dt

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

The Drift and Diffusion Terms Determine the Change in


Number of Infections Over Time
SDE:

p
dW
dI
= b(I) d(I) + b(I) + d(I)
dt
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) =
L.J.S. Allen, TTU

t Normal(0, t).
Stochastic Epidemic Models - I

In General, the SDE is Expressed in Terms of the


Parameters for Recovery, Transmission and Birth.
SDE:
dI

= I(N I) (b + )I +
dt
N

dW
I(N I) + (b + )I
,
N
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).

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

Three Sample Paths for the SDE SIS Model are Computed
Numerically and Compared to the Deterministic Solution.
R0 = 2
80

Number of Infectives

70
60
50
40
30
20
10
0
0

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.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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 R0 > 1.
The Stochastic Models Do Capture these Features.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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:

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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:


R0 =

b+

If R0 > 1 and b > 0, then limt I(t) = I > 0.


If R0 > 1 and b = 0, then limt I(t) = 0.
S(0)
> 1.
There is an epidemic if R0
N
If R0 1, then limt I(t) = 0.
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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)
>
>
>
>
it,
(k, j) = (0, 1)
>
>
<
bit,
(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
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

Three Sample Paths of the DTMC SIR Epidemic Model are


Compared to the Solution of the Deterministic Model.
R0 = 2, b = 0
S(0)
= 1.96.
R0
N
35

Number of Infectives, I(t)

30
25
20
15
10
5
0
0

500

1000
Time Steps

1500

2000

t = 0.01, N = 100, = 1, b = 0, = 0.5, S(0) = 98, and I(0) = 2.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

The SDE Model for the SIR Epidemic is a System of Two


It
o SDEs.
For example, in the case with b = 0,
dS
dt
dI
dt

dW1
dW2
SI + B11
+ B12
N
dt
dt

dW1
dW2
SI I + B21
+ B22
N
dt
dt

=
=

where W1 and W2 are two independent Wiener processes


and B = (Bij ) 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.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

Three Stochastic Sample Paths of the SDE SIR Epidemic


Model Are Compared to the Deterministic Solution.
R0 = 2, b = 0
S(0)
= 1.96.
R0
N
35

Number of Infectives

30
25
20
15
10
5
0
0

10
Time

15

20

t = 0.01, N = 100, = 1, b = 0, = 0.5, I(0) = 2.


L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

(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

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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.

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

% Eulers 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

Number of Infectives

60
50
40
30
20
10
0
0

10

15

20

25

Time

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

(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
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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]);

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

Probability

1
0.75
0.5
0.25
0
0

0
1000

50
2000 100

Time, n

L.J.S. Allen, TTU

State

Stochastic Epidemic Models - I

(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;
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

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
% Eulers 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);
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

axis([0,time,0,80]);
xlabel(Time);
ylabel(Number of Infectives);
hold off
80

Number of Infectives

70
60
50
40
30
20
10
0
0

10

15

20

25

Time

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

(4)
% Matlab Program
% SDE SIS Epidemic Model
% Three Sample Paths using Eulers 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;
L.J.S. Allen, TTU

Stochastic Epidemic Models - I

j=j+1;
end
plot(t,i,r-,Linewidth,2);
hold on
end
% Eulers 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

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

80

Number of Infectives

70
60
50
40
30
20
10
0
0

10

15

20

25

Time

L.J.S. Allen, TTU

Stochastic Epidemic Models - I

You might also like