Skip to content

Commit f05ec0c

Browse files
committed
Note that having lag and ahead as negative values is odd behaviour.
1 parent 5d3546f commit f05ec0c

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed
Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1-
test_that("epi_shift_interal", {
1+
# Loading
2+
library(tidyverse)
3+
library(covidcast)
4+
library(delphi.epidata)
5+
library(epiprocess)
6+
library(tidymodels)
27

8+
# Taken from example-recipe
9+
x <- covidcast(
10+
data_source = "jhu-csse",
11+
signals = "confirmed_7dav_incidence_prop",
12+
time_type = "day",
13+
geo_type = "state",
14+
time_values = epirange(20200301, 20211231),
15+
geo_values = "*"
16+
) %>%
17+
fetch_tbl() %>%
18+
select(geo_value, time_value, case_rate = value)
19+
20+
y <- covidcast(
21+
data_source = "jhu-csse",
22+
signals = "deaths_7dav_incidence_prop",
23+
time_type = "day",
24+
geo_type = "state",
25+
time_values = epirange(20200301, 20211231),
26+
geo_values = "*"
27+
) %>%
28+
fetch_tbl() %>%
29+
select(geo_value, time_value, death_rate = value)
30+
31+
x <- x %>%
32+
full_join(y, by = c("geo_value", "time_value")) %>%
33+
as_epi_df()
34+
rm(y)
35+
36+
xx <- x %>% filter(time_value > "2021-12-01")
37+
38+
# Tests
39+
test_that("Check that epi_ahead shifts properly", {
40+
r <- epi_recipe(x) %>%
41+
step_epi_ahead(death_rate, ahead = 7) %>%
42+
step_epi_lag(death_rate, lag = -7) %>%
43+
step_naomit(all_predictors()) %>%
44+
step_naomit(all_outcomes(), skip = TRUE)
45+
46+
slm_fit <- workflow() %>%
47+
add_recipe(r) %>%
48+
add_model(linear_reg()) %>%
49+
fit(data = x)
50+
51+
slope_ahead <- slm_fit$fit$fit$fit$coefficients[[2]]
52+
expect_equal(slope_ahead,1)
53+
})
54+
55+
test_that("Check that epi_lag shifts properly", {
56+
r2 <- epi_recipe(x) %>%
57+
step_epi_ahead(death_rate, ahead = -7) %>%
58+
step_epi_lag(death_rate, lag = 7) %>%
59+
step_naomit(all_predictors()) %>%
60+
step_naomit(all_outcomes(), skip = TRUE)
61+
62+
slm_fit2 <- workflow() %>%
63+
add_recipe(r2) %>%
64+
add_model(linear_reg()) %>%
65+
fit(data = x)
66+
67+
slope_lag <- slm_fit2$fit$fit$fit$coefficients[[2]]
68+
expect_equal(slope_lag,1)
369
})

0 commit comments

Comments
 (0)