Skip to content

Commit

Permalink
update figures
Browse files Browse the repository at this point in the history
  • Loading branch information
kathsherratt committed Jan 9, 2024
1 parent 9282b5a commit 5aea645
Show file tree
Hide file tree
Showing 19 changed files with 545 additions and 527 deletions.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ po/*~
rsconnect/
.DS_Store
.DS_Store
.DS_Store
32 changes: 19 additions & 13 deletions code/create-ensembles.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ create_weekly_ensembles <- function(results) {
# Dates for ensemble creation
latest_data <- max(subset(results, !is.na(obs))$target_end_date)
ensemble_dates <- unique(results$target_end_date)
forecast_dates <- ensemble_dates[5:length(ensemble_dates)] # start at 4 weeks in
forecast_dates <- forecast_dates[forecast_dates <= latest_data + 7] # only forecast up to where we can evaluate with observed data
# -----EDIT----
# forecast_dates <- ensemble_dates[5:length(ensemble_dates)] # start at 4 weeks in
#
forecast_dates <- ensemble_dates
#
# forecast_dates <- forecast_dates[forecast_dates <= latest_data + 7] # only forecast up to where we can evaluate with observed data
#---- end edit----

# Divide results with weekly expanding history of observations
results_window <- map(forecast_dates,
Expand All @@ -118,7 +123,9 @@ create_weekly_ensembles <- function(results) {
0.975, 0.99)
ensembles <- map_dfr(results_scored,
~ .x |>
group_by(location, target_variable, target_end_date) |>
group_by(location, target_variable,
target_end_date,
n_weeks_scored) |>
reframe(
value = cNORM::weighted.quantile.harrell.davis(
x = value_100k,
Expand All @@ -131,10 +138,12 @@ create_weekly_ensembles <- function(results) {
.id = "forecast_date") |>
ungroup()

# Add an unweighted ensemble to use as a baseline for evaluation
# Add an unweighted ensemble (one for each equivalent to all the weighted ensembles) to use as a baseline for evaluation
ensembles_unweighted <- map_dfr(results_scored,
~ .x |>
group_by(location, target_variable, target_end_date) |>
group_by(location, target_variable,
target_end_date,
n_weeks_scored) |>
reframe(
value = quantile(value_100k, quantiles),
quantile = paste0("q", quantiles),
Expand All @@ -144,15 +153,12 @@ create_weekly_ensembles <- function(results) {
.id = "forecast_date") |>
ungroup()

ensembles <- bind_rows(ensembles, ensembles_unweighted)
ensembles <- bind_rows(ensembles, ensembles_unweighted) |>
mutate(n_weeks_scored = ifelse(is.na(n_weeks_scored), 0, n_weeks_scored),
horizon = as.numeric(target_end_date - as.Date(forecast_date)) / 7)

# only keep forecasts for specified horizons
ensembles <- ensembles |>
mutate(horizon = as.numeric(target_end_date - as.Date(forecast_date)) / 7)
# ie conditioned on data up to n weeks ago

weekly_ensembles <- list(ensembles = ensembles,
weekly <- list(ensembles = ensembles,
weights = weights)

return(weekly_ensembles)
return(weekly)
}
2 changes: 1 addition & 1 deletion code/score-samples.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ score_samples <- function(results,
target_end_date <= last_data_point) |>
# absolute error
mutate(ae = abs(value_100k - obs_100k)) |>
# obs_100k_1 = ifelse(obs_100k==0, 1e-06, obs_100k))
# mean absolute error
group_by(location, target_variable,
model, sample, scenario_id) |>
summarise(mae = mean(ae),
inv_mae = 1/mae,
n_weeks_scored = n(),
.groups = "drop")

# ----- Create MAE weights for each value
Expand Down
442 changes: 0 additions & 442 deletions output/Main-text---Results.html

This file was deleted.

Binary file modified output/Supplement.pdf
Binary file not shown.
Binary file modified output/figures/SI-figure-1.pdf
Binary file not shown.
Binary file modified output/figures/SI-figure-2.pdf
Binary file not shown.
Binary file removed output/figures/figure-1.jpg
Binary file not shown.
Binary file added output/figures/figure-1.pdf
Binary file not shown.
Binary file removed output/figures/figure-2.jpg
Binary file not shown.
Binary file added output/figures/figure-2.pdf
Binary file not shown.
Binary file removed output/figures/figure-3.jpg
Binary file not shown.
Binary file added output/figures/figure-3.pdf
Binary file not shown.
Loading

0 comments on commit 5aea645

Please sign in to comment.