# 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

For a genuine prospective evaluation, accumulate `fit$forecast` and the following week’s actual case count over several weeks and pass the resulting quantile lists to `wis()`; see `?wis` and `?score_batches`.