Skip to content

Instantly share code, notes, and snippets.

@kathsherratt
kathsherratt / score-from-scratch.R
Last active October 17, 2021 22:50
Score forecasts from covid19-forecast-hub-europe
# Run full evaluation sequence for all forecast models saved in data-processed/
# Sources for this code taken from:
# https://github.com/epiforecasts/covid19-forecast-hub-europe/blob/main/code/reports/compile-evaluation-reports.r
# https://github.com/epiforecasts/covid19-forecast-hub-europe/blob/main/code/reports/evaluation/evaluation-report.Rmd
# https://github.com/epiforecasts/EuroForecastHub/blob/main/R/score_models.R
# https://github.com/epiforecasts/covid19-forecast-hub-europe/tree/main/code/reports/rmdchunks
# Set up ------------------------------------------------------------------
# R session working directory should be set to a local clone of covid19-forecast-hub-europe/
@kathsherratt
kathsherratt / plot-euro-truth-data.R
Created September 30, 2021 11:21
Plot hospitalisation data from Euro forecast hub
library(dplyr)
library(covidHubUtils)
library(ggplot2)
# Set up
min_date <- Sys.Date() - 6 * 7 # set an earliest date to display (eg six weeks)
location_names <- hub_locations_ecdc$location_name # set which countries to display (eg all countries with data)
# Get data
ecdc_daily <- load_truth(truth_source = "ECDC",
@kathsherratt
kathsherratt / test-hub-validations.R
Created November 22, 2021 16:19
test-hub-validations
# test forecast file
library(dplyr)
library(tibble)
library(readr)
library(purrr)
library(here)
# `tests` contains 9 tibbles each to test one element of validation
# Each tibble is a forecast with one valid row (location A) and one invalid row (location B)
@kathsherratt
kathsherratt / plot-euro-ensemble-regional.R
Created December 1, 2021 11:08
Plot Euro hub ensemble forecasts by European region
# Plot Euro hub ensemble forecasts by European region
library(here)
library(covidHubUtils)
library(countrycode)
library(dplyr)
library(lubridate)
library(ggplot2)
library(tidyr)
library(purrr)
@kathsherratt
kathsherratt / hub-team-tally.R
Last active March 20, 2023 11:15
Count teams contributing to European hubs over time
# Count teams contributing to European Forecast hub over time
library(gh)
library(purrr)
library(dplyr)
library(lubridate)
library(ggplot2)
library(ggrepel)
# Get model names / dates from github ---------------------------
model_names <- gh(paste0("/repos/covid19-forecast-hub-europe/covid19-",
# Create a template scenario projection
library(dplyr)
library(tidyr)
library(readr)
# Variables
origin_date <- as.Date("2022-05-22")
scenario_id <- paste0(c("A", "B", "C", "D"), "-", origin_date)
age_group <- c("0-15", "16-64", "65-130", "0-130")
target_variables <- c("inc case", "inc hosp", "inc death", "inc inf")
# Source: code by Hugo Gruson (Github @Bisaloo)
# https://github.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/blob/main/.github/workflows/create-parquet.yml
library(readr)
library(arrow)
library(dplyr)
library(lubridate)
locations <- read_csv(
here::here("data-locations", "locations_eu.csv")) |>
dplyr::select(location, location_name, population)
@kathsherratt
kathsherratt / download_variant_introduction.R
Last active July 1, 2023 16:22
Get variants of concern dataset from ECDC
# Gets variants of concern dataset from ECDC
# For each variant/country finds the first period
# with variant % greater than 5% and up to 50%
# before the first peak for that variant
# Note ECDC data are in weeks, dates are indexed to Saturdays to match target end dates
#
# Example
# variant_names <- c("B.1.617.2" = "Delta", "B.1.1.529" = "Omicron")
# forecast_variants <- download_variant_introduction(introduction_percent = 5,
# country_names = "Germany",
@kathsherratt
kathsherratt / improving_modelling_responses.Rmd
Last active September 13, 2024 12:09
Improving modelling survey: responses
---
title: "Appendix: Responses to improving conditions for outbreak modelling"
date: "2024"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(knitr)
library(googlesheets4)