Skip to contents

Nowcast

Functions for nowcasting.

epinowcast()
Nowcast using partially observed data
plot(<epinowcast>)
Plot method for epinowcast
summary(<epinowcast>)
Summary method for epinowcast

Data converters

Functions for converting between data formats

enw_add_cumulative()
Calculate cumulative reported cases from incidence of new reports
enw_add_incidence()
Calculate incidence of new reports from cumulative reports
enw_aggregate_cumulative()
Aggregate observations over a given timestep for both report and reference dates.
enw_incidence_to_linelist()
Convert Aggregate Counts (Incidence) to a Line List
enw_linelist_to_incidence()
Convert a Line List to Aggregate Counts (Incidence)

Preprocess

Functions for preprocessing observations

enw_add_delay()
Add a delay variable to the observations
enw_add_max_reported()
Add the maximum number of reported cases for each reference_date
enw_add_metaobs_features()
Add common metadata variables
enw_assign_group()
Assign a group to each row of a data.table
enw_complete_dates()
Complete missing reference and report dates
enw_construct_data()
Construct preprocessed data
enw_extend_date()
Extend a time series with additional dates
enw_filter_reference_dates()
Filter by reference dates
enw_filter_report_dates()
Filter by report dates
enw_flag_observed_observations()
Flag observed observations
enw_impute_na_observations()
Impute NA observations
enw_latest_data()
Filter observations to the latest available reported
enw_metadata()
Extract metadata from raw data
enw_metadata_delay()
Calculate reporting delay metadata for a given maximum delay
enw_missing_reference()
Extract reports with missing reference dates
enw_preprocess_data()
Preprocess observations
enw_reporting_triangle()
Construct the reporting triangle
enw_reporting_triangle_to_long()
Recast the reporting triangle from wide to long format

Model modules

Modular model components

enw_expectation()
Expectation model module
enw_fit_opts()
Format model fitting options for use with stan
enw_missing()
Missing reference data model module
enw_obs()
Setup observation model and data
enw_reference()
Reference date logit hazard reporting model module
enw_report()
Report date logit hazard reporting model module

Helpers for defining model modules

Functions that help with the setup of model modules and that may be specific to individual modules

add_max_observed_delay()
Add maximum observed delay
add_pmfs()
Add probability mass functions
convolution_matrix()
Construct a convolution matrix
enw_reference_by_report()
Construct a lookup of references dates by report
enw_reps_with_complete_refs()
Identify report dates with complete (i.e up to the maximum delay) reference dates
extract_obs_metadata()
Extract observation metadata
extract_sparse_matrix()
Extract sparse matrix elements
latest_obs_as_matrix()
Convert latest observed data to a matrix
simulate_double_censored_pmf()
Simulate daily double censored PMF

Model tools

Generic functions that assist with combining and using modular models

enw_formula_as_data_list()
Format formula data for use with stan
enw_get_cache()
Retrieve Stan cache location
enw_model()
Load and compile the nowcasting model
enw_pathfinder()
Fit a CmdStan model using the pathfinder algorithm
enw_priors_as_data_list()
Convert prior data.frame to list
enw_replace_priors()
Replace default priors with user specified priors
enw_sample()
Fit a CmdStan model using NUTS
enw_set_cache()
Set caching location for Stan models
enw_stan_to_r()
Expose epinowcast stan functions in R
enw_unset_cache()
Unset Stan cache location
remove_profiling()
Remove profiling statements from a character vector representing stan code
write_stan_files_no_profile()
Write copies of the .stan files of a Stan model and its #include files with all profiling statements removed.

Postprocess

Functions for postprocessing model output

build_ord_obs()
Build the ord_obs data.table.
enw_add_latest_obs_to_nowcast()
Add latest observations to nowcast output
enw_nowcast_samples()
Extract posterior samples for the nowcast prediction
enw_nowcast_summary()
Summarise the posterior nowcast prediction
enw_posterior()
Summarise the posterior
enw_pp_summary()
Posterior predictive summary
enw_quantiles_to_long()
Convert summarised quantiles from wide to long format
enw_summarise_samples()
Summarise posterior samples
subset_obs()
Subset observations data table for either modelled dates or not-modelled earlier dates.

Plot

Functions for plotting postprocessed nowcast model output

enw_plot_nowcast_quantiles()
Plot nowcast quantiles
enw_plot_obs()
Generic quantile plot
enw_plot_pp_quantiles()
Plot posterior prediction quantiles
enw_plot_quantiles()
Generic quantile plot
enw_plot_theme()
Package plot theme
plot(<epinowcast>)
Plot method for epinowcast

Model validation

Functions for validating model fits

enw_score_nowcast()
Evaluate nowcasts using proper scoring rules

Formula design tools

Functions that assist with interpreting model formulas

as_string_formula()
Converts formulas to strings
construct_re()
Constructs random effect terms
construct_rw()
Constructs random walk terms
enw_formula()
Define a model using a formula interface
enw_manual_formula()
Define a model manually using fixed and random effects
parse_formula()
Parse a formula into components
re()
Defines random effect terms using the lme4 syntax
remove_rw_terms()
Remove random walk terms from a formula object
rw()
Adds random walks with Gaussian steps to the model.
rw_terms()
Finds random walk terms in a formula object
split_formula_to_terms()
Split formula into individual terms

Model design tools

Functions that assist with designing models

enw_add_cumulative_membership()
Add a cumulative membership effect to a data.frame
enw_add_pooling_effect()
Add a pooling effect to model design metadata
enw_design()
A helper function to construct a design matrix from a formula
enw_effects_metadata()
Extracts metadata from a design matrix
enw_one_hot_encode_feature()
One-hot encode a variable and column-bind it to the original data.table

Datasets

Package datasets used in examples and by users to explore the package functionality

enw_example()
Load a package example
germany_covid19_hosp
Hospitalisations in Germany by date of report and reference

Simulate Datasets

Tools for simulating datasets

enw_simulate_missing_reference()
Simulate observations with a missing reference date.

Check inputs

Functions to check the structure of user inputs

check_calendar_timestep()
Check calendar timestep
check_design_matrix_sparsity()
Check design matrix sparsity
check_group()
Check observations for reserved grouping variables
check_group_date_unique()
Check observations for uniqueness of grouping variables with respect to reference_date and report_date
check_max_delay()
Check appropriateness of maximum delay
check_module()
Check a model module contains the required components
check_modules_compatible()
Check that model modules have compatible specifications
check_numeric_timestep()
Check Numeric Timestep
check_observation_indicator()
Check observation indicator
check_quantiles()
Check required quantiles are present
check_timestep()
Check timestep
check_timestep_by_date()
Check timestep by date
check_timestep_by_group()
Check timestep by group

Utilities

Utility functions

aggregate_rolling_sum()
Internal function to perform rolling sum aggregation
coerce_date()
Coerce Dates
coerce_dt()
Coerce data.tables
date_to_numeric_modulus()
Convert date column to numeric and calculate its modulus with given timestep.
get_internal_timestep()
Get internal timestep
is.Date()
Check an object is a Date
stan_fns_as_string()
Read in a stan function file as a character string