#' Basic Virus Model
#'
#' @description A basic virus infection model with 3 compartments
#'
#' @details The model includes uninfected and infected target cells, as well as free virus. The processes that are modeled are infection, virus production, uninfected cell birth and death, infected cell and virus death.
#'
#' This code was generated by the modelbuilder R package.
#' The model is implemented as a set of discrete time equations using a for loop.
#' The following R packages need to be loaded for the function to work: none
#'
#' @param U : starting value for Uninfected cells : numeric
#' @param I : starting value for Infected cells : numeric
#' @param V : starting value for Virus : numeric
#' @param n : rate of new uninfected cell replenishment : numeric
#' @param dU : rate at which uninfected cells die : numeric
#' @param dI : rate at which infected cells die : numeric
#' @param dV : rate at which virus is cleared : numeric
#' @param b : rate at which virus infects cells : numeric
#' @param p : rate at which infected cells produce virus : numeric
#' @param g : possible conversion factor for virus units : 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_Basic_Virus_Model_discrete()
#' # To choose values other than the standard one, specify them like this:
#' result <- simulate_Basic_Virus_Model_discrete(U = 2e+05,I = 0,V = 2)
#' # You can display or further process the result, like this:
#' plot(result$ts[,'time'],result$ts[,'U'],xlab='Time',ylab='Numbers',type='l')
#' print(paste('Max number of U: ',max(result$ts[,'U'])))
#' @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
#' @section Model creation date: 2022-05-09
#' @section Code Author: generated by the \code{modelbuilder} R package
#' @section Code creation date: 2022-05-09
#' @export
simulate_Basic_Virus_Model_discrete <- function(U = 1e+05, I = 0, V = 1, n = 0, dU = 0, dI = 1, dV = 2, b = 2e-05, p = 5, g = 1, tstart = 0, tfinal = 30, dt = 0.1)
{
#Function that encodes simulation loop
Basic_Virus_Model_fct <- function(vars, pars, times)
{
with( as.list(c(vars,pars)), {
ts = data.frame(cbind(times, matrix(0,nrow=length(times),ncol=length(vars))))
colnames(ts) = c('time','U','I','V')
ct=1 #a counter to index array
for (t in times)
{
ts[ct,] = c(t,U,I,V)
Up = U + dt*(+n -dU*U -b*V*U)
Ip = I + dt*(+b*V*U -dI*I)
Vp = V + dt*(+p*I -dV*V -b*g*V*U)
U = Up
I = Ip
V = Vp
ct = ct + 1
} #finish loop
return(ts)
}) #close with statement
} #end function encoding loop
##############################
#Main function code block
##############################
#Creating named vectors
varvec = c(U = U, I = I, V = V)
parvec = c(n = n, dU = dU, dI = dI, dV = dV, b = b, p = p, g = g)
timevec = seq(tstart, tfinal,by = dt)
#Running the model
simout <- Basic_Virus_Model_fct(vars = varvec, pars = parvec, times = timevec)
#Setting up empty list and returning result as data frame called ts
result <- list()
result$ts <- simout
return(result)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.