View source: R/regional_epinow.R
regional_epinow | R Documentation |
Efficiently runs epinow()
across multiple regions in an efficient manner
and conducts basic data checks and cleaning such as removing regions with
fewer than non_zero_points
as these are unlikely to produce reasonable
results whilst consuming significant resources. See the documentation for
epinow()
for further information.
By default all arguments supporting input from _opts()
functions are
shared across regions (including delays, truncation, Rt settings, stan
settings, and gaussian process settings). Region specific settings are
supported by passing a named list of _opts()
calls (with an entry per
region) to the relevant argument. A helper function (opts_list()
) is
available to facilitate building this list.
Regions can be estimated in parallel using the {future}
package (see
setup_future()
). The progress of producing estimates across multiple
regions can be tracked using the {progressr}
package. Modify this behaviour
using progressr::handlers()
and enable it in batch by setting
R_PROGRESSR_ENABLE=TRUE
as an environment variable.
regional_epinow(
data,
generation_time = gt_opts(),
delays = delay_opts(),
truncation = trunc_opts(),
rt = rt_opts(),
backcalc = backcalc_opts(),
gp = gp_opts(),
obs = obs_opts(),
stan = stan_opts(),
horizon = 7,
CrIs = c(0.2, 0.5, 0.9),
target_folder = NULL,
target_date,
non_zero_points = 2,
output = c("regions", "summary", "samples", "plots", "latest"),
return_output = is.null(target_folder),
summary_args = list(),
verbose = FALSE,
logs = tempdir(check = TRUE),
...,
reported_cases
)
data |
A |
generation_time |
A call to |
delays |
A call to |
truncation |
A call to |
rt |
A list of options as generated by |
backcalc |
A list of options as generated by |
gp |
A list of options as generated by |
obs |
A list of options as generated by |
stan |
A list of stan options as generated by |
horizon |
Numeric, defaults to 7. Number of days into the future to forecast. |
CrIs |
Numeric vector of credible intervals to calculate. |
target_folder |
Character string specifying where to save results (will create if not present). |
target_date |
Date, defaults to maximum found in the data if not specified. |
non_zero_points |
Numeric, the minimum number of time points with non-zero cases in a region required for that region to be evaluated. Defaults to 7. |
output |
A character vector of optional output to return. Supported
options are the individual regional estimates ("regions"), samples
("samples"), plots ("plots"), copying the individual region dated folder into
a latest folder (if |
return_output |
Logical, defaults to FALSE. Should output be returned, this automatically updates to TRUE if no directory for saving is specified. |
summary_args |
A list of arguments passed to |
verbose |
Logical defaults to FALSE. Outputs verbose progress messages
to the console from |
logs |
Character path indicating the target folder in which to store log
information. Defaults to the temporary directory if not specified. Default
logging can be disabled if |
... |
Pass additional arguments to |
reported_cases |
Deprecated; use |
A list of output stratified at the top level into regional output and across region output summary output
epinow()
estimate_infections()
setup_future()
regional_summary()
# set number of cores to use
old_opts <- options()
options(mc.cores = ifelse(interactive(), 4, 1))
# uses example case vector
cases <- example_confirmed[1:60]
cases <- data.table::rbindlist(list(
data.table::copy(cases)[, region := "testland"],
cases[, region := "realland"]
))
# run epinow across multiple regions and generate summaries
# samples and warmup have been reduced for this example
# for more examples, see the "estimate_infections examples" vignette
def <- regional_epinow(
data = cases,
generation_time = gt_opts(example_generation_time),
delays = delay_opts(example_incubation_period + example_reporting_delay),
rt = rt_opts(prior = list(mean = 2, sd = 0.2)),
stan = stan_opts(
samples = 100, warmup = 200
),
verbose = interactive()
)
options(old_opts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.