Skip to content

Commit

Permalink
Merge pull request #659 from cmu-delphi/ndefries/no-cumulative-sum
Browse files Browse the repository at this point in the history
Don't sum cumulative truth values
  • Loading branch information
dshemetov committed Aug 25, 2023
2 parents 8d045b7 + 71530b7 commit 83a436c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R-packages/evalcast/DESCRIPTION
@@ -1,7 +1,7 @@
Package: evalcast
Type: Package
Title: Tools For Evaluating COVID Forecasters
Version: 0.3.4
Version: 0.3.5
Authors@R:
c(
person(given = "Daniel",
Expand Down
7 changes: 7 additions & 0 deletions R-packages/evalcast/NEWS.md
@@ -1,3 +1,10 @@
# evalcast 0.3.5

- Fix truth value generation for cumulative signals. `get_target_response` now
returns the most recent value within a given time period for either a `day`
or `epiweek` incidence period. For incidence signals, `get_target_response`
still sums all values within the time period.

# evalcast 0.3.4

- Change `get_forecaster_predictions_alt` to read forecaster input files using
Expand Down
16 changes: 13 additions & 3 deletions R-packages/evalcast/R/get_target_response.R
Expand Up @@ -85,20 +85,30 @@ get_target_response <- function(signals,
"forecast dates: ",
paste(forecast_dates[problem_dates], collapse = ", "),
"."))
if (sum(problem_dates) == length(forecast_dates)) return(empty_actual())
if (length(problem_dates) == length(forecast_dates)) return(empty_actual())
out <- out[!problem_dates]
forecast_dates <- forecast_dates[!problem_dates]
target_periods <- target_periods[!problem_dates, ]
}
names(out) <- forecast_dates
target_periods$forecast_date = lubridate::ymd(forecast_dates)

if (grepl("cumulative", response$signal, fixed=TRUE)) {
agg_fn <- function(df) {
slice(df, which.max(time_value)) %>% select(geo_value, forecast_date, actual = value)
}
} else {
agg_fn <- function(df) {
summarize(df, actual = sum(.data$value))
}
}
out <- out %>%
bind_rows(.id = "forecast_date") %>%
mutate(forecast_date = lubridate::ymd(.data$forecast_date)) %>%
group_by(.data$geo_value, .data$forecast_date) %>%
summarize(actual = sum(.data$value)) %>%
# mutate(forecast_date = forecast_dates[as.numeric(.data$forecast_date)]) %>%
agg_fn() %>%
left_join(target_periods, by = "forecast_date")

# record date that this function was run for reproducibility
attr(out, "as_of") <- Sys.Date()
out
Expand Down

0 comments on commit 83a436c

Please sign in to comment.