Skip to content

Commit 83a436c

Browse files
authored
Merge pull request #659 from cmu-delphi/ndefries/no-cumulative-sum
Don't sum cumulative truth values
2 parents 8d045b7 + 71530b7 commit 83a436c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

R-packages/evalcast/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: evalcast
22
Type: Package
33
Title: Tools For Evaluating COVID Forecasters
4-
Version: 0.3.4
4+
Version: 0.3.5
55
Authors@R:
66
c(
77
person(given = "Daniel",

R-packages/evalcast/NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# evalcast 0.3.5
2+
3+
- Fix truth value generation for cumulative signals. `get_target_response` now
4+
returns the most recent value within a given time period for either a `day`
5+
or `epiweek` incidence period. For incidence signals, `get_target_response`
6+
still sums all values within the time period.
7+
18
# evalcast 0.3.4
29

310
- Change `get_forecaster_predictions_alt` to read forecaster input files using

R-packages/evalcast/R/get_target_response.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,30 @@ get_target_response <- function(signals,
8585
"forecast dates: ",
8686
paste(forecast_dates[problem_dates], collapse = ", "),
8787
"."))
88-
if (sum(problem_dates) == length(forecast_dates)) return(empty_actual())
88+
if (length(problem_dates) == length(forecast_dates)) return(empty_actual())
8989
out <- out[!problem_dates]
9090
forecast_dates <- forecast_dates[!problem_dates]
9191
target_periods <- target_periods[!problem_dates, ]
9292
}
9393
names(out) <- forecast_dates
9494
target_periods$forecast_date = lubridate::ymd(forecast_dates)
95+
96+
if (grepl("cumulative", response$signal, fixed=TRUE)) {
97+
agg_fn <- function(df) {
98+
slice(df, which.max(time_value)) %>% select(geo_value, forecast_date, actual = value)
99+
}
100+
} else {
101+
agg_fn <- function(df) {
102+
summarize(df, actual = sum(.data$value))
103+
}
104+
}
95105
out <- out %>%
96106
bind_rows(.id = "forecast_date") %>%
97107
mutate(forecast_date = lubridate::ymd(.data$forecast_date)) %>%
98108
group_by(.data$geo_value, .data$forecast_date) %>%
99-
summarize(actual = sum(.data$value)) %>%
100-
# mutate(forecast_date = forecast_dates[as.numeric(.data$forecast_date)]) %>%
109+
agg_fn() %>%
101110
left_join(target_periods, by = "forecast_date")
111+
102112
# record date that this function was run for reproducibility
103113
attr(out, "as_of") <- Sys.Date()
104114
out

0 commit comments

Comments
 (0)