#knitr::opts_knit$set(root.dir = 'epipredictr/') #knitr::opts_knit$set(fig.path = 'inst/report/figure/')
library(epipredictr) library(rstan) options(mc.cores = 4) rstan_options(auto_write = TRUE) library(scoringutils) library(dplyr) library(cowplot) # source("./R/utilities.R") # source("./R/models.R")
Forecast the time-varying R_t estimates into the future to get a sense of the trajectory of the COVID-19 epidemic in different countries.
We used three different models
1. windowed regression 2. BSTS with a global trend 3. BSTS with a local trend
to forecast transmission rates. Predictions were made using R and Stan and results were scored using CRPS and LogS using the scoringRules package.
[ ] graph with predictions by every country for best model [ ] table with - CI for forecasts - Past forecast score?
d <- readRDS("./data/time_varying_params.rds")[[1]] y_true <- d$mean
## Windowed Regression # model_lin_reg <- stan_model(file = "./inst/stan/linear_regression.stan") # res_lin <- fit_iteratively(incidences = y_true, model = model_lin_reg, # n_pred = 7, # max_n_past_obs = 7, vb = FALSE) res_lin <- fit_iteratively(incidences = y_true, model = "lin_reg", n_pred = 7, max_n_past_obs = 7, vb = FALSE) ## BSTS global trend # model_bsts <- stan_model(file = "./inst/stan/bsts.stan") # res_bsts <- fit_iteratively(incidences = y_true, # model = model_bsts, n_pred = 7, # max_n_past_obs = Inf, vb = FALSE) res_bsts <- fit_iteratively(incidences = y_true, model = "bsts", n_pred = 7, max_n_past_obs = Inf, vb = FALSE) ## BSTS local trend # model_bsts_local <- stan_model(file = "./inst/stan/bsts_local_trend.stan") # res_bsts_local <- fit_iteratively(incidences = y_true, # model = model_bsts_local, # n_pred = 7, # max_n_past_obs = Inf, vb = FALSE) res_bsts_local <- fit_iteratively(incidences = y_true, model = "bsts_local_trend", n_pred = 7, max_n_past_obs = Inf, vb = FALSE, length_local_trend = 7)
prior_post <- plot_prior_vs_posterior(res_bsts$stanfitobjects) prior_post$plot
prior_post <- plot_prior_vs_posterior(res_bsts_local$stanfitobjects) prior_post$plot
p_reg <- plot_pred_vs_true(y_pred_samples = res_lin$predictive_samples, y_true = res_lin$y, forecast_run = res_lin$forecast_run) p_bsts <- plot_pred_vs_true(y_pred_samples = res_bsts$predictive_samples, y_true = res_bsts$y, forecast_run = res_bsts$forecast_run) p_bsts_local <- plot_pred_vs_true(y_pred_samples = res_bsts_local$predictive_samples, y_true = res_bsts_local$y, forecast_run = res_bsts_local$forecast_run) plot_grid(p_reg, p_bsts, p_bsts_local, labels = "AUTO", ncol = 1)
scoringutils::eval_forecasts(true_values = y_true[15:76], predictions = res_lin$predictive_samples[15:76, ], outcome_type = "continuous") scoringutils::eval_forecasts(true_values = y_true[15:76], predictions = res_bsts$predictive_samples[15:76, ], outcome_type = "continuous") scoringutils::eval_forecasts(true_values = y_true[15:76], predictions = res_bsts_local$predictive_samples[15:76, ], outcome_type = "continuous")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.