|
| 1 | +library(dplyr) |
| 2 | +library(epiprocess) |
| 3 | +library(parsnip) |
| 4 | +library(workflows) |
| 5 | + |
| 6 | +# Random generated dataset |
| 7 | +set.seed(100) |
| 8 | +x <- tibble(geo_value = rep("nowhere",200), |
| 9 | + time_value = as.Date("2021-01-01") + 0:199, |
| 10 | + case_rate = rpois(100,20) + 1:200, |
| 11 | + death_rate = rpois(100,10) + 1:200) %>% |
| 12 | + as_epi_df() |
| 13 | + |
| 14 | +y <- tibble(geo_value = rep("nowhere",200), |
| 15 | + time_value = as.Date("2021-01-01") + 0:199, |
| 16 | + case_rate = rpois(100,20) + 1:200, |
| 17 | + death_rate = rpois(100,10) + 1:200) %>% |
| 18 | + as_epi_df() |
| 19 | + |
| 20 | +# Tests |
| 21 | +test_that("Check that epi_ahead shifts properly", { |
| 22 | + r1 <- epi_recipe(x) %>% |
| 23 | + step_epi_ahead(death_rate, ahead = 7) %>% |
| 24 | + step_epi_lag(death_rate, lag = c(0,7,14)) |
| 25 | + |
| 26 | + r2 <- epi_recipe(y) %>% |
| 27 | + step_epi_ahead(death_rate, ahead = 7) %>% |
| 28 | + step_epi_lag(death_rate, lag = c(0,7,14)) |
| 29 | + |
| 30 | + r3 <- r1 %>% |
| 31 | + step_naomit(all_predictors()) %>% |
| 32 | + step_naomit(all_outcomes(), skip = TRUE) |
| 33 | + |
| 34 | + r4 <- step_naomit2(r2) |
| 35 | + |
| 36 | + expect_identical(r3,r4) |
| 37 | +}) |
0 commit comments