Skip to content

Commit 0f4f2f9

Browse files
authored
Merge pull request #247 from cmu-delphi/v0.0.6
v0.0.6 to main
2 parents 96591a1 + c0d9e9e commit 0f4f2f9

File tree

75 files changed

+1948
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1948
-445
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
^musings$
1313
^data-raw$
1414
^vignettes/articles$
15+
^.git-blame-ignore-revs$

.github/workflows/styler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
33
on:
44
workflow_dispatch:
5-
pullrequest:
5+
pull_request:
66
paths:
77
[
88
"**.[rR]",

DESCRIPTION

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
Package: epipredict
22
Title: Basic epidemiology forecasting methods
3-
Version: 0.0.5
3+
Version: 0.0.6
44
Authors@R: c(
55
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
77
person("Logan", "Brooks", role = "aut"),
88
person("Rachel", "Lobay", role = "aut"),
9-
person("Maggie", "Liu", role = "aut"),
10-
person("Ken", "Mawer", role = "aut"),
11-
person("Chloe", "You", role = "aut"),
9+
person("Dmitry", "Shemetov", email = "[email protected]", role = "ctb"),
10+
person("David", "Weber", email = "[email protected]", role = "ctb"),
11+
person("Maggie", "Liu", role = "ctb"),
12+
person("Ken", "Mawer", role = "ctb"),
13+
person("Chloe", "You", role = "ctb"),
1214
person("Jacob", "Bien", role = "ctb")
1315
)
1416
Description: A forecasting "framework" for creating epidemiological
@@ -32,6 +34,7 @@ Imports:
3234
generics,
3335
glue,
3436
hardhat (>= 1.3.0),
37+
lifecycle,
3538
magrittr,
3639
methods,
3740
quantreg,

NAMESPACE

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ S3method(extrapolate_quantiles,dist_default)
3434
S3method(extrapolate_quantiles,dist_quantiles)
3535
S3method(extrapolate_quantiles,distribution)
3636
S3method(fit,epi_workflow)
37+
S3method(flusight_hub_formatter,canned_epipred)
38+
S3method(flusight_hub_formatter,data.frame)
3739
S3method(format,dist_quantiles)
3840
S3method(is.na,dist_quantiles)
3941
S3method(is.na,distribution)
@@ -52,6 +54,7 @@ S3method(print,alist)
5254
S3method(print,arx_class)
5355
S3method(print,arx_fcast)
5456
S3method(print,canned_epipred)
57+
S3method(print,cdc_baseline_fcast)
5558
S3method(print,epi_recipe)
5659
S3method(print,epi_workflow)
5760
S3method(print,flat_fcast)
@@ -81,6 +84,7 @@ S3method(residuals,flatline)
8184
S3method(run_mold,default_epi_recipe_blueprint)
8285
S3method(slather,layer_add_forecast_date)
8386
S3method(slather,layer_add_target_date)
87+
S3method(slather,layer_cdc_flatline_quantiles)
8488
S3method(slather,layer_naomit)
8589
S3method(slather,layer_point_from_distn)
8690
S3method(slather,layer_population_scaling)
@@ -108,6 +112,8 @@ export(arx_classifier)
108112
export(arx_fcast_epi_workflow)
109113
export(arx_forecaster)
110114
export(bake)
115+
export(cdc_baseline_args_list)
116+
export(cdc_baseline_forecaster)
111117
export(create_layer)
112118
export(default_epi_recipe_blueprint)
113119
export(detect_layer)
@@ -124,6 +130,7 @@ export(fit)
124130
export(flatline)
125131
export(flatline_args_list)
126132
export(flatline_forecaster)
133+
export(flusight_hub_formatter)
127134
export(frosting)
128135
export(get_test_data)
129136
export(grab_names)
@@ -133,6 +140,7 @@ export(is_layer)
133140
export(layer)
134141
export(layer_add_forecast_date)
135142
export(layer_add_target_date)
143+
export(layer_cdc_flatline_quantiles)
136144
export(layer_naomit)
137145
export(layer_point_from_distn)
138146
export(layer_population_scaling)
@@ -145,7 +153,8 @@ export(layer_unnest)
145153
export(nested_quantiles)
146154
export(new_default_epi_recipe_blueprint)
147155
export(new_epi_recipe_blueprint)
148-
export(pivot_quantiles)
156+
export(pivot_quantiles_longer)
157+
export(pivot_quantiles_wider)
149158
export(prep)
150159
export(quantile_reg)
151160
export(remove_frosting)
@@ -163,12 +172,13 @@ import(distributional)
163172
import(epiprocess)
164173
import(parsnip)
165174
import(recipes)
166-
import(vctrs)
175+
importFrom(cli,cli_abort)
167176
importFrom(epiprocess,growth_rate)
168177
importFrom(generics,augment)
169178
importFrom(generics,fit)
170179
importFrom(hardhat,refresh_blueprint)
171180
importFrom(hardhat,run_mold)
181+
importFrom(lifecycle,deprecated)
172182
importFrom(magrittr,"%>%")
173183
importFrom(methods,is)
174184
importFrom(quantreg,rq)
@@ -183,6 +193,7 @@ importFrom(rlang,caller_env)
183193
importFrom(rlang,is_empty)
184194
importFrom(rlang,is_null)
185195
importFrom(rlang,quos)
196+
importFrom(smoothqr,smooth_qr)
186197
importFrom(stats,as.formula)
187198
importFrom(stats,family)
188199
importFrom(stats,lm)
@@ -196,3 +207,12 @@ importFrom(stats,residuals)
196207
importFrom(tibble,as_tibble)
197208
importFrom(tibble,is_tibble)
198209
importFrom(tibble,tibble)
210+
importFrom(vctrs,as_list_of)
211+
importFrom(vctrs,field)
212+
importFrom(vctrs,new_rcrd)
213+
importFrom(vctrs,new_vctr)
214+
importFrom(vctrs,vec_cast)
215+
importFrom(vctrs,vec_data)
216+
importFrom(vctrs,vec_ptype_abbr)
217+
importFrom(vctrs,vec_ptype_full)
218+
importFrom(vctrs,vec_recycle_common)

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
# epipredict (development)
22

3+
# epipredict 0.0.6
4+
5+
* rename the `dist_quantiles()` to be more descriptive, breaking change)
6+
* removes previous `pivot_quantiles()` (now `*_wider()`, breaking change)
7+
* add `pivot_quantiles_wider()` for easier plotting
8+
* add complement `pivot_quantiles_longer()`
9+
* add `cdc_baseline_forecaster()` and `flusight_hub_formatter()`
10+
311
# epipredict 0.0.5
412

