Skip to content

Commit a33c07a

Browse files
committed
clearer var name for outcome target
1 parent 0f44b07 commit a33c07a

File tree

4 files changed

+240
-29
lines changed

4 files changed

+240
-29
lines changed

R/analysis-descriptive.R

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ create_raw_table1 <- function(scores, targets) {
7070
}
7171

7272
print_table1 <- function(scores) {
73-
outcome_targets <- unique(scores$outcome_target)
74-
tables <- outcome_targets |>
73+
epi_targets <- unique(scores$epi_target)
74+
tables <- epi_targets |>
7575
map(\(outcome) {
7676
scores <- scores |>
77-
filter(outcome_target == outcome)
77+
filter(epi_target == outcome)
7878
table <- create_raw_table1(scores)
7979

8080
colnames(table)[!(colnames(table) %in% c("Variable", "group"))] <-
@@ -88,8 +88,8 @@ print_table1 <- function(scores) {
8888

8989
## merge all
9090
table1 <- tables[[1]]
91-
if (length(outcome_targets) > 1) {
92-
for (i in seq(2, length(outcome_targets))) {
91+
if (length(epi_targets) > 1) {
92+
for (i in seq(2, length(epi_targets))) {
9393
table1 <- inner_join(table1, tables[[i]], by = c("Variable", "group"))
9494
}
9595
}
@@ -103,14 +103,14 @@ print_table1 <- function(scores) {
103103
starts_with("Mean WIS (SD)_")
104104
)
105105
## reorder
106-
for (outcome in rev(outcome_targets)) {
106+
for (outcome in rev(epi_targets)) {
107107
table1 <- table1 |>
108108
relocate(ends_with(outcome), .after = Variable)
109109
}
110110

111111
## build extra headers
112112
headers_to_add <- c(" " = 1, vapply(
113-
outcome_targets, \(x) sum(grepl(paste0("_", x, "$"), colnames(table1))),
113+
epi_targets, \(x) sum(grepl(paste0("_", x, "$"), colnames(table1))),
114114
1L
115115
))
116116

@@ -139,7 +139,7 @@ print_table1 <- function(scores) {
139139
plot_over_time <- function(scores, ensemble, add_plot, show_uncertainty = TRUE) {
140140
plot_over_time_target <- scores |>
141141
# Get mean & CIs
142-
group_by(target_end_date, outcome_target, CountryTargets) |>
142+
group_by(target_end_date, epi_target, CountryTargets) |>
143143
reframe(
144144
n = n(),
145145
mean = mean(wis, na.rm = TRUE),
@@ -160,7 +160,7 @@ plot_over_time <- function(scores, ensemble, add_plot, show_uncertainty = TRUE)
160160
)
161161
}
162162
plot_over_time_target <- plot_over_time_target +
163-
facet_wrap(~outcome_target, scales = "free_y") +
163+
facet_wrap(~epi_target, scales = "free_y") +
164164
scale_x_date(date_labels = "%b %Y") +
165165
scale_fill_manual(
166166
values = c(
@@ -180,7 +180,7 @@ plot_over_time <- function(scores, ensemble, add_plot, show_uncertainty = TRUE)
180180

181181
plot_over_time_method <- scores |>
182182
# Get mean & CIs
183-
group_by(target_end_date, outcome_target, Method) |>
183+
group_by(target_end_date, epi_target, Method) |>
184184
reframe(
185185
n = n(),
186186
mean = mean(wis, na.rm = TRUE),
@@ -197,7 +197,7 @@ plot_over_time <- function(scores, ensemble, add_plot, show_uncertainty = TRUE)
197197
)
198198
}
199199
plot_over_time_method <- plot_over_time_method +
200-
facet_wrap(~outcome_target, scales = "free_y") +
200+
facet_wrap(~epi_target, scales = "free_y") +
201201
scale_x_date(date_labels = "%b %Y") +
202202
scale_fill_brewer(
203203
aesthetics = c("col", "fill"),
@@ -229,7 +229,7 @@ plot_over_time <- function(scores, ensemble, add_plot, show_uncertainty = TRUE)
229229
# Ridge plot by model --------------------
230230
plot_ridges <- function(scores, target = "Deaths") {
231231
scores |>
232-
filter(outcome_target == target) |>
232+
filter(epi_target == target) |>
233233
group_by(Model) |>
234234
mutate(
235235
median_score = median(wis, na.rm = TRUE),
@@ -258,12 +258,12 @@ plot_ridges <- function(scores, target = "Deaths") {
258258
# Table of targets by model -------------
259259
table_targets <- function(scores) {
260260
table_targets <- scores |>
261-
select(Model, outcome_target, forecast_date, Location) |>
261+
select(Model, epi_target, forecast_date, Location) |>
262262
distinct() |>
263-
group_by(Model, outcome_target, forecast_date) |>
263+
group_by(Model, epi_target, forecast_date) |>
264264
summarise(target_count = n(), .groups = "drop") |>
265265
ungroup() |>
266-
group_by(Model, outcome_target) |>
266+
group_by(Model, epi_target) |>
267267
summarise(
268268
CountryTargets = all(target_count <= 2),
269269
min_targets = min(target_count),
@@ -287,20 +287,20 @@ table_metadata <- function(scores) {
287287
classification <- classify_models() |>
288288
select(Model = model, Method = classification)
289289
model_scores <- scores |>
290-
group_by(Model, outcome_target) |>
290+
group_by(Model, epi_target) |>
291291
table_confint() |>
292-
select(Model, outcome_target, Forecasts)
292+
select(Model, epi_target, Forecasts)
293293
country_targets <- table_targets(scores) |>
294-
select(Model, outcome_target, CountryTargets)
294+
select(Model, epi_target, CountryTargets)
295295
metadata_table <- classification |>
296296
left_join(model_scores) |>
297297
mutate(Description = paste0("[Metadata](https://raw.githubusercontent.com/covid19-forecast-hub-europe/covid19-forecast-hub-europe/main/model-metadata/", Model, ".yml)")) |>
298298
inner_join(country_targets) |>
299299
mutate(
300-
outcome_target = sub("s$", " forecasts", outcome_target)
300+
epi_target = sub("s$", " forecasts", epi_target)
301301
) |>
302302
pivot_wider(
303-
names_from = "outcome_target",
303+
names_from = "epi_target",
304304
values_from = "Forecasts",
305305
values_fill = ""
306306
) |>
@@ -312,7 +312,7 @@ table_metadata <- function(scores) {
312312
# Data --------------------
313313
data_plot <- function(scores, log = FALSE, all = FALSE) {
314314
data <- scores |>
315-
select(Location, outcome_target, target_end_date, Incidence) |>
315+
select(Location, epi_target, target_end_date, Incidence) |>
316316
distinct()
317317
pop <- read_csv(here("data", "populations.csv"), show_col_types = FALSE) |>
318318
rename(Location = location)
@@ -323,7 +323,7 @@ data_plot <- function(scores, log = FALSE, all = FALSE) {
323323
log_inc = log(Incidence + 1)
324324
)
325325
total <- data |>
326-
group_by(outcome_target, target_end_date) |>
326+
group_by(epi_target, target_end_date) |>
327327
summarise(
328328
Incidence = sum(Incidence),
329329
population = sum(population),
@@ -345,7 +345,7 @@ data_plot <- function(scores, log = FALSE, all = FALSE) {
345345

346346
plot <- plot +
347347
geom_line(data = total, linewidth = ifelse(all, 2, 1)) +
348-
facet_wrap(~outcome_target, scales = "free") +
348+
facet_wrap(~epi_target, scales = "free") +
349349
xlab("")
350350

351351
if (log) {

R/process-data.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ process_data <- function(scoring_scale = "log") {
4848
map(\(file) {
4949
read_csv(here("data", file))
5050
}) |>
51-
bind_rows(.id = "outcome_target") |>
51+
bind_rows(.id = "epi_target") |>
5252
filter(scale == scoring_scale)
5353

5454
# Add variables of interest to scores dataframe ----------------------
@@ -76,18 +76,18 @@ process_data <- function(scoring_scale = "log") {
7676
obs <- names(scores_files) |>
7777
set_names() |>
7878
map(~ read_csv(here("data", paste0("observed-", .x, ".csv")))) |>
79-
bind_rows(.id = "outcome_target") |>
79+
bind_rows(.id = "epi_target") |>
8080
mutate(Trend = factor(trend,
8181
levels = c("Stable", "Increasing", "Decreasing"))) |>
8282
rename(Incidence = observed) |>
83-
select(target_end_date, location, outcome_target, Trend, Incidence)
83+
select(target_end_date, location, epi_target, Trend, Incidence)
8484

8585
# Variant phase
8686
variant_phase <- classify_variant_phases()
8787

8888
# Combine all data -----------------------------------------------------
8989
data <- scores_raw |>
90-
left_join(obs, by = c("location", "target_end_date", "outcome_target")) |>
90+
left_join(obs, by = c("location", "target_end_date", "epi_target")) |>
9191
left_join(variant_phase, by = c("location", "target_end_date")) |>
9292
left_join(country_targets, by = "model") |>
9393
left_join(methods, by = "model") |>
@@ -97,7 +97,7 @@ process_data <- function(scoring_scale = "log") {
9797
Horizon = ifelse(!Horizon %in% 1:4, NA_integer_, Horizon),
9898
Model = as.factor(Model),
9999
Location = as.factor(Location),
100-
outcome_target = paste0(str_to_title(outcome_target), "s"),
100+
epi_target = paste0(str_to_title(epi_target), "s"),
101101
wis = wis + 1e-7) |>
102102
filter(!is.na(Horizon)) ## horizon not in 1:4
103103
return(data)

report/results.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ table_effects <- results$effects |>
125125
mutate(value_ci = paste0(round(value, 2),
126126
" (", round(lower_2.5, 2), "-",
127127
upper_97.5_text, ")"),
128-
group = paste(outcome_target, model, group, sep = "_")) |>
128+
group = paste(epi_target, model, group, sep = "_")) |>
129129
column_to_rownames("group")
130130
131131
effects_comp <- results$effects |>

0 commit comments

Comments
 (0)