#' Host Heterogeneity Model
#'
#' @description An SIR type model stratified for two different types of hosts.
#'
#' @details This model tracks susceptibles, infected and recovered of 2 different types. Think of those types as e.g. males/females, children/adults, etc. The model includes infection, recovery and waning immunity processes for both hosts.
#'
#' This code was generated by the modelbuilder R package.
#' The model is implemented as a set of stochastic equations using the adaptivetau package.
#' The following R packages need to be loaded for the function to work: adpativetau
#'
#' @param S1 : starting value for Susceptible type 1 hosts : numeric
#' @param I1 : starting value for Infected type 1 hosts : numeric
#' @param R1 : starting value for Recovered type 1 hosts : numeric
#' @param S2 : starting value for Susceptible type 2 hosts : numeric
#' @param I2 : starting value for Infected type 2 hosts : numeric
#' @param R2 : starting value for Recovered type 2 hosts : numeric
#' @param b11 : rate of transmission to susceptible type 1 host from infected type 1 host : numeric
#' @param b12 : rate of transmission to susceptible type 1 host from infected type 2 host : numeric
#' @param b21 : rate of transmission to susceptible type 2 host from infected type 1 host : numeric
#' @param b22 : rate of transmission to susceptible type 2 host from infected type 2 host : numeric
#' @param g1 : the rate at which infected type 1 hosts recover : numeric
#' @param g2 : the rate at which infected type 2 hosts recover : numeric
#' @param w1 : the rate at which type 1 host immunity wanes : numeric
#' @param w2 : the rate at which type 2 host immunity wanes : numeric
#' @param tfinal : Final time of simulation : numeric
#' @param rngseed : set random number seed for reproducibility : numeric
#' @return The function returns the output as a list.
#' The time-series from the simulation is returned as a dataframe saved as list element \code{ts}.
#' The \code{ts} dataframe has one column per compartment/variable. The first column is time.
#' @examples
#' # To run the simulation with default parameters:
#' result <- simulate_Host_Heterogeneity_Model_stochastic()
#' # To choose values other than the standard one, specify them like this:
#' result <- simulate_Host_Heterogeneity_Model_stochastic(S1 = 2000,I1 = 2,R1 = 0,S2 = 400,I2 = 2,R2 = 0)
#' # You can display or further process the result, like this:
#' plot(result$ts[,'time'],result$ts[,'S1'],xlab='Time',ylab='Numbers',type='l')
#' print(paste('Max number of S1: ',max(result$ts[,'S1'])))
#' @section Warning: This function does not perform any error checking. So if you try to do something nonsensical (e.g. have negative values for parameters), the code will likely abort with an error message.
#' @section Model Author: Andreas Handel, Alexis Vittengl
#' @section Model creation date: 2020-10-05
#' @section Code Author: generated by the \code{modelbuilder} R package
#' @section Code creation date: 2021-07-19
#' @export
simulate_Host_Heterogeneity_Model_stochastic <- function(S1 = 1000, I1 = 1, R1 = 0, S2 = 200, I2 = 1, R2 = 0, b11 = 0.002, b12 = 0, b21 = 0, b22 = 0.01, g1 = 1, g2 = 1, w1 = 0, w2 = 0, tfinal = 60, rngseed = 123)
{
#Block of ODE equations for adaptivetau
Host_Heterogeneity_Model_fct <- function(y, parms, t)
{
with(as.list(c(y,parms)),
{
#specify each rate/transition/reaction that can happen in the system
rates = c(b11*S1*I1, b12*S1*I2, b21*S2*I1, b22*S2*I2, g1*I1, g2*I2, w1*R1, w2*R2)
return(rates)
}
)
} # end function specifying rates used by adaptive tau
#specify for each reaction/rate/transition how the different variables change
#needs to be in exactly the same order as the rates listed in the rate function
transitions = list(c(S1 = -1,I1 = +1),
c(S1 = -1,I1 = +1),
c(S2 = -1,I2 = +1),
c(S2 = -1,I2 = +1),
c(R1 = +1,I1 = -1),
c(R2 = +1,I2 = -1),
c(R1 = -1,S1 = +1),
c(R2 = -1,S2 = +1))
##############################
#Main function code block
##############################
set.seed(rngseed) #set random number seed for reproducibility
#Creating named vectors
varvec = c(S1 = S1, I1 = I1, R1 = R1, S2 = S2, I2 = I2, R2 = R2)
parvec = c(b11 = b11, b12 = b12, b21 = b21, b22 = b22, g1 = g1, g2 = g2, w1 = w1, w2 = w2)
#Running the model
simout = adaptivetau::ssa.adaptivetau(init.values = varvec, transitions = transitions,
rateFunc = Host_Heterogeneity_Model_fct, params = parvec, tf = tfinal)
#Setting up empty list and returning result as data frame called ts
result <- list()
result$ts <- as.data.frame(simout)
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.