Skip to content

Commit 5e3ed56

Browse files
committed
fix rlang bug, more detailed examples
1 parent bece1fe commit 5e3ed56

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

R/climatological_forecaster.R

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
#' @seealso [step_climate()]
2828
#'
2929
#' @examples
30-
#' rates <- cases_deaths_subset
30+
#' cases <- cases_deaths_subset
3131
#' # 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")
3435
#' autoplot(fcast)
3536
#'
3637
#' # 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
3740
#' backcast <- climatological_forecaster(
38-
#' rates, "case_rate_7d_av",
41+
#' cases, "case_rate_7d_av",
3942
#' climate_args_list(
4043
#' quantile_by_key = "geo_value",
4144
#' forecast_date = as.Date("2021-06-01")
@@ -45,10 +48,14 @@
4548
#'
4649
#' # compute the climate "daily" rather than "weekly"
4750
#' # use a two week window (on both sides)
51+
#' # "cases" is on different scales by geography, due to population size
4852
#' daily_fcast <- climatological_forecaster(
49-
#' rates, "case_rate_7d_av",
53+
#' cases, "cases",
5054
#' 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
5259
#' )
5360
#' )
5461
#' autoplot(daily_fcast) +
@@ -87,7 +94,7 @@ climatological_forecaster <- function(epi_data,
8794
))
8895
}
8996
# process the time types
90-
sym_outcome <- sym(outcome)
97+
sym_outcome <- rlang::data_sym(outcome)
9198
epi_data <- epi_data %>%
9299
filter(!is.na(!!outcome)) %>%
93100
select(all_of(c(key_colnames(epi_data), outcome)))
@@ -123,7 +130,6 @@ climatological_forecaster <- function(epi_data,
123130
rename(.pred = climate_pred)
124131
# get the quantiles
125132
Quantile <- function(x, w) {
126-
x <- x - stats::median(x, na.rm = TRUE)
127133
if (args_list$symmetrize) x <- c(x, -x)
128134
list(unname(quantile(
129135
x,
@@ -132,7 +138,7 @@ climatological_forecaster <- function(epi_data,
132138
}
133139
climate_quantiles <- epi_data %>%
134140
left_join(climate_center, by = c(".idx", keys)) %>%
135-
mutate(sym_outcome = sym_outcome - .pred) %>%
141+
mutate({{outcome}} := !!sym_outcome - .pred) %>%
136142
select(.idx, .weights, all_of(c(outcome, args_list$quantile_by_key))) %>%
137143
dplyr::reframe(
138144
roll_modular_multivec(

man/climatological_forecaster.Rd

Lines changed: 13 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)