Top-level calibration based on mobility, splines, and phenomenological heterogeneity. This function is a wrapper for calibrate, which first sets up the model matrix for time-dependent transmission rates \(\beta(t)\). For example, for splines, it sets up the spline basis and the coefficients of each basis function. For mobility, it sets up the slope and intercept parameters (since mobility is treated as a log-linear function between break points).

calibrate_comb(
  data,
  params,
  opt_pars = NULL,
  mob_data = NULL,
  mob_breaks = NULL,
  mob_breaks_int = FALSE,
  mob_logist_scale = NA,
  spline_days = 14,
  spline_setback = 0,
  spline_extrap = c("linear", "constant"),
  spline_df = NA,
  knot_quantile_var = NA,
  spline_pen = 0,
  spline_type = "bs",
  spline_int = FALSE,
  testing_data = NULL,
  maxit = 10000,
  skip.hessian = FALSE,
  use_DEoptim = TRUE,
  DE_cores = 1,
  beta_break_dates = NULL,
  use_mobility = FALSE,
  use_phenomhet = FALSE,
  use_spline = FALSE,
  use_testing = FALSE,
  vars = NULL,
  debug_plot = interactive(),
  debug = FALSE,
  debug_hist = FALSE,
  return_val = c("fit", "X", "formula", "args", "time_args"),
  start_date = NULL,
  priors = list(),
  ...
)

Arguments

data

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

params

parameters

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

mob_data

mobility data

mob_breaks

vector of breakpoints for piecewise mobility model

mob_breaks_int

(logical) specifies whether the intercept of the mobility/transmission relationship changes at each mobility breakpoint. The default (FALSE) specifies that mobility in 'mobility period' i is beta0*(rel_mobility)^p_i; TRUE would specify beta0*(a_i)*(rel_mobility)^p_i, with a_1==1.

mob_logist_scale

specifies the scale of the smooth (logistic) transition between mobility periods, in days: if it is NA (default), the model uses sharp breaks for a piecewise-constant model. Otherwise, the parameter used makes a logistic transition between the two periods with the specified scale.

spline_days

days between spline knots

spline_setback

days before end of time series to set boundary knots for spline (this implies linear extrapolation after knots if spline_type="ns" is specified, which is probably wise)

spline_extrap

spline extrapolation model ("linear" or "constant")

spline_df

overall spline degrees of freedom

knot_quantile_var

variable to use cum dist for knotspacing

spline_pen

penalization for spline

spline_type

spline type ("ns" for natural spline or "bs" for b-spline)

spline_int

spline intercept (??)

testing_data

data frame with columns containing dates (Date) and testing intensity (intensity) (= tests per capita per day)

maxit

maximum iterations for Nelder-Mead/optimization step

skip.hessian

skip Hessian calculation?

use_DEoptim

use differential evolution as first stage?

DE_cores

number of parallel workers for DE

beta_break_dates

discrete break dates for transmission changes

use_mobility

include mobility as a covariate in the model?

use_phenomhet

include phenomenological heterogeneity?

use_spline

include spline?

use_testing

include variation in testing intensity?

vars

which vars to use? (default is all in data)

debug_plot

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

debug

print debugging messages?

debug_hist

keep information on parameter history?

return_val

"fit" (return calibrated value); "X" (short-circuit/return model matrix?); "formula" (return log-linear formula for time-varying beta)

start_date

start date

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

...

extra args

Examples

if (require(dplyr)) {
  dd <- ont_all %>% trans_state_vars() %>%
       filter(var %in% c("H","report"))
 params <- read_params("ICU1.csv")
 ## quick and dirty example (maximize speed)
if (FALSE) {
 calibrate_comb(data=dd, params=params,
               use_spline=TRUE,
              maxit=10, skip.hessian=TRUE, use_DEoptim =FALSE)
X <-  calibrate_comb(data=dd, params=params,
              use_spline=TRUE,
              spline_type="ns",
              spline_setback=1,
              spline_extrap="constant",
              return_val="X")
matplot(X, ylab="")
form <-  calibrate_comb(data=dd, params=params,
              use_spline=TRUE,
              spline_type="ns",
              spline_setback=1,
              spline_extrap="constant",
              return_val="formula")
print(form)
}
}