Run pandemic simulation

run_sim(
  params,
  state = NULL,
  start_date = "2020-03-20",
  end_date = "2020-05-1",
  params_timevar = NULL,
  dt = 1,
  ndt = 1,
  stoch = c(obs = FALSE, proc = FALSE),
  stoch_start = NULL,
  ratemat_args = NULL,
  step_args = list(),
  ode_args = list(),
  use_ode = FALSE,
  condense = TRUE,
  condense_args = NULL,
  verbose = FALSE,
  use_flex = FALSE,
  flexmodel = NULL,
  obj_fun = NULL
)

Arguments

params

named vector of parameters

state

named vector of states

start_date

starting date (Date or character, any sensible D-M-Y format)

end_date

ending date (ditto)

params_timevar

four-column data frame containing columns 'Date'; 'Symbol' (parameter name/symbol); 'Value'; and 'Type' (rel_orig (relative to value at time zero); rel_prev (relative to previous value); or abs (absolute value at specified time). If a 'Relative_value' column is present, it is renamed to 'Value' and 'Type' is set to rel_orig for back-compatibility.

dt

time step for do_step

ndt

number of internal time steps per time step

stoch

a logical vector with elements "obs" (add obs error?) and "proc" (add process noise?)

stoch_start

dates on which to enable stochasticity (vector of dates with names 'proc' and 'obs')

ratemat_args

additional arguments to pass to make_ratemat

step_args

additional arguments to pass to do_step

ode_args

additional arguments to ode

use_ode

integrate via ODE rather than discrete step?

condense

if TRUE, use condense.pansim to reduce the number of variables in the output (in particular, collapse subclasses and return only one I, H, and ICU variable)

condense_args

arguments to pass to condense (before adding observation error)

verbose

print messages (e.g. about time-varying parameters)?

use_flex

use flexmodel approach

flexmodel

optional flexmodel object

obj_fun

optional TMB objective function computed with tmb_fun

Examples

params <- read_params("ICU1.csv")
paramsS <- update(params,c(proc_disp=0.1,obs_disp=100))
paramsSz <- update(paramsS, zeta=5)
state <- make_state(params=params)
time_pars <- data.frame(Date=c("2020-03-20","2020-03-25"),
                       Symbol=c("beta0","beta0"),
                       Relative_value=c(0.7,0.1),
                       stringsAsFactors=FALSE)
res1 <- run_sim(params,state,start_date="2020-02-01",end_date="2020-06-01")
res1X <- run_sim(params,state,start_date="2020-02-01",end_date="2020-06-01",
                 condense_args=list(keep_all=TRUE))
res1_S <- update(res1, params=paramsS, stoch=c(obs=TRUE, proc=TRUE))
res1_t <- update(res1, params_timevar=time_pars)
#> Warning: specifying params_timevar with Relative_value is deprecated: auto-converting (reported once per session)
res1_S_t <- update(res1_S, params_timevar=time_pars)
#> Warning: specifying params_timevar with Relative_value is deprecated: auto-converting (reported once per session)
res2_S_t <- update(res1_S_t,params=update(paramsS, proc_disp=0.5))
#> Warning: specifying params_timevar with Relative_value is deprecated: auto-converting (reported once per session)
res3_S_t <- update(res2_S_t,stoch_start="2020-04-01")
#> Warning: specifying params_timevar with Relative_value is deprecated: auto-converting (reported once per session)
res3_Sz <- update(res1_S, params=paramsSz)
plot(res3_Sz,log=TRUE,log_lwr=1e-4)