Learn R Programming

Baseline nowcast

Summary

Nowcasting right-truncated epidemiological data is critical for timely public health decision-making, as reporting delays can create misleading impressions of declining trends in recent data. This package provides nowcasting methods based on using empirical delay distributions and uncertainty from past performance. It is also designed to be used as a baseline method for developers of new nowcasting methods. For more details on the performance of the method(s) in this package applied to case studies of COVID-19 and norovirus, see our recent paper at https://wellcomeopenresearch.org/articles/10-614. The package supports standard data frame inputs with reference date, report date, and count columns, as well as the direct use of reporting triangles, and is compatible with ‘epinowcast’ objects. Alongside an opinionated default workflow, it has a low-level pipe-friendly modular interface, allowing context-specific workflows. It can accommodate a wide spectrum of reporting schedules, including mixed patterns of reference and reporting (daily-weekly, weekly-daily). It also supports sharing delay distributions and uncertainty estimates between strata, as well as custom uncertainty models and delay estimation methods.

Installation

You can install the latest released version using:

install.packages("baselinenowcast")

Alternatively, you can install the latest GitHub release from our r-universe repository:

install.packages("baselinenowcast", repos = "https://epinowcast.r-universe.dev")

To install the development version from GitHub, use the pak package:

pak::pak(file.path("epinowcast", "baselinenowcast"))

Another option for installation is using the remotes package:

remotes::install_github(file.path("epinowcast", "baselinenowcast"))

Resources

We provide a range of other documentation, case studies, and community spaces to ask (and answer!) questions:

Our organisation website includes links to other resources, guest posts, and seminar schedule for both upcoming and past recordings.

Our community forum has areas for question and answer and considering new methods and tools, among others. If you are generally interested in real-time analysis of infectious disease, you may find this useful even if you do not use baselinenowcast.

Contributing

We welcome contributions and new contributors! We particularly appreciate help on identifying and identified issues. Please check and add to the issues, and/or add a pull request and see our contributing guide for more information.

How to make a bug report or feature request

Please briefly describe your problem and what output you expect in an issue. See our contributing guide for more information.

Code of Conduct

Please note that the baselinenowcast project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Citation

If you use baselinenowcast in your work, please consider citing it with citation("baselinenowcast") (or print(citation("baselinenowcast"), bibtex = TRUE)):

To cite baselinenowcast in publications please use the following.

  Johnson KE, Tang M, Tyszka E, Nemcova B, Wolffram D, Ergas R, Reich
  NG, Funk S, Mellor J, Bracher J, Abbott S (2025). "Baseline
  nowcasting methods for handling delays in epidemiological data."
  _Wellcome Open Research_. doi:10.12688/wellcomeopenres.25027.1
  <https://doi.org/10.12688/wellcomeopenres.25027.1>,
  <https://wellcomeopenresearch.org/articles/10-614>.

A BibTeX entry for LaTeX users is

  @Article{,
    title = {Baseline nowcasting methods for handling delays in epidemiological data},
    author = {Kaitlyn E. Johnson and Maria Tang and Emily Tyszka and Barbora Nemcova and Daniel Wolffram and Rosa Ergas and Nicholas G. Reich and Sebastian Funk and Jonathon Mellor and Johannes Bracher and Sam Abbott},
    year = {2025},
    journal = {Wellcome Open Research},
    doi = {10.12688/wellcomeopenres.25027.1},
    url = {https://wellcomeopenresearch.org/articles/10-614},
  }

  Johnson KE, Tyszka E, Bracher J, Funk S, Abbott S (2025).
  _baselinenowcast: Methods for baseline nowcasting right-truncated
  epidemiological data_.
  <https://github.com/epinowcast/baselinenowcast/>.

A BibTeX entry for LaTeX users is

  @Manual{,
    license = {MIT},
    title = {baselinenowcast: Methods for baseline nowcasting right-truncated epidemiological data},
    author = {Kaitlyn E. Johnson and Emily Tyszka and Johannes Bracher and Sebastian Funk and Sam Abbott},
    year = {2025},
    url = {https://github.com/epinowcast/baselinenowcast/},
  }

Contributors

All contributions to this project are gratefully acknowledged using the allcontributors package following the allcontributors specification. Contributions of any kind are welcome!

Code

kaitejohnson, seabbs, TimTaylor, jamesmbaazam, sbfnk

Issue Authors

jonathonmellor, swo, jcblemai, lauraajones2

Issue Contributors

jbracher, SamuelBrand1

Copy Link

Version

Install

install.packages('baselinenowcast')

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Kaitlyn Johnson

Last Published

February 3rd, 2026

Functions in baselinenowcast (0.2.0)

as_reporting_triangle.triangle

Convert ChainLadder triangle to reporting_triangle format
.add_days

Internal: Add days to dates
baselinenowcast.reporting_triangle

Create a dataframe of nowcast results from a single reporting triangle
assert_reporting_triangle

Assert validity of reporting_triangle objects
baselinenowcast_df-class

Nowcast Data.frame Object
assert_baselinenowcast_df

Assert validity of baselinenowcast_df objects
baselinenowcast

Generate a nowcast
combine_obs_with_pred

Combine observed data with a single prediction draw
baselinenowcast.data.frame

Create a dataframe of nowcast results from a dataframe of cases indexed by reference date and report date
.add_months

Internal: Add months to dates
.add_weeks

Internal: Add weeks to dates
.check_lhs_not_only_zeros

Check if there are non-zero-values on the LHS of NAs
assert_delays_unit

Validate each item in the reporting triangle
.check_against_requirements

Check target size against number of reference times available and the number required
.add_years

Internal: Add years to dates
.apply_mask

Apply mask to extract the elements of the matrix that are both true
.assign_allocation_from_ns

Assign number of reference times to delay and uncertainty from the sizes
.calculate_ns

Helper function to calculate various size requirements
.calc_expectation

Calculate the updated rows of the expected nowcasted triangle
.calc_n_retro_nowcast_times

Calculate the number of retrospective nowcast times that can be used after aggregating
.diff_days

Internal: Compute day difference between dates
.check_na_bottom_right

Check if matrix has valid NA pattern
.compute_nowcast_stats

Compute nowcast requirement statistics
.compute_zero_stats

Compute zero value statistics
.compute_quantile_delay_stats

Compute quantile delay statistics for complete rows
.count_negative_rows

Count rows with negative values
.compute_complete_row_stats

Compute complete row statistics
.combine_triangle_dfs

Combine triangle data.frames
.check_obs_and_pred

Check observations and predictions are compatible
.diff_months

Internal: Compute month difference between dates
.rename_cols

Rename required columns
.perform_allocation_process

Perform the allocation process
.diff_years

Internal: Compute year difference between dates
.format_reference_date_range

Get formatted reference date range string
.diff_weeks

Internal: Compute week difference between dates
.get_triangle_info

Get triangle dimension information
.filter_to_recent_horizons

Filter to recent horizons
.handle_target_exceeds_avail

Helper for when target exceeds available reference times
.display_triangle_basics

Display basic triangle information
.extract_predictions

Extract from one matrix only elements that are missing in another
.validate_rep_tri_args

Validate reporting_triangle constructor arguments
.validate_inputs_allocation

Helper function to validate allocation parameters
.update_triangle_matrix

Update reporting_triangle with new matrix data
.safelydoesit

Safe iterator
.validate_multiple_inputs

Validate the inputs to estimate_and_apply_uncertainty() to ensure that the reporting triangle, point nowcast matrix, and specified maximum delay are correct.
.split_df_by_cols

Split dataframe into a list of dataframes by the entries in the specified columns
.validate_delay

Validate the delay PMF if it is passed in
.validate_inputs_uncertainty

Validate the specified number of reference times meets the minimum requirements
.validate_for_delay_estimation

Validate reporting_triangle for delay estimation Domain-specific checks to ensure the reporting triangle is suitable for delay estimation in estimate_delay().
.validate_delay_and_triangle

Validate triangle to nowcast and delay PMF together Various checks to make sure that the reporting triangle and the delay PMF passed in to apply_delay() are formatted properly and compatible.
example_downward_corr_rt

Example reporting triangle with downward corrections
estimate_uncertainty

Estimate uncertainty parameters
estimate_uncertainty_retro

Estimate uncertainty parameters using retrospective nowcasts
estimate_delay

Estimate a delay distribution from a reporting triangle
.validate_strata_cols

Validate each of the strata columns passed to baselinenowcast
estimate_and_apply_delay

Estimate and apply delay from a reporting triangle
estimate_and_apply_uncertainty

Estimate and apply uncertainty to a point nowcast matrix
estimate_and_apply_delays

Estimate and apply delays to generate retrospective nowcasts
.validate_uncertainty

Validate the uncertainty parameters if they are passed in
.validate_rep_tri_df

Validate the reporting triangle data.frame
fit_by_horizon

Helper function that fits its each column of the matrix (horizon) to an observation model.
get_reference_dates

Get reference dates from reporting_triangle
get_delays_unit

Get delays unit from a reporting triangle
get_delays_from_dates

Compute delays between report dates and reference dates
example_reporting_triangle

Simple example reporting triangle for demonstrations
get_max_delay

Get maximum delay from reporting_triangle
get_mean_delay

Get mean delay for each row of reporting_triangle
get_quantile_delay

Get quantile delay for each row of reporting_triangle
fit_nb

Fit a negative binomial to a vector of observations and expectations
germany_covid19_hosp

Incident COVID-19 hospitalisations indexed by the date of positive test (reference date) and report date from Germany in 2021 and 2022.
get_report_dates

Compute report dates from reference dates and delays
new_baselinenowcast_df

Combine data from a nowcast dataframe, strata, and reference dates
new_reporting_triangle

Class constructor for reporting_triangle objects
reporting_triangle-class

Reporting Triangle Object
is_reporting_triangle

Check if an object is a reporting_triangle
sample_nb

Sample from negative binomial model given a set of predictions
print.reporting_triangle

Print a reporting_triangle object
get_reporting_structure

Get reporting structure from a reporting triangle
head.reporting_triangle

Get first rows of a reporting_triangle
preprocess_negative_values

Preprocess negative values in the reporting triangle
tail.reporting_triangle

Get last rows of a reporting_triangle
sample_prediction

Get a draw of only the predicted elements of the nowcast vector
summary.reporting_triangle

Summarize a reporting_triangle object
sample_predictions

Get a dataframe of multiple draws of only the predicted elements of the nowcast vector
syn_nssp_df

A synthetic dataset containing the number of incident cases indexed by reference date and report date. While data of this form could be from any source, this data is meant to represent the output of pre-processing the syn_nssp_line_list dataset, which is a synthetic patient-level line list data from the United State's National Syndromic Surveillance System (NSSP).
syn_nssp_line_list

A synthetic dataset resembling line-list (each row is a patient) data from the United States' National Syndromic Surveillance System (NSSP) accessed via the Essence platform. All entries are synthetic, formatted to look as close to the real raw data as possible.
sample_nowcast

Generate a single draw of a nowcast combining observed and predicted values
[.reporting_triangle

Subset reporting_triangle objects
sample_nowcasts

Generate multiple draws of a nowcast combining observed and predicted values
[<-.reporting_triangle

Subset assignment for reporting_triangle objects
truncate_to_delay

Truncate reporting triangle to a specific maximum delay
truncate_to_quantile

Truncate reporting_triangle to quantile-based maximum delay
validate_reporting_triangle

Validate a reporting_triangle object
truncate_to_row

Truncate reporting triangle by removing a specified number of the last rows
truncate_to_rows

Truncate reporting triangle by removing bottom rows
apply_reporting_structure

Apply reporting structure to generate a single retrospective reporting triangle
as_reporting_triangle

Create a reporting_triangle object
as_reporting_triangle.data.frame

Create a reporting_triangle object from a data.frame
allocate_reference_times

Allocate training volume based on combination of defaults and user-specified values for training volume for delay and uncertainty estimation.
as_reporting_triangle.matrix

Create a reporting_triangle from a matrix
as.matrix.reporting_triangle

Convert reporting_triangle to plain matrix
as.data.frame.reporting_triangle

Convert reporting_triangle to data.frame
as_ChainLadder_triangle

Convert reporting_triangle to ChainLadder triangle format
apply_delay

Apply the delay to generate a point nowcast
apply_reporting_structures

Apply reporting structures to generate retrospective reporting triangles