| rt_forecast | R Documentation |
Fits filtered (real-time/causal) and smoothed (retrospective) R_t
estimates to a case-count time series using the EpiFilter algorithm
(Parag 2021), computes one-step-ahead in-sample predictions (a model
adequacy check), a genuine out-of-sample one-step forecast with
predictive intervals, and the elimination probability P(R_t < 1) at
every time point. Disease-agnostic: supply the generation interval
for your own pathogen via mean_GI/var_GI.
rt_forecast(
time,
cases,
mean_GI,
var_GI,
Rmin = 0.01,
Rmax = 10,
grid_size = 200,
eta = 0.1,
ci_level = 0.025,
quantile_levels = c(0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45),
maxI = NULL
)
time |
numeric vector of time indices (e.g. epi weeks) |
cases |
numeric vector of case counts, same length as |
mean_GI |
mean generation interval, in the same time units as
|
var_GI |
variance of the generation interval, same time units |
Rmin, Rmax |
bounds of the grid searched over for R_t (default 0.01, 10) |
grid_size |
number of points in the R_t grid (default 200) |
eta |
diffusion (state) noise controlling smoothness of R_t (default 0.1) |
ci_level |
tail probability defining the reported main credible interval (default 0.025, i.e. a 95% interval) |
quantile_levels |
additional quantile levels (each in (0, 0.5))
to compute for the out-of-sample forecast, used by |
maxI |
upper bound of the internal prediction grid; if |
Unlike a script, this returns an object rather than writing files -
use plot.rtforecast() if you want the plots run_rtforecast.R
used to write directly.
an object of class "rtforecast": a list with elements
results (per-time filtered and smoothed R_t estimates with 95%
credible intervals, and elimination probability P(R_t < 1)),
predictions (in-sample one-step-ahead predictions with 50%/95%
intervals), forecast (a one-row data frame: the out-of-sample
forecast one step beyond the data, with 50%/95% intervals and the
R_t used), forecast_quantiles (a named list of c(lo, hi) pairs
for that same forecast at each requested level, for use with
wis(); NULL if quantile_levels = NULL), call_args (the
settings used, including the resolved maxI), and raw (the
underlying filter/smoother objects, for advanced use).
data(measles_cdmx)
fit <- rt_forecast(measles_cdmx$time, measles_cdmx$cases,
mean_GI = 11/7, var_GI = (4/7)^2)
head(fit$results)
fit$forecast
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.