## Gillespie algorithm benchmark question: key for part (d) ## 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 (d). rm(list=ls()) event <- function(time,S,I,R,N=pop.size,R0=basic.reproductive.ratio,rho=rate.of.waning,external=external.introduction.rate,final.time=MAXTIME){ trans.rate <- R0*S*I/N + external recov.rate <- I loss.rate <- rho*R tot.rate <- trans.rate+recov.rate+loss.rate if(tot.rate==0){ return(data.frame(time=final.time,S=S,I=I,R=R)) } event.time <- time+rexp(1,tot.rate) dd <- runif(1) if(dd