| backtest | R Documentation |
Evaluates forecast accuracy by repeatedly fitting models on historical data and comparing predictions to held-out observations. This implements the evaluation framework described in Abousamra et al. (2024).
backtest(
data,
engines = "mlr",
origins = "weekly",
horizons = c(7L, 14L, 21L, 28L),
min_train = 42L,
...
)
data |
An lfq_data object. |
engines |
Character vector of engine names to compare.
Default |
origins |
How to select forecast origins:
|
horizons |
Integer vector of forecast horizons in days.
Default |
min_train |
Minimum training window in days. Origins earlier
than |
... |
Additional arguments passed to |
Implements the rolling-origin evaluation framework described in Abousamra et al. (2024), Section 2.4. At each origin date, the model is fit on data up to that date and forecasts are compared to held-out future observations. This avoids look-ahead bias and provides an honest assessment of real-time forecast accuracy.
An lfq_backtest object (tibble subclass) with columns:
Date used as the training cutoff.
Date being predicted.
Forecast horizon in days.
Engine name.
Lineage name.
Predicted frequency (median).
Lower prediction bound.
Upper prediction bound.
Observed frequency at target_date.
Abousamra E, Figgins M, Bedford T (2024). Fitness models provide accurate short-term forecasts of SARS-CoV-2 variant frequency. PLoS Computational Biology, 20(9):e1012443. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1371/journal.pcbi.1012443")}
score_forecasts() to compute accuracy metrics,
compare_models() to rank engines.
sim <- simulate_dynamics(n_lineages = 3,
advantages = c("A" = 1.2, "B" = 0.8),
n_timepoints = 20, seed = 1)
bt <- backtest(sim, engines = "mlr",
horizons = c(7, 14), min_train = 42)
bt
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.