Skip to content

Commit d6edae8

Browse files
committed
extra details for symmetrize
1 parent c5a37a9 commit d6edae8

File tree

9 files changed

+58
-35
lines changed

9 files changed

+58
-35
lines changed

R/arx_forecaster.R

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,13 @@ arx_fcast_epi_workflow <- function(
268268
#' @param quantile_levels Vector or `NULL`. A vector of probabilities to produce
269269
#' prediction intervals. These are created by computing the quantiles of
270270
#' training residuals. A `NULL` value will result in point forecasts only.
271-
#' @param symmetrize Logical. The default `TRUE` calculates
272-
#' symmetric prediction intervals. This argument only applies when
273-
#' residual quantiles are used. It is not applicable with
274-
#' `trainer = quantile_reg()`, for example.
271+
#' @param symmetrize Logical. The default `TRUE` calculates symmetric prediction
272+
#' intervals. This argument only applies when residual quantiles are used. It
273+
#' is not applicable with `trainer = quantile_reg()`, for example. This is
274+
#' achieved by including both the residuals and their negation. Typically, one
275+
#' would only want non-symmetric quantiles when increasing trajectories are
276+
#' quite different from decreasing ones, such as a strictly postive variable
277+
#' near zero.
275278
#' @param nonneg Logical. The default `TRUE` enforces nonnegative predictions
276279
#' by hard-thresholding at 0.
277280
#' @param quantile_by_key Character vector. Groups residuals by listed keys

R/layer_residual_quantiles.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
#' @param quantile_levels numeric vector of probabilities with values in (0,1)
1111
#' referring to the desired quantile. Note that 0.5 will always be included
1212
#' even if left out by the user.
13-
#' @param symmetrize logical. If `TRUE` then interval will be symmetric.
13+
#' @param symmetrize logical. If `TRUE` then the interval will be symmetric.
14+
#' This is achieved by including both the residuals and their negations.
15+
#' Typically, one would only want non-symmetric quantiles when increasing
16+
#' trajectories are quite different from decreasing ones, such as a strictly
17+
#' postive variable near zero.
1418
#' @param by_key A character vector of keys to group the residuals by before
1519
#' calculating quantiles. The default, `c()` performs no grouping.
1620
#' @param name character. The name for the output column.
@@ -96,7 +100,7 @@ slather.layer_residual_quantiles <-
96100
return(components)
97101
}
98102

99-
s <- ifelse(object$symmetrize, -1, NA)
103+
symmetric <- ifelse(object$symmetrize, -1, NA)
100104
r <- grab_residuals(the_fit, components)
101105

102106
## Handle any grouping requests
@@ -131,7 +135,7 @@ slather.layer_residual_quantiles <-
131135

132136
r <- r %>%
133137
summarize(dstn = quantile_pred(matrix(quantile(
134-
c(.resid, s * .resid),
138+
c(.resid, symmetric * .resid),
135139
probs = object$quantile_levels, na.rm = TRUE
136140
), nrow = 1), quantile_levels = object$quantile_levels))
137141
# Check for NA

man/arx_args_list.Rd

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

man/cdc_baseline_args_list.Rd

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

man/climate_args_list.Rd

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

man/flatline_args_list.Rd

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

man/layer_residual_quantiles.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/step_adjust_latency.Rd

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

vignettes/epipredict.Rmd

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ This is a different method of generating a flatline forecast, used as a baseline
264264
for [COVID19ForecastHub](https://covid19forecasthub.org).
265265

266266
```{r make-cdc-forecast, warning=FALSE}
267-
all_cdc_flatline <-
268-
cdc_baseline_forecaster(
269-
covid_case_death_rates |>
270-
filter(time_value <= forecast_date, geo_value %in% used_locations),
271-
outcome = "death_rate",
272-
args_list = cdc_baseline_args_list(
273-
aheads = 1:28,
274-
data_frequency = "1 day"
267+
all_cdc_flatline <-
268+
cdc_baseline_forecaster(
269+
covid_case_death_rates |>
270+
filter(time_value <= forecast_date, geo_value %in% used_locations),
271+
outcome = "death_rate",
272+
args_list = cdc_baseline_args_list(
273+
aheads = 1:28,
274+
data_frequency = "1 day"
275+
)
275276
)
276-
)
277277
# same plotting code as in the arx multi-ahead case
278278
workflow <- all_cdc_flatline$epi_workflow
279279
results <- all_cdc_flatline$predictions

0 commit comments

Comments
 (0)