cmu-delphi / epipredict

Tools for building predictive models in epidemiology.
https://cmu-delphi.github.io/epipredict/
Other
8 stars 9 forks source link

Add tests for weekly spaced data #397

Open dsweber2 opened 3 days ago

dsweber2 commented 3 days ago

The motivating case is this outdated snippet from step_epi_slide, yoinked from https://github.com/cmu-delphi/epipredict/pull/387

tt_week <- seq(as.Date("2022-01-01"), by = "1 week", length.out = 20)
edf_weekly <- data.frame(
  time_value = c(tt_week, tt_week),
  geo_value = rep(c("ca", "ny"), each = 20L),
  value = c(2:21, 3:22)
) %>%
  as_epi_df()

test_that("epi_slide works on weekly data with one of before/ahead set", {
  expect_no_error(
    baked <- epi_recipe(edf_weekly) %>%
      step_epi_slide(value, .f = "mean", before = as.difftime(3, units = "weeks")) %>%
      prep(edf_weekly) %>%
      bake(new_data = NULL)
  )
  attributes(baked)$metadata$as_of <- as.Date("1999-09-09")
  expect_snapshot(baked)
})