Skip to content

flatline_forecaster NA bug #454

Open
@dsweber2

Description

@dsweber2

If there are NAs at the end of the dataset, somehow flatline_forecaster ends up with a forecast that is repeated 3 times over.

here's constructing a synthetic example that has 2 days of NA values at the end

jhu <- epidatasets::covid_case_death_rates %>%
  dplyr::filter(time_value >= as.Date("2021-11-01"))
geo_values <- jhu$geo_value %>% unique()
one_day_nas <- tibble(
  geo_value = geo_values,
  time_value = as.Date("2022-01-01"),
  case_rate = NA,
  death_rate = runif(length(geo_values))
)
second_day_nas <- one_day_nas %>%
  mutate(time_value = as.Date("2022-01-02"))
jhu_nad <- jhu %>%
  as_tibble() %>%
  bind_rows(one_day_nas, second_day_nas) %>%
  epiprocess::as_epi_df()

with the result

res <- flatline_forecaster(jhu_nad, "case_rate")
+     res$predictions %>% arrange(geo_value)
> # A tibble: 168 × 5
   geo_value .pred .pred_distn forecast_date target_date
   <chr>     <dbl>   <qtls(7)> <date>        <date>     
 1 ak         36.4      [36.4] 2022-01-02    2022-01-09 
 2 ak         36.4      [36.4] 2022-01-02    2022-01-09 
 3 ak         36.4      [36.4] 2022-01-02    2022-01-09 
 4 al         89.9      [89.9] 2022-01-02    2022-01-09 
 5 al         89.9      [89.9] 2022-01-02    2022-01-09 
 6 al         89.9      [89.9] 2022-01-02    2022-01-09 
 7 ar         82.6      [82.6] 2022-01-02    2022-01-09 
 8 ar         82.6      [82.6] 2022-01-02    2022-01-09 
 9 ar         82.6      [82.6] 2022-01-02    2022-01-09 
10 as          0           [0] 2022-01-02    2022-01-09 
# ℹ 158 more rows
# ℹ Use `print(n = ...)` to see more rows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions