Lecture 02
Lecture 02
Michael Höhle1
1 Departmentof Mathematics
Stockholm University, Sweden
1
LaMo: 2020-06-16 @ 22:13:45
MT3002 Michael Höhle 1 / 40
Reed-Frost model Deterministic SIR model Stochastic SIR model in continuous time References
Overview
1 Reed-Frost model
Outline
1 Reed-Frost model
Exercise 1
Show that the one-step success probability in the Markov chain
equation on the previous slide is 1 − (1 − w )yt .
0.4
0.2
0.0
0 1 2 3 4 5 6 7 8 9 11 13 15 17 19
Final size
0.30
0.30
0.30
Probability
Probability
Probability
Probability
0.15
0.15
0.15
0.15
0.00
0.00
0.00
0.00
0 18 38 58 78 98 0 18 38 58 78 98 0 18 38 58 78 98 0 18 38 58 78 98
0.30
0.30
0.30
Probability
Probability
Probability
Probability
0.15
0.15
0.15
0.15
0.00
0.00
0.00
0.00
0 18 38 58 78 98 0 18 38 58 78 98 0 18 38 58 78 98 0 18 38 58 78 98
fsize.RF <-
function(n, m, w, samples) {
#Initial susceptible
xj <- matrix(data=n,nrow=samples,ncol=1)
#Initial infectives
yj <- matrix(data=m,nrow=samples,ncol=1)
#Loop over all (samples) simulations until they all are ceased.
while (sum(yj>0) & sum(xj>0)) {
#Sample from all processes concurrently
yj <- ifelse(xj > 0, rbinom(samples, xj, 1-(1-w)^yj), 0)
#Update all xj
xj <- xj - yj
}
#Done
return(n-xj)
}
Statistical inference
Estimation of w from time series data y = (y0 , y1 , y2 , . . . , yK )
using the binomial likelihood
K −1
y
Y
L(w ) ∝ pt t+1 (1 − pt )xt −yt+1 ,
t=0
Example
######################################################################
# Likelihood function for the Reed-Frost model
#
# Parameters:
# w.logit - logit(w) to have unrestricted parameter space
# x - vector containing the number of susceptibles at each time
# y - vector containing the number of infectious at each time
#
######################################################################
l <- function(w.logit,x,y) {
if (length(x) != length(y)) { stop("x and y need to be the same length") }
K <- length(x)
w <- plogis(w.logit)
p <- 1 - (1-w)^y
return(sum(dbinom( y[-1], size=x[-K], prob=p[-K],log=TRUE)))
}
# Epidemic D in Table 4.1 of Daley and Gani (1999), assuming all susceptibles got infected
y <- c(1, 4, 14, 10, 1, 0)
x <- numeric(length(y))
x[1] <- sum(y[-1])
x[2:length(x)] <- x[1]-cumsum(y[2:length(y)])
Inference for x0
−19
−20
−21
30 35 40 45
x0
Outline
1 Reed-Frost model
40
20
0
0 10 20 30 40 50 60
Example
Number of infected I (t) for γ = 0.3, N = 2 × 104 , I (0) = 1
and different values of β.
10000 15000 20000
β = 1.5e−04
β = 4.5e−05
β = 3.0e−05
I(t)
5000
0
0 10 20 30 40 50
time
Use deSolve::lsoda
sim <- lsoda(y=c(N-1,1), times=times, func=sir,parms=c(beta.grid[1],gamma))
head(sim, n=3)
## time 1 2
## [1,] 0.00000000 19999.00 1.000000
## [2,] 0.05005005 19998.84 1.144682
## [3,] 0.10010010 19998.66 1.310297
Euler−method (h=0.1)
12000
lsoda
8000
I(t)
4000
0
0 5 10 15 20
time
Example cont.
β = 1.5e−04
β = 4.5e−05
β = 3.0e−05
S(t)
5000
0
0 10 20 30 40 50
time
CSFV outbreak
80
LS fit
No. infectious herds
LS−sqrt fit
60
40
20
0
0 10 20 30 40 50 60
LS fit
No. infectious herds
LS−sqrt fit
60
Poisson fit
40
20
0
0 10 20 30 40 50 60
Exercise
Exercise 2
Read the blog post “Flatten the COVID-19 curve” and experiment
with different containment strategies using the Shiny App. Discuss
the pros and cons of different strategies. Discuss limitations of the
model when used to evaluate strategies.
Outline
1 Reed-Frost model
60
40
20
0
0 5 10 15 20
Time
#Possible events
eventLevels <- c("S->I","I->R")
#Initialize result
events <- data.frame(t=t,x=x,y=y,event=NA)
#Loop until we are past time T
while (t < T & (y>0)) {
#Draw the waiting type for each possible event
wait <- rexp(2,c("S->I"=beta*x*y,"I->R"=gamma*y))
#Which event occurs first
i <- which.min(wait)
#Advance Time
t <- t+wait[i]
#Update population according to the eventy type
if (eventLevels[i]=="S->I") { x <- x-1 ; y <- y+1}
if (eventLevels[i]=="I->R") { y <- y-1 }
#Store result
events <- rbind(events,c(t,x,y,i))
}
#Recode event type and return
events$event <- factor(eventLevels[events$event], levels=eventLevels)
return(events)
}
20
10
0
0 5 10 15 20 25 30 35
Time
Exercise
Exercise 3
Set β = 0.01 and γ = 0.5 and S(0) = 100 and I (0) = 1. Simulate
1000 instances of the final size of the epidemic using rSIR and
make a histogram of the result.
C (t) ∼ Bin(S(t), 1 − πt )
1 − πt = 1 − exp{−λ(t)} ≈ λ(t), so
Literature I