## Gillespie algorithm benchmark question: key for part (c) ## Meaningful Modeling of Epidemiological Data, 2012 ## AIMS, Muizenberg ## Juliet Pulliam, 2011,2012 ## The question leads you through the construction of a stochastic ## SIRS model using the Gillespie algorithm. ## ## This is example code for part (c). rm(list=ls()) event <- function(time,S,I,R,N=pop.size,R0=basic.reproductive.ratio,rho=rate.of.waning){ trans.rate <- R0*S*I/N recov.rate <- I loss.rate <- rho*R tot.rate <- trans.rate+recov.rate+loss.rate event.time <- time+rexp(1,tot.rate) dd <- runif(1) if(dd0){ next.time <- event(next.time$time,next.time$S,next.time$I,next.time$R) ts <- rbind(ts,next.time) } plot(ts$time,ts$I,type="l",xlab="Time",ylab="Number infectious",bty="n")