RtForecastR walkthrough

library(RtForecastR)

Fit R_t and get a forecast

rt_forecast() estimates the filtered (real-time) and smoothed (retrospective) effective reproduction number from a case-count time series, and produces a genuine one-step-ahead out-of-sample forecast.

data(measles_cdmx)
fit <- rt_forecast(measles_cdmx$time, measles_cdmx$cases,
                    mean_GI = 11/7, var_GI = (4/7)^2)
fit
#> <rtforecast> 31 time points
#> Latest R_t (filtered): 0.722 (0.462-1.064) 
#> One-step-ahead forecast for time 48 :
#>   4.5 cases (95% CI: 1-10, 50% CI: 3-6)
plot(fit, which = "Rt")

plot(fit, which = "forecast")

Checking calibration

fit$predictions holds in-sample one-step-ahead predictions - a quick adequacy check:

mae(fit$predictions$cases, fit$predictions$pred_next)
#> [1] 9.38
coverage(fit$predictions$cases, fit$predictions$pred_lo95, fit$predictions$pred_hi95)
#> [1] 0.7666667

This is not genuine forecast validation, since the model has already seen nearby data. For that, run a rolling backtest: refit on data up to each week, forecast the next week, and score those forecasts against what was later observed with mae(), coverage() and wis() (using fit$forecast_quantiles). A complete worked backtest, with interpretation and cautions, is in the companion tutorial: https://github.com/rajsubediresearch/RtForecastR-tutorial.