## ---- setseed, echo=FALSE----------------------------------------------------- set.seed(1) knitr::opts_chunk$set(fig.width = 8, fig.height = 6) ## ----------------------------------------------------------------------------- library(GillespieSSA) ## ----------------------------------------------------------------------------- parms <- c(c = 1) # Rate parameter M <- 50 # Number of chain reactions simName <- "Linear Chain System" # Simulation name tf <- 5 # Final time ## ----------------------------------------------------------------------------- x0 <- c(1000, rep(0, M)) names(x0) <- paste0("x", seq_len(M+1)) ## ----------------------------------------------------------------------------- nu <- matrix(rep(0, M * (M+1)), ncol = M) nu[cbind(seq_len(M), seq_len(M))] <- -1 nu[cbind(seq_len(M)+1, seq_len(M))] <- 1 ## ----------------------------------------------------------------------------- a <- paste0("c*x", seq_len(M)) ## ----direct------------------------------------------------------------------- set.seed(1) out <- ssa( x0 = x0, a = a, nu = nu, parms = parms, tf = tf, method = ssa.d(), simName = simName, verbose = FALSE, consoleInterval = 1 ) ssa.plot(out, show.title = TRUE, show.legend = FALSE) ## ----etl---------------------------------------------------------------------- set.seed(1) out <- ssa( x0 = x0, a = a, nu = nu, parms = parms, tf = tf, method = ssa.etl(tau = .1), simName = simName, verbose = FALSE, consoleInterval = 1 ) ssa.plot(out, show.title = TRUE, show.legend = FALSE) ## ----btl---------------------------------------------------------------------- set.seed(1) out <- ssa( x0 = x0, a = a, nu = nu, parms = parms, tf = tf, method = ssa.btl(f = 50), simName = simName, verbose = FALSE, consoleInterval = 1 ) ssa.plot(out, show.title = TRUE, show.legend = FALSE) ## ----otl---------------------------------------------------------------------- set.seed(1) out <- ssa( x0 = x0, a = a, nu = nu, parms = parms, tf = tf, method = ssa.otl(), simName = simName, verbose = FALSE, consoleInterval = 1 ) ssa.plot(out, show.title = TRUE, show.legend = FALSE)