Skip to content

Commit ba0a94f

Browse files
authored
Merge pull request #437 from cmu-delphi/hotfix-growth_rate
Hotfix growth rate
2 parents 5496b84 + a4ab931 commit ba0a94f

14 files changed

+123
-135
lines changed

DESCRIPTION

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: epipredict
22
Title: Basic epidemiology forecasting methods
3-
Version: 0.1.9
3+
Version: 0.1.10
44
Authors@R: c(
55
person("Daniel J.", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
@@ -25,7 +25,7 @@ URL: https://github.com/cmu-delphi/epipredict/,
2525
BugReports: https://github.com/cmu-delphi/epipredict/issues/
2626
Depends:
2727
epidatasets,
28-
epiprocess (>= 0.9.0),
28+
epiprocess (>= 0.10.4),
2929
parsnip (>= 1.0.0),
3030
R (>= 3.5.0)
3131
Imports:
@@ -73,7 +73,6 @@ Remotes:
7373
cmu-delphi/epidatasets,
7474
cmu-delphi/epidatr,
7575
cmu-delphi/epiprocess,
76-
cmu-delphi/epidatasets,
7776
dajmcdon/smoothqr
7877
Config/Needs/website: cmu-delphi/delphidocs
7978
Config/testthat/edition: 3

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
1111
`data(<dataset name>)`, but can be accessed with
1212
`data(<dataset name>, package = "epidatasets")`, `epidatasets::<dataset name>`
1313
or, after loading the package, the name of the dataset alone (#382).
14+
- Addresses upstream breaking changes from cmu-delphi/epiprocess#595 (`growth_rate()`).
15+
`step_growth_rate()` has lost its `additional_gr_args_list` argument and now
16+
has an `na_rm` argument.
1417

1518
## Improvements
1619

R/arx_classifier.R

+14-24
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
#'
2828
#' @examples
2929
#' library(dplyr)
30+
#' tiny_geos <- c("as", "mp", "vi", "gu", "pr")
3031
#' jhu <- covid_case_death_rates %>%
31-
#' filter(time_value >= as.Date("2021-11-01"))
32+
#' filter(time_value >= as.Date("2021-11-01"), !(geo_value %in% tiny_geos))
3233
#'
3334
#' out <- arx_classifier(jhu, "death_rate", c("case_rate", "death_rate"))
3435
#'
@@ -58,7 +59,10 @@ arx_classifier <- function(
5859
if (args_list$adjust_latency == "none") {
5960
forecast_date_default <- max(epi_data$time_value)
6061
if (!is.null(args_list$forecast_date) && args_list$forecast_date != forecast_date_default) {
61-
cli_warn("The specified forecast date {args_list$forecast_date} doesn't match the date from which the forecast is occurring {forecast_date}.")
62+
cli_warn(
63+
"The specified forecast date {args_list$forecast_date} doesn't match the
64+
date from which the forecast is occurring {forecast_date}."
65+
)
6266
}
6367
} else {
6468
forecast_date_default <- attributes(epi_data)$metadata$as_of
@@ -101,7 +105,7 @@ arx_classifier <- function(
101105
#'
102106
#' @return An unfit `epi_workflow`.
103107
#' @export
104-
#' @seealso [arx_classifier()]
108+
#' @seealso [arx_classifier()] [arx_class_args_list()]
105109
#' @examples
106110
#' library(dplyr)
107111
#' jhu <- covid_case_death_rates %>%
@@ -154,12 +158,13 @@ arx_class_epi_workflow <- function(
154158
role = "grp",
155159
horizon = args_list$horizon,
156160
method = args_list$method,
157-
log_scale = args_list$log_scale,
158-
additional_gr_args_list = args_list$additional_gr_args
161+
log_scale = args_list$log_scale
159162
)
160163
for (l in seq_along(lags)) {
161164
pred_names <- predictors[l]
162-
pred_names <- as.character(glue::glue_data(args_list, "gr_{horizon}_{method}_{pred_names}"))
165+
pred_names <- as.character(glue::glue_data(
166+
args_list, "gr_{horizon}_{method}_{pred_names}"
167+
))
163168
r <- step_epi_lag(r, !!pred_names, lag = lags[[l]])
164169
}
165170
# ------- outcome
@@ -185,8 +190,7 @@ arx_class_epi_workflow <- function(
185190
role = "pre-outcome",
186191
horizon = args_list$horizon,
187192
method = args_list$method,
188-
log_scale = args_list$log_scale,
189-
additional_gr_args_list = args_list$additional_gr_args
193+
log_scale = args_list$log_scale
190194
)
191195
}
192196
}
@@ -270,9 +274,6 @@ arx_class_epi_workflow <- function(
270274
#' @param method Character. Options available for growth rate calculation.
271275
#' @param log_scale Scalar logical. Whether to compute growth rates on the
272276
#' log scale.
273-
#' @param additional_gr_args List. Optional arguments controlling growth rate
274-
#' calculation. See [epiprocess::growth_rate()] and the related Vignette for
275-
#' more details.
276277
#' @param check_enough_data_n Integer. A lower limit for the number of rows per
277278
#' epi_key that are required for training. If `NULL`, this check is ignored.
278279
#' @param check_enough_data_epi_keys Character vector. A character vector of
@@ -301,7 +302,6 @@ arx_class_args_list <- function(
301302
horizon = 7L,
302303
method = c("rel_change", "linear_reg"),
303304
log_scale = FALSE,
304-
additional_gr_args = list(),
305305
check_enough_data_n = NULL,
306306
check_enough_data_epi_keys = NULL,
307307
...) {
@@ -320,23 +320,14 @@ arx_class_args_list <- function(
320320
arg_is_lgl(log_scale)
321321
arg_is_pos(n_training)
322322
if (is.finite(n_training)) arg_is_pos_int(n_training)
323-
if (!is.list(additional_gr_args)) {
324-
cli_abort(c(
325-
"`additional_gr_args` must be a {.cls list}.",
326-
"!" = "This is a {.cls {class(additional_gr_args)}}.",
327-
i = "See `?epiprocess::growth_rate` for available arguments."
328-
))
329-
}
330323
arg_is_pos(check_enough_data_n, allow_null = TRUE)
331324
arg_is_chr(check_enough_data_epi_keys, allow_null = TRUE)
332325

333326
if (!is.null(forecast_date) && !is.null(target_date)) {
334327
if (forecast_date + ahead != target_date) {
335328
cli_warn(
336-
paste0(
337-
"`forecast_date` {.val {forecast_date}} +",
338-
" `ahead` {.val {ahead}} must equal `target_date` {.val {target_date}}."
339-
),
329+
"`forecast_date` {.val {forecast_date}} +
330+
`ahead` {.val {ahead}} must equal `target_date` {.val {target_date}}.",
340331
class = "epipredict__arx_args__inconsistent_target_ahead_forecaste_date"
341332
)
342333
}
@@ -362,7 +353,6 @@ arx_class_args_list <- function(
362353
horizon,
363354
method,
364355
log_scale,
365-
additional_gr_args,
366356
check_enough_data_n,
367357
check_enough_data_epi_keys
368358
),

R/step_growth_rate.R

+24-27
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@
2222
#' being removed from the data. Alternatively, you could specify arbitrary
2323
#' large values, or perhaps zero. Setting this argument to `NULL` will result
2424
#' in no replacement.
25-
#' @param additional_gr_args_list A list of additional arguments used by
26-
#' [epiprocess::growth_rate()]. All `...` arguments may be passed here along
27-
#' with `dup_rm` and `na_rm`.
25+
#' @inheritParams epiprocess::growth_rate
2826
#' @template step-return
2927
#'
3028
#'
3129
#' @family row operation steps
3230
#' @importFrom epiprocess growth_rate
3331
#' @export
3432
#' @examples
35-
#' r <- epi_recipe(covid_case_death_rates) %>%
33+
#' library(dplyr)
34+
#' tiny_geos <- c("as", "mp", "vi", "gu", "pr")
35+
#' rates <- covid_case_death_rates %>%
36+
#' filter(time_value >= as.Date("2021-11-01"), !(geo_value %in% tiny_geos))
37+
#'
38+
#' r <- epi_recipe(rates) %>%
3639
#' step_growth_rate(case_rate, death_rate)
3740
#' r
3841
#'
3942
#' r %>%
40-
#' prep(covid_case_death_rates) %>%
43+
#' prep(rates) %>%
4144
#' bake(new_data = NULL)
4245
step_growth_rate <-
4346
function(recipe,
@@ -46,11 +49,11 @@ step_growth_rate <-
4649
horizon = 7,
4750
method = c("rel_change", "linear_reg"),
4851
log_scale = FALSE,
52+
na_rm = TRUE,
4953
replace_Inf = NA,
5054
prefix = "gr_",
5155
skip = FALSE,
52-
id = rand_id("growth_rate"),
53-
additional_gr_args_list = list()) {
56+
id = rand_id("growth_rate")) {
5457
if (!is_epi_recipe(recipe)) {
5558
cli_abort("This recipe step can only operate on an {.cls epi_recipe}.")
5659
}
@@ -63,15 +66,7 @@ step_growth_rate <-
6366
}
6467
arg_is_chr(role)
6568
arg_is_chr_scalar(prefix, id)
66-
arg_is_lgl_scalar(log_scale, skip)
67-
68-
69-
if (!is.list(additional_gr_args_list)) {
70-
cli_abort(c(
71-
"`additional_gr_args_list` must be a {.cls list}.",
72-
i = "See `?epiprocess::growth_rate` for available options."
73-
))
74-
}
69+
arg_is_lgl_scalar(log_scale, skip, na_rm)
7570

7671
recipes::add_step(
7772
recipe,
@@ -82,13 +77,13 @@ step_growth_rate <-
8277
horizon = horizon,
8378
method = method,
8479
log_scale = log_scale,
80+
na_rm = na_rm,
8581
replace_Inf = replace_Inf,
8682
prefix = prefix,
8783
keys = key_colnames(recipe),
8884
columns = NULL,
8985
skip = skip,
90-
id = id,
91-
additional_gr_args_list = additional_gr_args_list
86+
id = id
9287
)
9388
)
9489
}
@@ -101,13 +96,13 @@ step_growth_rate_new <-
10196
horizon,
10297
method,
10398
log_scale,
99+
na_rm,
104100
replace_Inf,
105101
prefix,
106102
keys,
107103
columns,
108104
skip,
109-
id,
110-
additional_gr_args_list) {
105+
id) {
111106
recipes::step(
112107
subclass = "growth_rate",
113108
terms = terms,
@@ -116,13 +111,13 @@ step_growth_rate_new <-
116111
horizon = horizon,
117112
method = method,
118113
log_scale = log_scale,
114+
na_rm = na_rm,
119115
replace_Inf = replace_Inf,
120116
prefix = prefix,
121117
keys = keys,
122118
columns = columns,
123119
skip = skip,
124-
id = id,
125-
additional_gr_args_list = additional_gr_args_list
120+
id = id
126121
)
127122
}
128123

@@ -137,13 +132,13 @@ prep.step_growth_rate <- function(x, training, info = NULL, ...) {
137132
horizon = x$horizon,
138133
method = x$method,
139134
log_scale = x$log_scale,
135+
na_rm = x$na_rm,
140136
replace_Inf = x$replace_Inf,
141137
prefix = x$prefix,
142138
keys = x$keys,
143139
columns = recipes::recipes_eval_select(x$terms, training, info),
144140
skip = x$skip,
145-
id = x$id,
146-
additional_gr_args_list = x$additional_gr_args_list
141+
id = x$id
147142
)
148143
}
149144

@@ -177,10 +172,12 @@ bake.step_growth_rate <- function(object, new_data, ...) {
177172
across(
178173
all_of(object$columns),
179174
~ epiprocess::growth_rate(
180-
time_value, .x,
175+
.x,
176+
x = time_value,
181177
method = object$method,
182-
h = object$horizon, log_scale = object$log_scale,
183-
!!!object$additional_gr_args_list
178+
h = object$horizon,
179+
log_scale = object$log_scale,
180+
na_rm = object$na_rm
184181
),
185182
.names = "{object$prefix}{object$horizon}_{object$method}_{.col}"
186183
)

man/arx_class_args_list.Rd

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arx_class_epi_workflow.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/arx_classifier.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/epi_recipe.Rd

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)