auxiliary/stratification_functionality_testing/base_models/simulate_COVAX1_ode.R

#' COVAX1
#' 
#' @description A Covid vaccine model
#' 
#' @details The model includes susceptible, presymptomatic, asymptomatic, infected/symptomatic/ill, recovered, and deceased compartments.
#' 
#' This code was generated by the modelbuilder R package.  
#' The model is implemented as a set of ordinary differential equations using the deSolve package. 
#' The following R packages need to be loaded for the function to work: deSolve. 
#' 
#' Starting conditions for model variables 
#' @param S : starting value for Susceptible : numeric
#' @param P : starting value for Presymptomatic : numeric
#' @param A : starting value for Asymptomatic : numeric
#' @param I : starting value for Ill : numeric
#' @param R : starting value for Recovered : numeric
#' @param D : starting value for Deceased : numeric
#' Values for model parameters : numeric 
#' @param bP : transmission by presymptomatic : numeric
#' @param bA : transmission by asymptomatic : numeric
#' @param bI : transmission by ill : numeric
#' @param nu : fraction symptomatic : numeric
#' @param sig : progression to symptomatic : numeric
#' @param gA : recovery of asymptomatic : numeric
#' @param gI : leaving the symptomatic class : numeric
#' @param rho : fraction dying : numeric
#' @param w : immunity wane rate : numeric
#' Values for model times : numeric 
#' @param tstart : Start time of simulation : numeric
#' @param tfinal : Final time of simulation : numeric
#' @param dt : Time step : 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_COVAX1_ode() 
#' # To choose values other than the standard one, specify them like this:  
#' result <- simulate_COVAX1_ode(S = 2000,P = 2,A = 2,I = 2,R = 0,D = 0) 
#' # You can display or further process the result, like this:  
#' plot(result$ts[,'time'],result$ts[,'S'],xlab='Time',ylab='Numbers',type='l') 
#' print(paste('Max number of S: ',max(result$ts[,'S']))) 
#' @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: COVAMOD consortium
#' @section Model creation date: 2020-10-01
#' @section Code Author: generated by the \code{modelbuilder} R package 
#' @section Code creation date: 2020-10-01
#' @export 
 
simulate_COVAX1_ode <- function(S = 1000, P = 1, A = 1, I = 1, R = 0, D = 0, bP = 0.001, bA = 5e-04, bI = 0.001, nu = 0.3, sig = 0.2, gA = 0.125, gI = 0.1, rho = 0.01, w = 0.01, tstart = 0, tfinal = 100, dt = 0.1) 
{ 
  ############################## 
  #Block of ODE equations for deSolve 
  ############################## 
  COVAX1_ode_fct <- function(t, y, parms) 
  {
    with( as.list(c(y,parms)), { #lets us access variables and parameters stored in y and parms by name 
    #StartODES
    #Susceptible : infection by presymptomatic leading to symptomatic infections : infection by presymptomatic leading to asymptomatic infections : infection by asymptomatic leading to symptomatic infections : infection by asymptomatic leading to asymptomatic infections : infection by symptomatic leading to symptomatic infections : infection by symptomatic leading to asymptomatic infections : waning immunity :
    dS_mb = -nu*bP*S*P -(1-nu)*bP*S*P -nu*bA*S*A -(1-nu)*bA*S*A -nu*bI*S*I -(1-nu)*bI*S*I w*R
    #Presymptomatic : infection by presymptomatic : infection by ill : infection by asymptomatic : progression to symptoms :
    dP_mb = +nu*bP*S*P +nu*bA*S*A +nu*bI*S*I -sig*P
    #Asymptomatic : infection by presymptomatic : infection by ill : infection by asymptomatic : recovery :
    dA_mb = +(1-nu)*bP*S*P +(1-nu)*bA*S*A +(1-nu)*bI*S*I -gA*A
    #Ill : progression to symptoms : progression to death : progression to recovery :
    dI_mb = +sig*P -rho*gI*I -(1-rho)*gI*I
    #Recovered : recovery of asymptomatics : recovery of ill : waning immunity :
    dR_mb = +gA*A +(1-rho)*gI*I -w*R
    #Deceased : death :
    dD_mb = +rho*gI*I
    #EndODES
    list(c(dS_mb,dP_mb,dA_mb,dI_mb,dR_mb,dD_mb)) 
  } ) } #close with statement, end ODE code block 
 
  ############################## 
  #Main function code block 
  ############################## 
  #Creating named vectors 
  varvec_mb = c(S = S, P = P, A = A, I = I, R = R, D = D) 
  parvec_mb = c(bP = bP, bA = bA, bI = bI, nu = nu, sig = sig, gA = gA, gI = gI, rho = rho, w = w) 
  timevec_mb = seq(tstart, tfinal,by = dt) 
  #Running the model 
  simout = deSolve::ode(y = varvec_mb, parms = parvec_mb, times = timevec_mb,  func = COVAX1_ode_fct, rtol = 1e-12, atol = 1e-12) 
  #Setting up empty list and returning result as data frame called ts 
  result <- list() 
  result$ts <- as.data.frame(simout) 
  return(result) 
} 
ahgroup/modelbuilder documentation built on April 14, 2024, 2:29 p.m.