negative log-likelihood function

mle_fun(
  p,
  data,
  debug = FALSE,
  debug_plot = FALSE,
  debug_hist = FALSE,
  opt_pars,
  base_params,
  start_date = min(data$date),
  end_date = max(data$date),
  time_args = NULL,
  sim_args = NULL,
  sim_fun = run_sim_break,
  checkpoint = FALSE,
  aggregate_args = NULL,
  priors = NULL,
  na_penalty = 1e+06,
  ...
)

Arguments

p

parameter vector (in unlisted form)

data

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

debug

print debugging messages?

debug_plot

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

debug_hist

keep information on parameter history?

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

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)

start_date

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

end_date

ending date

time_args

arguments passed to sim_fun

sim_args

additional arguments to pass to run_sim

sim_fun

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

checkpoint

save file containing call information?

aggregate_args

arguments passed to aggregate.pansim

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))

na_penalty

value to add to NLL for NA values in log-likelihood

...

unused (but useful in case junk needs to be discarded)

Examples

library(dplyr)
p <- read_params("ICU1.csv")
op <- get_opt_pars(p)
dd <- ont_all %>% trans_state_vars() %>% filter(var %in% c("H","death"))
mle_fun(p=unlist(op), dd, opt_pars=op, base_params=p)
#> [1] 318.4274
op <- op["params"] ## exclude log_nb_disp
try(mle_fun(p=unlist(op), dd, opt_pars=op, base_params=p))
#> Error in mle_fun(p = unlist(op), dd, opt_pars = op, base_params = p) : 
#>   dispersion params must be specified in opt_pars *or* parameters
p2 <- update(p, obs_disp=2)
mle_fun(p=unlist(op), dd, opt_pars=op, base_params=p2)
#> [1] 875.1008
p3 <- update(p, obs_disp_H=2, obs_disp_death=2)
mle_fun(p=unlist(op), dd, opt_pars=op, base_params=p3)
#> [1] 875.1008