Adding Values In a Stochastic Simulation using R -


here i've managed extract extract time in discrete form such 1,2,3...,50 each simulation of users. but, since there no value interval 20-21 , more, there coding such can add value inside myself? because, if there no reading time interval, means readings same until next interval. coding used below:

library(gillespiessa)  parms <- c(beta=0.591,sigma=1/8,gamma=1/7)  x0 <- c(s=50,e=0,i=1,r=0)  <- 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:1,fun=function(x)  ssa(x0,a,nu,parms,tf=50)$data)  out a<-as.data.frame(out)  idx <- diff(ceiling(a$v1)) == 1 a[idx,] 

## change ==1 >0 idx <- diff(ceiling(a$v1)) > 0   ## discrete time series discrete.data <- a[idx,]  ## last time step value end.time <- ceiling(tail(discrete.data$v1,1))  ## create empty data frame time steps new.df <- data.frame(t=0:end.time, s=0, e=0, i=0, r=0)  ## replace time steps have valid values new.df[new.df$t %in% ceiling(discrete.data$v1),2:5] <- discrete.data[,2:5]   

if necessary missing values can replace na, depends on how want handle them.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -