Learn R Programming

rtestim

This package uses Poisson likelihood with a trend filtering penalty (a type of regularized nonparametric regression) to estimate the effective reproductive number, Rt. This value roughly says “how many new infections will result from each new infection today”. Values larger than 1 indicate that an epidemic is growing while those less than 1 indicate decline.

Installation

You can install the development version of rtestim from GitHub with:

# install.packages("remotes")
remotes::install_github("dajmcdon/rtestim")

Or the released version on CRAN

install.packages("rtestim")

Quick example

Here we create some data that “looks” like a typical wave in an epidemic. Because the model uses regularized regression, we estimate the model at a range of tuning parameters simultaneously.

set.seed(12345)
library(rtestim)
library(ggplot2)
dat <- data.frame(
  Time = 1:101,
  incident_cases = c(1, rpois(100, dnorm(1:100, 50, 15) * 500 + 1))
)
ggplot(dat, aes(Time, incident_cases)) +
  geom_point(colour = "cornflowerblue") +
  theme_bw()

We fit the model and visualize the resulting estimated sequences of $R_t$:

mod <- estimate_rt(observed_counts = dat$incident_cases, nsol = 20)
plot(mod)

The additional parameter nsol = 20 specifies the number of tuning parameters for which $R_t$ is estimated. A built in function for cross-validation can be used to select the tuning parameter.

mod_cv <- cv_estimate_rt(dat$incident_cases, nsol = 20)
plot(mod_cv, which_lambda = "lambda.1se")

Copy Link

Version

Install

install.packages('rtestim')

Monthly Downloads

164

Version

1.0.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Daniel McDonald

Last Published

October 24th, 2025

Functions in rtestim (1.0.1)

interpolate_rt

Interpolate (or extrapolate) Rt estimates to intermediate design points
delay_calculator

Calculate the total infectiousness at each observed time point.
cv_estimate_rt

Leave-kth-out cross validation for choosing a optimal parameter lambda
confband

Add confidence bands to estimated Rt or incidence curves
cancovid

Canadian Incident COVID-19 Cases
configure_rt_admm

Rt estimation algorithm configuration
estimate_rt

Estimate Rt using smoothness-penalized Poisson likelihood
fitted.cv_poisson_rt

Fitted cv_poisson_rt
discretize_gamma

Compute the discretized density function for gamma distribution
plot.cv_poisson_rt

Plot cv_poisson_rt
predict.cv_poisson_rt

Predict observed data using estimated Rt
predict.poisson_rt

Predict observed data using estimated Rt
plot.rt_confidence_band

Plot estimated confidence bands for an estimate of Rt
plot.poisson_rt

Plot estimated Rt values from a poisson_rt object