Skip to content

Commit f9c1d32

Browse files
committed
default quantiles are the same everywhere
1 parent 521756d commit f9c1d32

13 files changed

+23
-28
lines changed

R/arx_forecaster.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ arx_fcast_epi_workflow <- function(
253253
#' the last day of data. For example, if the last day of data was 3 days ago,
254254
#' the ahead becomes `ahead+3`.
255255
#' - `"extend_lags"`: increase the lags so they're relative to the actual
256-
#' forecast date. For example, if the lags are `c(0,7,14)` and the last day of
257-
#' data was 3 days ago, the lags become `c(3,10,17)`.
256+
#' forecast date. For example, if the lags are `c(0, 7, 14)` and the last day of
257+
#' data was 3 days ago, the lags become `c(3, 10, 17)`.
258258
#' @param warn_latency by default, `step_adjust_latency` warns the user if the
259259
#' latency is large. If this is `FALSE`, that warning is turned off.
260260
#' @param quantile_levels Vector or `NULL`. A vector of probabilities to produce
@@ -295,7 +295,7 @@ arx_args_list <- function(
295295
target_date = NULL,
296296
adjust_latency = c("none", "extend_ahead", "extend_lags", "locf"),
297297
warn_latency = TRUE,
298-
quantile_levels = c(0.05, 0.5, 0.95),
298+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
299299
symmetrize = TRUE,
300300
nonneg = TRUE,
301301
quantile_by_key = character(0L),
@@ -362,7 +362,7 @@ compare_quantile_args <- function(alist, tlist, train_method = c("qr", "grf")) {
362362
default_alist <- eval(formals(arx_args_list)$quantile_levels)
363363
default_tlist <- switch(train_method,
364364
"qr" = eval(formals(quantile_reg)$quantile_levels),
365-
"grf" = c(.1, .5, .9)
365+
"grf" = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95)
366366
)
367367
if (setequal(alist, default_alist)) {
368368
if (setequal(tlist, default_tlist)) {

R/autoplot.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ ggplot2::autoplot
3939
#' step_epi_naomit()
4040
#'
4141
#' f <- frosting() %>%
42-
#' layer_residual_quantiles(
43-
#' quantile_levels = c(.025, .1, .25, .75, .9, .975)
44-
#' ) %>%
42+
#' layer_residual_quantiles() %>%
4543
#' layer_threshold(starts_with(".pred")) %>%
4644
#' layer_add_target_date()
4745
#'

R/extract.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' @examples
1414
#' f <- frosting() %>%
1515
#' layer_predict() %>%
16-
#' layer_residual_quantiles(quantile_levels = c(0.0275, 0.975), symmetrize = FALSE) %>%
16+
#' layer_residual_quantiles(symmetrize = FALSE) %>%
1717
#' layer_naomit(.pred)
1818
#'
1919
#' extract_argument(f, "layer_residual_quantiles", "symmetrize")

R/flatline_forecaster.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ flatline_args_list <- function(
108108
n_training = Inf,
109109
forecast_date = NULL,
110110
target_date = NULL,
111-
quantile_levels = c(0.05, 0.5, 0.95),
111+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
112112
symmetrize = TRUE,
113113
nonneg = TRUE,
114114
quantile_by_key = character(0L),

R/layer_quantile_distn.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#' p
4545
layer_quantile_distn <- function(frosting,
4646
...,
47-
quantile_levels = c(0.25, 0.5, 0.75),
47+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
4848
truncate = c(-Inf, Inf),
4949
name = ".pred_distn",
5050
id = rand_id("quantile_distn")) {

R/layer_residual_quantiles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#' p2 <- forecast(wf2)
5050
layer_residual_quantiles <- function(
5151
frosting, ...,
52-
quantile_levels = c(0.025, 0.1, 0.25, 0.5, 0.75, 0.9, 0.975),
52+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
5353
symmetrize = TRUE,
5454
by_key = character(0L),
5555
name = ".pred_distn",

R/make_grf_quantiles.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ make_grf_quantiles <- function() {
141141
data = c(x = "X", y = "Y"),
142142
func = c(pkg = "grf", fun = "quantile_forest"),
143143
defaults = list(
144-
quantiles = c(0.1, 0.5, 0.9),
144+
quantiles = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
145145
num.threads = 1L,
146146
seed = rlang::expr(stats::runif(1, 0, .Machine$integer.max))
147147
)

R/make_quantile_reg.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' @param engine Character string naming the fitting function. Currently, only
1313
#' "rq" and "grf" are supported.
1414
#' @param quantile_levels A scalar or vector of values in (0, 1) to determine which
15-
#' quantiles to estimate (default is 0.5).
15+
#' quantiles to estimate (default is the set 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95).
1616
#' @param method A fitting method used by [quantreg::rq()]. See the
1717
#' documentation for a list of options.
1818
#'
@@ -27,7 +27,9 @@
2727
#' rq_spec <- quantile_reg(quantile_levels = c(.2, .8)) %>% set_engine("rq")
2828
#' ff <- rq_spec %>% fit(y ~ ., data = tib)
2929
#' predict(ff, new_data = tib)
30-
quantile_reg <- function(mode = "regression", engine = "rq", quantile_levels = 0.5, method = "br") {
30+
quantile_reg <- function(mode = "regression", engine = "rq",
31+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
32+
method = "br") {
3133
# Check for correct mode
3234
if (mode != "regression") {
3335
cli_abort("`mode` must be 'regression'")

R/make_smooth_quantile_reg.R

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
#' the [tidymodels](https://www.tidymodels.org/) framework. Currently, the
66
#' only supported engine is [smoothqr::smooth_qr()].
77
#'
8-
#' @param mode A single character string for the type of model.
9-
#' The only possible value for this model is "regression".
10-
#' @param engine Character string naming the fitting function. Currently, only
11-
#' "smooth_qr" is supported.
12-
#' @param quantile_levels A scalar or vector of values in (0, 1) to determine which
13-
#' quantiles to estimate (default is 0.5).
8+
#' @inheritParams quantile_reg
149
#' @param outcome_locations Defaults to the vector `1:ncol(y)` but if the
1510
#' responses are observed at a different spacing (or appear in a different
1611
#' order), that information should be used here. This
@@ -76,7 +71,7 @@ smooth_quantile_reg <- function(
7671
mode = "regression",
7772
engine = "smoothqr",
7873
outcome_locations = NULL,
79-
quantile_levels = 0.5,
74+
quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
8075
degree = 3L) {
8176
# Check for correct mode
8277
if (mode != "regression") cli_abort("`mode` must be 'regression'")

tests/testthat/test-layer_residual_quantiles.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ test_that("Grouping by keys is supported", {
6565
expect_warning(p2 <- forecast(wf2))
6666

6767
pivot1 <- pivot_quantiles_wider(p1, .pred_distn) %>%
68-
mutate(width = `0.9` - `0.1`)
68+
mutate(width = `0.95` - `0.05`)
6969
pivot2 <- pivot_quantiles_wider(p2, .pred_distn) %>%
70-
mutate(width = `0.9` - `0.1`)
70+
mutate(width = `0.95` - `0.05`)
7171
expect_equal(pivot1$width, rep(pivot1$width[1], nrow(pivot1)))
7272
expect_false(all(pivot2$width == pivot2$width[1]))
7373
})

0 commit comments

Comments
 (0)