epinowcast | R Documentation |
Provides a user friendly interface around package functionality to produce a nowcast from observed preprocessed data, and a series of user defined models. By default a model that assumes a fixed parametric reporting distribution with a flexible expectation model is used. Explore the individual model components for additional documentation and see the package case studies for example model specifications for different tasks.
epinowcast(
data,
reference = epinowcast::enw_reference(parametric = ~1, distribution = "lognormal",
non_parametric = ~0, data = data),
report = epinowcast::enw_report(non_parametric = ~0, structural = ~0, data = data),
expectation = epinowcast::enw_expectation(r = ~0 + (1 | day:.group), generation_time =
1, observation = ~1, latent_reporting_delay = 1, data = data),
missing = epinowcast::enw_missing(formula = ~0, data = data),
obs = epinowcast::enw_obs(family = "negbin", data = data),
fit = epinowcast::enw_fit_opts(sampler = epinowcast::enw_sample, nowcast = TRUE, pp =
FALSE, likelihood = TRUE, debug = FALSE, output_loglik = FALSE),
model = epinowcast::enw_model(),
priors,
...
)
data |
Output from |
reference |
The reference date indexed reporting process model
specification as defined using |
report |
The report date indexed reporting process model
specification as defined using |
expectation |
The expectation model specification as defined using
|
missing |
The missing reference date model specification as defined
using |
obs |
The observation model as defined by |
fit |
Model fit options as defined using |
model |
The model to use within |
priors |
A |
... |
Additional model modules to pass to |
A object of the class "epinowcast" which inherits from
enw_preprocess_data()
and data.table
, and combines the input data,
priors, and output from the sampler specified in enw_fit_opts()
.
Other epinowcast:
plot.epinowcast()
,
summary.epinowcast()
# Load data.table and ggplot2
library(data.table)
library(ggplot2)
# Use 2 cores
options(mc.cores = 2)
# Load and filter germany hospitalisations
nat_germany_hosp <-
germany_covid19_hosp[location == "DE"][age_group == "00+"]
nat_germany_hosp <- enw_filter_report_dates(
nat_germany_hosp,
latest_date = "2021-10-01"
)
# Make sure observations are complete
nat_germany_hosp <- enw_complete_dates(
nat_germany_hosp,
by = c("location", "age_group")
)
# Make a retrospective dataset
retro_nat_germany <- enw_filter_report_dates(
nat_germany_hosp,
remove_days = 40
)
retro_nat_germany <- enw_filter_reference_dates(
retro_nat_germany,
include_days = 40
)
# Get latest observations for the same time period
latest_obs <- enw_latest_data(nat_germany_hosp)
latest_obs <- enw_filter_reference_dates(
latest_obs,
remove_days = 40, include_days = 20
)
# Preprocess observations (note this maximum delay is likely too short)
pobs <- enw_preprocess_data(retro_nat_germany, max_delay = 20)
# Fit the default nowcast model and produce a nowcast
# Note that we have reduced samples for this example to reduce runtimes
nowcast <- epinowcast(pobs,
fit = enw_fit_opts(
save_warmup = FALSE, pp = TRUE,
chains = 2, iter_warmup = 500, iter_sampling = 500
)
)
nowcast
# plot the nowcast vs latest available observations
plot(nowcast, latest_obs = latest_obs)
# plot posterior predictions for the delay distribution by date
plot(nowcast, type = "posterior") +
facet_wrap(vars(reference_date), scale = "free")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.