Given time series data and a set of starting parameters/structure/etc., calibrate the model via negative binomial maximum likelihood estimation (MLE), simultaneously fitting initial conditions, initial growth rate, time-changes in growth rate, and dispersion parameters.

calibrate(
  start_date = min(data$date) - start_date_offset,
  start_date_offset = 15,
  end_date = max(data$date),
  time_args = list(params_timevar = data.frame(Date = c("2020-03-23", "2020-03-30",
    "2020-04-01"), Symbol = rep("beta0", 3), Relative_value = c(-1, NA, NA))),
  base_params,
  data,
  opt_pars = list(params = c(log_E0 = 4, log_beta0 = -1), logit_time_params = c(-1,
    -1), log_nb_disp = NULL),
  fixed_pars = NULL,
  sim_fun = run_sim_break,
  sim_args = NULL,
  aggregate_args = NULL,
  condense_args = NULL,
  priors = NULL,
  debug = FALSE,
  debug_plot = FALSE,
  debug_hist = FALSE,
  last_debug_plot = FALSE,
  use_DEoptim = FALSE,
  mle2_method = "Nelder-Mead",
  mle2_control = list(maxit = 10000),
  mle2_args = list(),
  seed = NULL,
  DE_args = list(),
  DE_lwr = NULL,
  DE_upr = NULL,
  DE_cores = getOption("mc.cores", 2)
)

Arguments

start_date

starting date for sims (far enough back to allow states to sort themselves out)

start_date_offset

days to go back before first data value

end_date

ending date

time_args

arguments passed to sim_fun

base_params

baseline parameters (an object (vector?) of type params_pansim containing all of the parameters needed for a simulation; some may be overwritten during the calibration process)

data

a data set to compare to, containing date/var/value (current version assumes that only a single state var is included)

opt_pars

starting parameters (and structure). Parameters that are part of the params_pansim parameter vector can be specified within the params element (with prefixes if they are transformed); other parameters can include distributional parameters or time-varying parameters

fixed_pars

parameters to fix

sim_fun

function for simulating a single run (e.g. run_sim_break, run_sim_mobility)

sim_args

additional arguments to pass to run_sim

aggregate_args

arguments passed to aggregate.pansim

condense_args

arguments to pass to condense (via run_sim) [not implemented yet?]

priors

a list of tilde-delimited expressions giving prior distributions expressed in terms of the elements of opt_pars, e.g. list(~dlnorm(rel_beta0[1],meanlog=-1,sd=0.5))

debug

print debugging messages?

debug_plot

plot debugging curves? (doesn't work with parallel DEoptim)

debug_hist

keep information on parameter history?

last_debug_plot

plot debugging curve for only last parameter set (stored in .debug_plot.pdf in current directory)

use_DEoptim

use differential evolution as first stage?

mle2_method

method arg for mle2

mle2_control

control args for mle2

mle2_args

additional arguments for mle2

seed

random-number seed (for DE)

DE_args

arguments for DEoptim

DE_lwr

lower bounds for DE optimization

DE_upr

upper bounds, ditto

DE_cores

number of parallel workers for DE

Details

mle2 is used to estimate parameters by trajectory matching. Differential evolution optimization is conducted via DEoptim.

Examples

library(dplyr)
params <- fix_pars(read_params("ICU1.csv"))
 opt_pars <- list(params=c(log_E0=4, log_beta0=-1,
        log_mu=log(params[["mu"]]), logit_phi1=qlogis(params[["phi1"]])),
                                  logit_rel_beta0=c(-1,-1),
                                   log_nb_disp=NULL)
dd <- (ont_all %>% trans_state_vars() %>% filter(var %in% c("report", "death", "H")))
if (FALSE) {
  cal1 <- calibrate(data=dd, base_params=params, opt_pars=opt_pars, debug_plot=TRUE)
  cal1_DE <- calibrate(data=dd, base_params=params, opt_pars=opt_pars, use_DEoptim=TRUE, DE_cores=1)
  cal2 <- calibrate(data=dd, base_params=params, opt_pars=opt_pars, use_DEoptim=TRUE)
  if (require(bbmle)) {
     -logLik(cal2$mle2)
   }
   attr(cal2,"de")$optim$bestval
}