Skip to content

flatline_forecaster error when using target_date #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dshemetov opened this issue Feb 2, 2024 · 0 comments · Fixed by #300
Closed

flatline_forecaster error when using target_date #290

dshemetov opened this issue Feb 2, 2024 · 0 comments · Fixed by #300

Comments

@dshemetov
Copy link
Contributor

dshemetov commented Feb 2, 2024

TL;DR: target_date results in NA forecasts? If you comment out target_date and uncomment ahead lines below, the forecasts are reasonable.

r$> library(epidatr) # Access Delphi API
    library(epipredict)
    library(dplyr)
 
    format_storage <- function(pred, true_forecast_date, target_end_date) {
      pred %>%
        mutate(
          forecast_date = true_forecast_date,
          .dstn = nested_quantiles(.pred_distn)
        ) %>%
        unnest(.dstn) %>%
        select(-any_of(c(".pred_distn", ".pred", "time_value"))) %>%
        rename(quantile = quantile_levels, value = values, target_end_date = 
    target_date) %>%
        relocate(geo_value, forecast_date, target_end_date, quantile, value)
    }
 
 
    epidata <- pub_covidcast(
      source = "jhu-csse",
      signals = "deaths_incidence_num",
      time_type = "day",
      geo_type = "state",
      geo_values = c("ca", "tx", "fl"),
      time_values = epirange(20210101, 20211231)
    ) %>%
      select(geo_value, time_value, deaths = value) %>%
      as_epi_df()
 
    fit <- flatline_forecaster(
      epidata,
      outcome = "deaths",
      args_list = flatline_args_list(
        # ahead = 1L,
        n_training = 7L,
        forecast_date = as.Date("2021-12-31"),
        target_date = as.Date("2022-01-01"),
        quantile_levels = c(0.2, 0.5, 0.8),
      )
    )
    format_storage(fit$predictions, as.Date("2021-12-31"), as.Date("2022-01-0
    1"))
# A tibble: 9 × 5
  geo_value forecast_date target_end_date quantile value
  <chr>     <date>        <date>             <dbl> <dbl>
1 ca        2021-12-31    2022-01-08           0.2    NA
2 ca        2021-12-31    2022-01-08           0.5    NA
3 ca        2021-12-31    2022-01-08           0.8    NA
4 fl        2021-12-31    2022-01-08           0.2    NA
5 fl        2021-12-31    2022-01-08           0.5    NA
6 fl        2021-12-31    2022-01-08           0.8    NA
7 tx        2021-12-31    2022-01-08           0.2    NA
8 tx        2021-12-31    2022-01-08           0.5    NA
9 tx        2021-12-31    2022-01-08           0.8    NA
@dshemetov dshemetov changed the title flatline_forecaster error extracting prediction with non-standard quantiles flatline_forecaster error when using target_date Feb 2, 2024
dajmcdon added a commit that referenced this issue Mar 28, 2024
This was referenced Mar 28, 2024
@dshemetov dshemetov mentioned this issue Apr 2, 2024
4 tasks
dshemetov added a commit that referenced this issue Apr 3, 2024
dajmcdon added a commit that referenced this issue Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant