27
27
# ' @seealso [step_climate()]
28
28
# '
29
29
# ' @examples
30
- # ' rates <- cases_deaths_subset
30
+ # ' cases <- cases_deaths_subset
31
31
# ' # set as_of to the last day in the data
32
- # ' attr(rates, "metadata")$as_of <- as.Date("2021-12-31")
33
- # ' fcast <- climatological_forecaster(rates, "case_rate_7d_av")
32
+ # ' # "case_rate_7d_av" is on the same scale for all geographies
33
+ # ' attr(cases, "metadata")$as_of <- as.Date("2021-12-31")
34
+ # ' fcast <- climatological_forecaster(cases, "case_rate_7d_av")
34
35
# ' autoplot(fcast)
35
36
# '
36
37
# ' # Compute quantiles separately by location, and a backcast
38
+ # ' # "cases" is on different scales by geography, due to population size
39
+ # ' # so, it is better to compute quantiles separately
37
40
# ' backcast <- climatological_forecaster(
38
- # ' rates , "case_rate_7d_av",
41
+ # ' cases , "case_rate_7d_av",
39
42
# ' climate_args_list(
40
43
# ' quantile_by_key = "geo_value",
41
44
# ' forecast_date = as.Date("2021-06-01")
45
48
# '
46
49
# ' # compute the climate "daily" rather than "weekly"
47
50
# ' # use a two week window (on both sides)
51
+ # ' # "cases" is on different scales by geography, due to population size
48
52
# ' daily_fcast <- climatological_forecaster(
49
- # ' rates , "case_rate_7d_av ",
53
+ # ' cases , "cases ",
50
54
# ' climate_args_list(
51
- # ' time_type = "day", window_size = 14L, forecast_horizon = 0:30
55
+ # ' quantile_by_key = "geo_value",
56
+ # ' time_type = "day",
57
+ # ' window_size = 14L,
58
+ # ' forecast_horizon = 0:30
52
59
# ' )
53
60
# ' )
54
61
# ' autoplot(daily_fcast) +
@@ -87,7 +94,7 @@ climatological_forecaster <- function(epi_data,
87
94
))
88
95
}
89
96
# process the time types
90
- sym_outcome <- sym (outcome )
97
+ sym_outcome <- rlang :: data_sym (outcome )
91
98
epi_data <- epi_data %> %
92
99
filter(! is.na(!! outcome )) %> %
93
100
select(all_of(c(key_colnames(epi_data ), outcome )))
@@ -123,7 +130,6 @@ climatological_forecaster <- function(epi_data,
123
130
rename(.pred = climate_pred )
124
131
# get the quantiles
125
132
Quantile <- function (x , w ) {
126
- x <- x - stats :: median(x , na.rm = TRUE )
127
133
if (args_list $ symmetrize ) x <- c(x , - x )
128
134
list (unname(quantile(
129
135
x ,
@@ -132,7 +138,7 @@ climatological_forecaster <- function(epi_data,
132
138
}
133
139
climate_quantiles <- epi_data %> %
134
140
left_join(climate_center , by = c(" .idx" , keys )) %> %
135
- mutate(sym_outcome = sym_outcome - .pred ) %> %
141
+ mutate({{ outcome }} : = !! sym_outcome - .pred ) %> %
136
142
select(.idx , .weights , all_of(c(outcome , args_list $ quantile_by_key ))) %> %
137
143
dplyr :: reframe(
138
144
roll_modular_multivec(
0 commit comments