513
* add `smooth_quantile_reg()`
614
* improved printing of various methods / internals
715
* canned forecasters get a class
816
* fixed quantile bug in `flatline_forecaster()`
917
* add functionality to output the unfit workflow from the canned forecasters
10-
* add `pivot_quantiles()` for easier plotting
11-
1218

1319
# epipredict 0.0.4
1420

R/arx_classifier.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ arx_class_args_list <- function(
250250
method = c("rel_change", "linear_reg", "smooth_spline", "trend_filter"),
251251
log_scale = FALSE,
252252
additional_gr_args = list(),
253-
nafill_buffer = Inf) {
253+
nafill_buffer = Inf,
254+
...) {
255+
rlang::check_dots_empty()
254256
.lags <- lags
255257
if (is.list(lags)) lags <- unlist(lags)
256258
method <- match.arg(method)
@@ -305,3 +307,5 @@ print.arx_class <- function(x, ...) {
305307
name <- "ARX Classifier"
306308
NextMethod(name = name, ...)
307309
}
310+
311+
# this is a trivial change to induce a check

R/arx_forecaster.R

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#' out <- arx_forecaster(jhu, "death_rate",
3434
#' c("case_rate", "death_rate"),
3535
#' trainer = quantile_reg(),
36-
#' args_list = arx_args_list(levels = 1:9 / 10)
36+
#' args_list = arx_args_list(quantile_levels = 1:9 / 10)
3737
#' )
3838
arx_forecaster <- function(epi_data,
3939
outcome,
@@ -99,7 +99,7 @@ arx_forecaster <- function(epi_data,
9999
#' arx_fcast_epi_workflow(jhu, "death_rate",
100100
#' c("case_rate", "death_rate"),
101101
#' trainer = quantile_reg(),
102-
#' args_list = arx_args_list(levels = 1:9 / 10)
102+
#' args_list = arx_args_list(quantile_levels = 1:9 / 10)
103103
#' )
104104
arx_fcast_epi_workflow <- function(
105105
epi_data,
@@ -134,18 +134,20 @@ arx_fcast_epi_workflow <- function(
134134
# --- postprocessor
135135
f <- frosting() %>% layer_predict() # %>% layer_naomit()
136136
if (inherits(trainer, "quantile_reg")) {
137-
# add all levels to the forecaster and update postprocessor
138-
tau <- sort(compare_quantile_args(
139-
args_list$levels,
140-
rlang::eval_tidy(trainer$args$tau)
137+
# add all quantile_level to the forecaster and update postprocessor
138+
quantile_levels <- sort(compare_quantile_args(
139+
args_list$quantile_levels,
140+
rlang::eval_tidy(trainer$args$quantile_levels)
141141
))
142-
args_list$levels <- tau
143-
trainer$args$tau <- rlang::enquo(tau)
144-
f <- layer_quantile_distn(f, levels = tau) %>% layer_point_from_distn()
142+
args_list$quantile_levels <- quantile_levels
143+
trainer$args$quantile_levels <- rlang::enquo(quantile_levels)
144+
f <- layer_quantile_distn(f, quantile_levels = quantile_levels) %>%
145+
layer_point_from_distn()
145146
} else {
146147
f <- layer_residual_quantiles(
147148
f,
148-
probs = args_list$levels, symmetrize = args_list$symmetrize,
149+
quantile_levels = args_list$quantile_levels,
150+
symmetrize = args_list$symmetrize,
149151
by_key = args_list$quantile_by_key
150152
)
151153
}
@@ -173,7 +175,7 @@ arx_fcast_epi_workflow <- function(
173175
#' The default `NULL` will attempt to determine this automatically.
174176
#' @param target_date Date. The date for which the forecast is intended.
175177
#' The default `NULL` will attempt to determine this automatically.
176-
#' @param levels Vector or `NULL`. A vector of probabilities to produce
178+
#' @param quantile_levels Vector or `NULL`. A vector of probabilities to produce
177179
#' prediction intervals. These are created by computing the quantiles of
178180
#' training residuals. A `NULL` value will result in point forecasts only.
179181
#' @param symmetrize Logical. The default `TRUE` calculates
@@ -197,6 +199,7 @@ arx_fcast_epi_workflow <- function(
197199
#' create a prediction. For this reason, setting `nafill_buffer < min(lags)`
198200
#' will be treated as _additional_ allowed recent data rather than the
199201
#' total amount of recent data to examine.
202+
#' @param ... Space to handle future expansions (unused).
200203
#'
201204
#'
202205
#' @return A list containing updated parameter choices with class `arx_flist`.
@@ -205,18 +208,19 @@ arx_fcast_epi_workflow <- function(
205208
#' @examples
206209
#' arx_args_list()
207210
#' arx_args_list(symmetrize = FALSE)
208-
#' arx_args_list(levels = c(.1, .3, .7, .9), n_training = 120)
211+
#' arx_args_list(quantile_levels = c(.1, .3, .7, .9), n_training = 120)
209212
arx_args_list <- function(
210213
lags = c(0L, 7L, 14L),
211214
ahead = 7L,
212215
n_training = Inf,
213216
forecast_date = NULL,
214217
target_date = NULL,
215-
levels = c(0.05, 0.95),
218+
quantile_levels = c(0.05, 0.95),
216219
symmetrize = TRUE,
217220
nonneg = TRUE,
218221
quantile_by_key = character(0L),
219-
nafill_buffer = Inf) {
222+
nafill_buffer = Inf,
223+
...) {
220224
# error checking if lags is a list
221225
.lags <- lags
222226
if (is.list(lags)) lags <- unlist(lags)
@@ -227,7 +231,7 @@ arx_args_list <- function(
227231
arg_is_date(forecast_date, target_date, allow_null = TRUE)
228232
arg_is_nonneg_int(ahead, lags)
229233
arg_is_lgl(symmetrize, nonneg)
230-
arg_is_probabilities(levels, allow_null = TRUE)
234+
arg_is_probabilities(quantile_levels, allow_null = TRUE)
231235
arg_is_pos(n_training)
232236
if (is.finite(n_training)) arg_is_pos_int(n_training)
233237
if (is.finite(nafill_buffer)) arg_is_pos_int(nafill_buffer, allow_null = TRUE)
@@ -238,7 +242,7 @@ arx_args_list <- function(
238242
lags = .lags,
239243
ahead,
240244
n_training,
241-
levels,
245+
quantile_levels,
242246
forecast_date,
243247
target_date,
244248
symmetrize,
@@ -259,8 +263,8 @@ print.arx_fcast <- function(x, ...) {
259263
}
260264

261265
compare_quantile_args <- function(alist, tlist) {
262-
default_alist <- eval(formals(arx_args_list)$levels)
263-
default_tlist <- eval(formals(quantile_reg)$tau)
266+
default_alist <- eval(formals(arx_args_list)$quantile_level)
267+
default_tlist <- eval(formals(quantile_reg)$quantile_level)
264268
if (setequal(alist, default_alist)) {
265269
if (setequal(tlist, default_tlist)) {
266270
return(sort(unique(union(alist, tlist))))

R/canned-epipred.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ validate_forecaster_inputs <- function(epi_data, outcome, predictors) {
88
arg_is_chr(predictors)
99
arg_is_chr_scalar(outcome)
1010
if (!outcome %in% names(epi_data)) {
11-
cli::cli_abort("{outcome} was not found in the training data.")
11+
cli::cli_abort("{.var {outcome}} was not found in the training data.")
1212
}
1313
check <- hardhat::check_column_names(epi_data, predictors)
1414
if (!check$ok) {
1515
cli::cli_abort(c(
1616
"At least one predictor was not found in the training data.",
17-
"!" = "The following required columns are missing: {check$missing_names}."
17+
"!" = "The following required columns are missing: {.val {check$missing_names}}."
1818
))
1919
}
2020
invisible(TRUE)
@@ -41,8 +41,8 @@ arx_lags_validator <- function(predictors, lags) {
4141
predictors_miss <- setdiff(predictors, names(lags))
4242
cli::cli_abort(c(
4343
"If lags is a named list, then all predictors must be present.",
44-
i = "The predictors are '{predictors}'.",
45-
i = "So lags is missing '{predictors_miss}'."
44+
i = "The predictors are {.var {predictors}}.",
45+
i = "So lags is missing {.var {predictors_miss}}'."
4646
))
4747
}
4848
}

0 commit comments

Comments
 (0)