calibrate | R Documentation |
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)
)
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 |
base_params |
baseline parameters (an object (vector?) of
type |
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 |
fixed_pars |
parameters to fix |
sim_fun |
function for simulating a single run
(e.g. |
sim_args |
additional arguments to pass to
|
aggregate_args |
arguments passed to
|
condense_args |
arguments to pass to |
priors |
a list of tilde-delimited expressions giving prior
distributions expressed in terms of the elements of
|
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 |
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 |
DE_lwr |
lower bounds for DE optimization |
DE_upr |
upper bounds, ditto |
DE_cores |
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")))
## Not run:
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
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.