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)
)
starting date for sims (far enough back to allow states to sort themselves out)
days to go back before first data value
ending date
arguments passed to sim_fun
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)
a data set to compare to, containing date/var/value (current version assumes that only a single state var is included)
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
parameters to fix
function for simulating a single run
(e.g. run_sim_break
,
run_sim_mobility
)
additional arguments to pass to
run_sim
arguments passed to
aggregate.pansim
arguments to pass to condense
(via run_sim
) [not implemented yet?]
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))
print debugging messages?
plot debugging curves? (doesn't work with parallel DEoptim)
keep information on parameter history?
plot debugging curve for only last
parameter set (stored in .debug_plot.pdf
in current
directory)
use differential evolution as first stage?
method arg for mle2
control args for mle2
additional arguments for mle2
random-number seed (for DE)
arguments for DEoptim
lower bounds for DE optimization
upper bounds, ditto
number of parallel workers for DE
mle2
is used to estimate parameters by trajectory matching.
Differential evolution optimization is conducted
via DEoptim
.
Other classic_macpan:
add_d_log()
,
add_updated_vaxrate()
,
aggregate_agecats()
,
calibrate_comb()
,
check_age_cat_compatibility()
,
check_contact_rate_setting()
,
col_multiply()
,
condense_age()
,
condense_params_vax()
,
condense_state()
,
condense_vax()
,
dev_is_tikz()
,
do_step()
,
expand_params_age()
,
expand_params_desc_age()
,
expand_params_desc_variant()
,
expand_params_desc_vax()
,
expand_params_mistry()
,
expand_params_variant()
,
expand_params_vax()
,
expand_state_age()
,
expand_state_vax()
,
expand_stateval_testing()
,
fix_pars()
,
fix_stored()
,
forecast_ensemble()
,
forecast_sim()
,
getData()
,
get_GI_moments()
,
get_Gbar()
,
get_R0()
,
get_doses_per_day()
,
get_evec()
,
get_kernel_moments()
,
get_opt_pars()
,
get_r()
,
invlink_trans()
,
make_betavec()
,
make_beta()
,
make_jac()
,
make_ratemat()
,
make_state()
,
make_test_wtsvec()
,
make_vaxrate()
,
mk_Nvec()
,
mk_agecats()
,
mk_contact_rate_setting()
,
mk_mistry_Nvec()
,
mk_pmat()
,
mk_vaxcats()
,
mle_fun()
,
non_expanded_states
,
rExp()
,
read_params()
,
repair_names_age()
,
restore()
,
run_sim_ageify()
,
run_sim_break()
,
run_sim_loglin()
,
run_sim_mobility()
,
run_sim_range()
,
run_sim()
,
show_ratemat()
,
testify()
,
texify()
,
trans_state_vars()
,
update_contact_rate_setting()
,
update_foi()
,
update_params_mistry()
,
vis_model()
,
write_params()
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
}