@@ -34,10 +34,10 @@ modified_data <-
34
34
modified_data %> % tail()
35
35
as_of - (modified_data %> % filter(! is.na(ahead_4_case_rate )) %> % pull(time_value ) %> % max())
36
36
all_shift_cols <- tibble :: tribble(
37
- ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
38
- " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 5 , 8 , " lag_8_case_rate" , " numeric" , " predictor" ,
39
- " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 4 , 11 , " lag_11_death_rate" , " numeric" , " predictor" ,
40
- " case_rate" , 4 , " ahead_" , " ahead_4_case_rate" , - 5 , 9 , " ahead_9_case_rate" , " numeric" , " outcome"
37
+ ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
38
+ " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 5 , 8 , " lag_8_case_rate" , " numeric" , " predictor" ,
39
+ " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 4 , 11 , " lag_11_death_rate" , " numeric" , " predictor" ,
40
+ " case_rate" , 4 , " ahead_" , " ahead_4_case_rate" , - 5 , 9 , " ahead_9_case_rate" , " numeric" , " outcome"
41
41
)
42
42
test_recipe <- epi_recipe(modified_data ) %> %
43
43
step_epi_lag(case_rate , lag = c(3 )) %> %
@@ -82,12 +82,12 @@ test_that("get_latent_column_tibble infers latency and works correctly", {
82
82
info <- tibble(variable = c(" lag_3_case_rate" , " lag_7_death_rate" , " ahead_4_case_rate" ), type = " numeric" , role = c(rep(" predictor" , 2 ), " outcome" ), source = " derived" )
83
83
84
84
case_lag <- get_latent_column_tibble(
85
- shift_cols [1 ,], modified_data , as_of , NULL , 1 , info
85
+ shift_cols [1 , ], modified_data , as_of , NULL , 1 , info
86
86
)
87
87
expect_equal(case_lag , all_shift_cols [1 , ])
88
88
89
89
death_lag <- get_latent_column_tibble(
90
- shift_cols [2 ,], modified_data , as_of , NULL , 1 , info
90
+ shift_cols [2 , ], modified_data , as_of , NULL , 1 , info
91
91
)
92
92
expect_equal(death_lag , all_shift_cols [2 , ])
93
93
@@ -104,17 +104,17 @@ test_that("get_latent_column_tibble assigns given latencies", {
104
104
shift_cols , modified_data , as_of , 50 , 1 , info
105
105
)
106
106
weird_latencies <- tibble :: tribble(
107
- ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
108
- " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 50 , 53 , " lag_53_case_rate" , " numeric" , " predictor" ,
109
- " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 50 , 57 , " lag_57_death_rate" , " numeric" , " predictor" ,
107
+ ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
108
+ " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 50 , 53 , " lag_53_case_rate" , " numeric" , " predictor" ,
109
+ " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 50 , 57 , " lag_57_death_rate" , " numeric" , " predictor" ,
110
110
)
111
111
expect_equal(both_lag , weird_latencies )
112
112
113
113
# supposing we add the latencies by hand, and they're different, and in a different order
114
114
weird_latencies <- tibble :: tribble(
115
- ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
116
- " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 70 , 73 , " lag_73_case_rate" , " numeric" , " predictor" ,
117
- " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 30 , 37 , " lag_37_death_rate" , " numeric" , " predictor" ,
115
+ ~ terms , ~ shift , ~ prefix , ~ original_name , ~ latency , ~ effective_shift , ~ new_name , ~ type , ~ role ,
116
+ " case_rate" , 3 , " lag_" , " lag_3_case_rate" , 70 , 73 , " lag_73_case_rate" , " numeric" , " predictor" ,
117
+ " death_rate" , 7 , " lag_" , " lag_7_death_rate" , 30 , 37 , " lag_37_death_rate" , " numeric" , " predictor" ,
118
118
)
119
119
both_lag <- get_latent_column_tibble(
120
120
shift_cols , modified_data , as_of , c(death_rate = 30 , case_rate = 70 ), 1 , info
0 commit comments