简体   繁体   中英

Gillespie Stochastic Simulation in Discrete Time using R

I'm simulating a Stochastic Simulation for Epidemiology. How do I simulate it in a discrete time? I managed to obtain for continuous time using the coding below.

library(GillespieSSA)    
parms <- c(beta=0.591,sigma=1/8,gamma=1/7)    
x0 <- c(S=50,E=0,I=1,R=0)    
a <- c("beta*S*I","sigma*E","gamma*I")    
nu <- matrix(c(-1,0,0, 1,-1,0, 0,1,-1, 0,0,1),nrow=4,byrow=TRUE)   
set.seed(12345)    
out <- lapply(X=1:10,FUN=function(x) ssa(x0,a,nu,parms,tf=50)$data)
out

How should I alter the coding to get discrete time? Thanking in advance.

The Gillespie algorithm (see this paper ) basically simulates the trajectory of a continuous-time Markov chain (it is a discrete-event simulation approach).

Broadly speakig, this means that each event in out is associated with a continuous time, and that this is inherent to the simulation approach you used (ie, not easy to change).

However, you can easily find out the state of your model at discrete points in time : it is the state of the model before the first event with a higher time stamp.

Example : You observe reaction event e_1 at time 1.932.. , e_2 at time 1.999892.. , and e_3 at time 2.00892.. . The state of the model at time t=2.0 is the state after event e_2 occurred and before event e_3 occurred.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM