Learn R Programming

EpiNow2: Estimate real-time case counts and time-varying epidemiological parameters

Summary

{EpiNow2} estimates the time-varying reproduction number, growth rate, and doubling time using a range of open-source tools (Abbott et al.), and current best practices (Gostic et al.). It aims to help users avoid some of the limitations of naive implementations in a framework that is informed by community feedback and is actively supported.

Forecasting is also supported for the time-varying reproduction number, infections, and reported cases using the same generative process approach as used for estimation.

{EpiNow2} estimates the time-varying reproduction number on cases by date of infection (using a similar approach to that implemented in {EpiEstim}). True infections, treated as latent and unobserved, are estimated and then mapped to observed data (for example cases by date of report) via one or more delay distributions (in the examples in the package documentation these are an incubation period and a reporting delay) and a reporting model that can include weekly periodicity.

Uncertainty is propagated from all inputs into the final parameter estimates, helping to mitigate spurious findings. This is handled internally. The time-varying reproduction estimates and the uncertain generation time also give time-varying estimates of the rate of growth.

{EpiNow2} provides three models:

  • estimate_infections(): Reconstruct cases by date of infection from reported cases.

  • estimate_secondary(): Estimate the relationship between primary and secondary observations, for example, deaths (secondary) based on hospital admissions (primary), or bed occupancy (secondary) based on hospital admissions (primary).

  • estimate_truncation(): Estimate a truncation distribution from multiple snapshots of the same data source over time. For more flexibility, check out the {epinowcast} package.

The default model in estimate_infections() uses a non-stationary Gaussian process to estimate the time-varying reproduction number and infer infections. Other options, which generally reduce runtimes at the cost of the granularity of estimates or real-time performance, include:

  • A stationary Gaussian process (faster to estimate but currently gives reduced performance for real time estimates).
  • User specified breakpoints.
  • A fixed reproduction number.
  • A piecewise constant, combining a fixed reproduction number with breakpoints.
  • A random walk, combining a fixed reproduction number with regularly spaced breakpoints (i.e weekly).
  • A deconvolution/back-calculation method for inferring infections, followed with calculating the time-varying reproduction number.
  • Adjustment for the remaining susceptible population beyond the forecast horizon.

By default, all these models are fit with MCMC sampling using the rstan R package as the backend. Users can, however, switch to use approximate algorithms like variational inference, the pathfinder algorithm, or Laplace approximation especially for quick prototyping. The latter two methods are provided through the cmdstanr R package, so users will have to install that separately.

The documentation for estimate_infections provides examples of the implementation of the different options available.

{EpiNow2} is designed to be used via a single function call to two functions:

  • epinow(): Estimate Rt and cases by date of infection and forecast these infections into the future.

  • regional_epinow(): Efficiently run epinow() across multiple regions in an efficient manner.

These two functions call estimate_infections(), which works to reconstruct cases by date of infection from reported cases.

For more details on using each function corresponding function documentation.

Installation

Install the released version of the package:

install.packages("EpiNow2")

Install the development version of the package with:

install.packages("EpiNow2", repos = c("https://epiforecasts.r-universe.dev", getOption("repos")))

Alternatively, install the development version of the package with pak as follows (few users should need to do this):

# check whether {pak} is installed
if (!require("pak")) {
  install.packages("pak")
}
pak::pkg_install("epiforecasts/EpiNow2")

If using pak fails, try:

# check whether {remotes} is installed
if (!require("remotes")) {
  install.packages("remotes")
}
remotes::install_github("epiforecasts/EpiNow2")

To build {EpiNow2} from source, users will need to configure their C toolchain. This is because {EpiNow2} implements the underlying models in Stan (a statistical modelling programming language), which is built on C++.

Each operating system has a different set up procedure. Windows users need to install an appropriate version of RTools. Mac users can follow these steps, and Linux users can use this guide.

Resources

The Getting Started vignette (see vignette("EpiNow2")) is your quickest entry point to the package. It provides a quick run through of the two main functions in the package and how to set up them up. It also discusses how to summarise and visualise the results after running the models.

More broadly, users can also learn the details of estimating delay distributions, nowcasting, and forecasting in a structured way through the free and open short-course, “Nowcasting and forecasting infectious disease dynamics”, developed by some authors of this package.

The package has two websites: one for the stable release version on CRAN, and another for the version in development. These two provide various resources for learning about the package, including the function reference, details about each model (model definition), workflows for each model (usage), and case studies or literature of applications of the package. However, the development website may contain experimental features and information not yet available in the stable release.

The workflow vignette (see vignette("estimate_infections_workflow")) provides guidance on the end-to-end process of estimating reproduction numbers and performing short-term forecasts for a disease spreading in a

In different vignettes we provide the mathematical definition of each model. For example, the model definition vignette for estimate_infections() can be found in vignette("estimate_infections").

A simple example of using the package to estimate a national Rt for Covid-19 can be found here.

Contributing

We welcome all contributions. If you have identified an issue with the package, you can file an issue here. We also welcome additions and extensions to the underlying model either in the form of options or improvements. If you wish to contribute in any form, please follow the package contributing guide.

Contributors

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

Code

seabbs, sbfnk, jamesmbaazam, joeHickson, hsbadr, pitmonticone, actions-user, ellisp, kaitejohnson, jdmunday, pearsonca, Bisaloo, JAllen42, adamkucharski, adrian-lison, avehtari, andrjohns, claude, jcken95, LloydChapman, medewitt, nikosbosse, sophiemeakin, zsusswein

Issue Authors

raulfernandezn, pcarbo, johnaponte, sophie-schiller, munozedg, kathsherratt, yungwai, kgostic, fkrauer, philturk, krageth, tony352, username-rp, HAKGH, AndrewRiceMGW, brynhayder, RichardMN, andrybicio, rhamoonga, furqan915, MFZaini1984, fabsig, affans, GauriSaran, davidvilanova, jrcpulliam, dajmcdon, joshwlambert, avallecam, athowes, lorenzwalthert, nlinton, martinamcm, jonathonmellor, TimTaylor, ciaramccarthy1, SamuelBrand1, damonbayer, valentinedwv, coderabbitai, HenrikBengtsson, bob-carpenter

Issue Contributors

jhellewell14, thlytras, LizaHadley, ntorresd, micahwiesner67, paigemiller, WardBrian

Copy Link

Version

Install

install.packages('EpiNow2')

Monthly Downloads

609

Version

1.8.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Sebastian Funk

Last Published

February 4th, 2026

Functions in EpiNow2 (1.8.0)

$.estimate_infections

Extract elements from estimate_infections objects with deprecated warnings
convolve_and_scale

Convolve and scale a time series
$.estimate_secondary

Extract elements from estimate_secondary objects with deprecated warnings
check_generation_time

Validate probability distribution for using as generation time
create_gp_data

Create Gaussian Process Data
convert_to_logsd

Convert mean and sd to log standard deviation for a log normal distribution
calc_CrI

Calculate Credible Interval
create_shifted_cases

Create Delay Shifted Cases
check_stan_delay

Validate probability distribution for passing to stan
create_future_rt

Construct the Required Future Rt assumption
calc_CrIs

Calculate Credible Intervals
create_sampling_log_message

Create sampling log message
check_truncation_length

Check and warn if truncation distribution is longer than observed time
convert_to_logmean

Convert mean and sd to log mean for a log normal distribution
construct_output

Construct Output
create_initial_conditions

Create Initial Conditions Generating Function
clean_nowcasts

Clean Nowcasts for a Supplied Date
create_infection_summary

Create summary output from infection estimation objects
epinow2_cmdstan_model

Load and compile an EpiNow2 cmdstanr model
epinow

Real-time Rt Estimation, Forecasting and Reporting
create_stan_args

Create a List of Stan Arguments
default_fill_missing_obs

Temporary function to support the transition to full support of missing data.
copy_results_to_latest

Copy Results From Dated Folder to Latest
create_stan_data

Create Stan Data Required for estimate_infections
backcalc_opts

Back Calculation Options
bootstrapped_dist_fit

Fit a Subsampled Bootstrap to Integer Values and Summarise Distribution Parameters
clean_regions

Clean Regions
epinow2_rstan_model

Load an EpiNow2 rstan model.
example_generation_time

Example generation time
example_confirmed

Example Confirmed Case Data Set
epinow2_stan_model

Return a stan model object for the appropriate backend
dist_fit

Fit an Integer Adjusted Exponential, Gamma or Lognormal distributions
check_reports_valid

Validate data input
create_backcalc_data

Create Back Calculation Data
create_delay_inits

Create initial conditions for delays
create_obs_model

Create Observation Model Settings
create_rt_data

Create Time-varying Reproduction Number Data
check_sparse_pmf_tail

Check that PMF tail is not sparse
fit_model_approximate

Fit a Stan Model using an approximate method
create_stan_params

Create parameters for stan
create_stan_delays

Create delay variables for stan
extract_latent_state

Extract samples for a latent state from a Stan model
convert_to_natural

Internal function for converting parameters to natural parameters.
example_reporting_delay

Example reporting delay
example_incubation_period

Example incubation period
extract_parameter_samples

Extract parameter samples from a Stan model
delay_opts

Delay Distribution Options
estimate_truncation

Estimate Truncation of Observed Data
discrete_pmf

Discretised probability mass function
estimates_by_report_date

Estimate Cases by Report Date
fill_missing

Fill missing data in a data set to prepare it for use within the package
dist_spec_distributions

Get parametric distribution types
fit_model_with_nuts

Fit a Stan Model using the NUTs sampler
get_distribution

Get the distribution of a <dist_spec>
filter_leading_zeros

Filter leading zeros from a data set.
get_element

Extracts an element of a <dist_spec>
match_output_arguments

Match User Supplied Arguments with Supported Options
estimate_secondary

Estimate a Secondary Observation from a Primary Observation
extract_CrIs

Extract Credible Intervals Present
estimate_infections

Estimate Infections, the Time-Varying Reproduction Number and the Rate of Growth
forecast_infections

Forecast infections from a given fit and trajectory of the time-varying reproduction number
growth_to_R

Convert Growth Rates to Reproduction numbers.
expose_stan_fns

Expose internal package stan functions in R
example_truncated

Example Case Data Set with Truncation
map_prob_change

Categorise the Probability of Change for Rt
fix_parameters

Fix the parameters of a <dist_spec>
is_constrained

Check if a <dist_spec> is constrained, i.e. has a finite maximum or nonzero CDF cutoff.
get_predictions

Get predictions from a fitted model
extract_params

Extract parameter names
extract_delay_params

Extract delay distributions from a fitted model
extract_parameters

Extract samples from all parameters
get_raw_result

Get a Single Raw Result
max.dist_spec

Returns the maximum of one or more delay distribution
get_regions_with_most_reports

Get Regions with Most Reported Cases
format_quantile_predictions

Format quantile predictions
extract_scalar_params

Extract scalar parameters from a fitted model
extract_samples

Extract all samples from a stan fit
mean.dist_spec

Returns the mean of one or more delay distribution
format_fit

Format Posterior Samples
discretise

Discretise a <dist_spec>
plot_summary

Plot a Summary of the Latest Results
plot_estimates

Plot Estimates
process_regions

Process all Region Estimates
plot.forecast_secondary

Plot method for forecast_secondary objects
plot_CrIs

Plot EpiNow2 Credible Intervals
report_summary

Provide Summary Statistics for Estimated Infections and Rt
new_dist_spec

Internal function for generating a dist_spec given parameters and a distribution.
==.dist_spec

Compares two delay distributions
rt_opts

Time-Varying Reproduction Number Options
reconstruct_parametric

Reconstruct a parametric delay distribution
reconstruct_nonparametric

Reconstruct a nonparametric delay distribution
ndist

Calculate the number of distributions in a <dist_spec>
filter_opts

Filter Options for a Target Region
estimate_delay

Estimate a Delay Distribution
format_sample_predictions

Format sample predictions
make_conf

Format Credible Intervals
secondary_opts

Secondary Reports Options
get_samples

Get posterior samples from a fitted model
merge_trunc_pred_obs

Merge truncation predictions with observations for display
natural_params

Get the names of the natural parameters of a distribution
make_param

Internal function to create a parameter list
reconstruct_delay

Reconstruct a dist_spec from stored stan data and posterior
format_samples_with_dates

Format raw Stan samples with dates and metadata
extract_delays

Extract samples from all delay parameters
get_regional_results

Get Combined Regional Results
extract_inits

Generate initial conditions from a Stan fit
setup_default_logging

Setup Default Logging
forecast_opts

Forecast options
forecast_secondary

Forecast Secondary Observations Given a Fit from estimate_secondary
extract_stan_param

Extract a parameter summary from a Stan object
set_dt_single_thread

Set to Single Threading
extract_single_dist

Extract a single element of a composite <dist_spec>
get_regions

Get Folders with Results
plot.forecast_infections

Plot method for forecast_infections
get_pmf

Get the probability mass function of a nonparametric distribution
plot.estimate_truncation

Plot method for estimate_truncation
get_parameters

Get parameters from distributions or fitted models
select_plots

Internal helper function to select plots from those created by report_plots()
lower_bounds

Get the lower bounds of the parameters of a distribution
lapply_func

Choose a parallel or sequential apply function
print.epinowfit

Print information about an object that has resulted from a model fit.
pad_reported_cases

Pads reported cases with daily initial zeros
process_region

Process regional estimate
regional_summary

Regional Summary Output
get_seeding_time

Estimate seeding time from delays and generation time
gt_opts

Generation Time Distribution Options
gp_opts

Approximate Gaussian Process Settings
format_simulation_output

Format Simulation Output from Stan
fit_model

Fit a model using the chosen backend.
report_plots

Report plots
summary.forecast_infections

Summary output from forecast_infections
summary.estimate_truncation

Summarise results from estimate_truncation
setup_future

Set up Future Backend
setup_logging

Setup Logging
setup_target_folder

Setup Target Folder for Saving
save_input

Save Observed Data
sd

Returns the standard deviation of one or more delay distribution
setup_dt

Convert to Data Table
summary.estimate_infections

Summary output from estimate_infections
[[.estimate_secondary

Extract elements from estimate_secondary objects with bracket notation
summarise_key_measures

Summarise rt and cases
stan_opts

Stan Options
opts_list

Forecast optiong
obs_opts

Observation Model Options
plot.estimate_secondary

Plot method for estimate_secondary
prepare_truncation_obs

Prepare truncation observations for Stan
plot.estimate_infections

Plot method for estimate_infections
print.dist_spec

Prints the parameters of one or more delay distributions
stan_pathfinder_opts

Stan pathfinder algorithm Options
summary.estimate_secondary

Summarise results from estimate_secondary
stan_laplace_opts

Stan Laplace algorithm Options
[[.estimate_infections

Extract elements from estimate_infections objects with bracket notation
summary.epinow

Summary output from epinow
update_secondary_args

Update estimate_secondary default priors
stable_convolve

Numerically stable convolution function for two pmf vectors
summarise_results

Summarise Real-time Results
[[.epinow

Extract elements from epinow objects with bracket notation
+.dist_spec

Creates a delay distribution as the sum of two other delay distributions.
plot.dist_spec

Plot PMF and CDF for a dist_spec object
regional_epinow

Real-time Rt Estimation, Forecasting and Reporting by Region
posterior_to_normal

Create a Normal distribution from posterior samples
regional_runtimes

Summarise Regional Runtimes
run_region

Run epinow with Regional Processing Code
stan_sampling_opts

Stan Sampling Options
simulate_secondary

Simulate secondary observations from primary observations
save_estimate_infections

Save Estimated Infections
simulate_infections

Simulate infections using the renewal equation
stan_vb_opts

Stan Variational Bayes Options
trunc_opts

Truncation Distribution Options
update_horizon

Updates Forecast Horizon Based on Input Data and Target
add_breakpoints

Add breakpoints to certain dates in a data set.
apply_default_cdf_cutoff

Apply default CDF cutoff to a <dist_spec> if it is unconstrained
EpiNow2-package

EpiNow2: Estimate and Forecast Real-Time Infection Dynamics
Distributions

Probability distributions
R_to_growth

Convert Reproduction Numbers to Growth Rates
apply_zero_threshold

Convert zero case counts to NA (missing) if the 7-day average is above a threshold.
bound_dist

Define bounds of a <dist_spec>
c.dist_spec

Combines multiple delay distributions for further processing
collapse

Collapse nonparametric distributions in a <dist_spec>
allocate_delays

Allocate Delays into Required Stan Format
allocate_empty

Allocate Empty Parameters to a List
add_day_of_week

Adds a day of the week vector
$.epinow

Extract elements from epinow objects with deprecated warnings
combine_tv_and_static_params

Combine time-varying and static parameters
add_horizon

Add missing values for future dates
calc_summary_measures

Calculate All Summary Measures
calc_summary_stats

Calculate Summary Statistics