Skip to content

Commit dc5c7ac

Browse files
authored
Merge pull request #443 from cmu-delphi/nh-quantiles
hardhat quantiles
2 parents 4da9b23 + 8387aa2 commit dc5c7ac

Some content is hidden

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

54 files changed

+1849
-3094
lines changed

DESCRIPTION

+2-4
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.11
3+
Version: 0.1.12
44
Authors@R: c(
55
person("Daniel J.", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
@@ -30,13 +30,12 @@ Depends:
3030
Imports:
3131
checkmate,
3232
cli,
33-
distributional,
3433
dplyr,
3534
epiprocess (>= 0.10.4),
3635
generics,
3736
ggplot2,
3837
glue,
39-
hardhat (>= 1.3.0),
38+
hardhat (>= 1.4.1),
4039
lifecycle,
4140
lubridate,
4241
magrittr,
@@ -77,6 +76,5 @@ Remotes:
7776
Config/Needs/website: cmu-delphi/delphidocs
7877
Config/testthat/edition: 3
7978
Encoding: UTF-8
80-
LazyData: true
8179
Roxygen: list(markdown = TRUE)
8280
RoxygenNote: 7.3.2

NAMESPACE

+20-31
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
S3method(Add_model,epi_workflow)
44
S3method(Add_model,workflow)
5-
S3method(Math,dist_quantiles)
6-
S3method(Ops,dist_quantiles)
75
S3method(Remove_model,epi_workflow)
86
S3method(Remove_model,workflow)
97
S3method(Update_model,epi_workflow)
@@ -41,20 +39,14 @@ S3method(extract_frosting,default)
4139
S3method(extract_frosting,epi_workflow)
4240
S3method(extract_layers,frosting)
4341
S3method(extract_layers,workflow)
44-
S3method(extrapolate_quantiles,dist_default)
45-
S3method(extrapolate_quantiles,dist_quantiles)
46-
S3method(extrapolate_quantiles,distribution)
42+
S3method(extrapolate_quantiles,quantile_pred)
4743
S3method(fit,epi_workflow)
4844
S3method(flusight_hub_formatter,canned_epipred)
4945
S3method(flusight_hub_formatter,data.frame)
5046
S3method(forecast,epi_workflow)
51-
S3method(format,dist_quantiles)
52-
S3method(is.na,dist_quantiles)
53-
S3method(is.na,distribution)
5447
S3method(key_colnames,epi_workflow)
5548
S3method(key_colnames,recipe)
56-
S3method(mean,dist_quantiles)
57-
S3method(median,dist_quantiles)
49+
S3method(mean,quantile_pred)
5850
S3method(predict,epi_workflow)
5951
S3method(predict,flatline)
6052
S3method(prep,check_enough_train_data)
@@ -86,7 +78,6 @@ S3method(print,layer_naomit)
8678
S3method(print,layer_point_from_distn)
8779
S3method(print,layer_population_scaling)
8880
S3method(print,layer_predict)
89-
S3method(print,layer_predictive_distn)
9081
S3method(print,layer_quantile_distn)
9182
S3method(print,layer_residual_quantiles)
9283
S3method(print,layer_threshold)
@@ -101,7 +92,7 @@ S3method(print,step_lag_difference)
10192
S3method(print,step_naomit)
10293
S3method(print,step_population_scaling)
10394
S3method(print,step_training_window)
104-
S3method(quantile,dist_quantiles)
95+
S3method(quantile,quantile_pred)
10596
S3method(refresh_blueprint,default_epi_recipe_blueprint)
10697
S3method(residuals,flatline)
10798
S3method(run_mold,default_epi_recipe_blueprint)
@@ -112,25 +103,22 @@ S3method(slather,layer_naomit)
112103
S3method(slather,layer_point_from_distn)
113104
S3method(slather,layer_population_scaling)
114105
S3method(slather,layer_predict)
115-
S3method(slather,layer_predictive_distn)
116106
S3method(slather,layer_quantile_distn)
117107
S3method(slather,layer_residual_quantiles)
118108
S3method(slather,layer_threshold)
119109
S3method(slather,layer_unnest)
120110
S3method(snap,default)
121-
S3method(snap,dist_default)
122-
S3method(snap,dist_quantiles)
123-
S3method(snap,distribution)
111+
S3method(snap,quantile_pred)
124112
S3method(tidy,check_enough_train_data)
125113
S3method(tidy,frosting)
126114
S3method(tidy,layer)
127115
S3method(update,layer)
128-
S3method(vec_ptype_abbr,dist_quantiles)
129-
S3method(vec_ptype_full,dist_quantiles)
130-
S3method(weighted_interval_score,default)
131-
S3method(weighted_interval_score,dist_default)
132-
S3method(weighted_interval_score,dist_quantiles)
133-
S3method(weighted_interval_score,distribution)
116+
S3method(vec_arith,quantile_pred)
117+
S3method(vec_arith.numeric,quantile_pred)
118+
S3method(vec_arith.quantile_pred,numeric)
119+
S3method(vec_math,quantile_pred)
120+
S3method(vec_proxy_equal,quantile_pred)
121+
S3method(weighted_interval_score,quantile_pred)
134122
export("%>%")
135123
export(Add_model)
136124
export(Remove_model)
@@ -167,6 +155,7 @@ export(epi_workflow)
167155
export(extract_argument)
168156
export(extract_frosting)
169157
export(extract_layers)
158+
export(extract_quantile_levels)
170159
export(extrapolate_quantiles)
171160
export(filter)
172161
export(fit)
@@ -203,6 +192,7 @@ export(pivot_quantiles_longer)
203192
export(pivot_quantiles_wider)
204193
export(pivot_wider)
205194
export(prep)
195+
export(quantile_pred)
206196
export(quantile_reg)
207197
export(rand_id)
208198
export(remove_epi_recipe)
@@ -212,6 +202,7 @@ export(rename)
212202
export(select)
213203
export(slather)
214204
export(smooth_quantile_reg)
205+
export(snap)
215206
export(step_adjust_latency)
216207
export(step_climate)
217208
export(step_epi_ahead)
@@ -230,7 +221,6 @@ export(update_frosting)
230221
export(update_model)
231222
export(validate_layer)
232223
export(weighted_interval_score)
233-
import(distributional)
234224
import(epidatasets)
235225
import(epiprocess)
236226
import(parsnip)
@@ -290,9 +280,12 @@ importFrom(ggplot2,geom_linerange)
290280
importFrom(ggplot2,geom_point)
291281
importFrom(ggplot2,geom_ribbon)
292282
importFrom(glue,glue)
283+
importFrom(hardhat,extract_quantile_levels)
293284
importFrom(hardhat,extract_recipe)
285+
importFrom(hardhat,quantile_pred)
294286
importFrom(hardhat,refresh_blueprint)
295287
importFrom(hardhat,run_mold)
288+
importFrom(lifecycle,deprecated)
296289
importFrom(lubridate,"%m-%")
297290
importFrom(lubridate,leap_year)
298291
importFrom(lubridate,month)
@@ -325,14 +318,11 @@ importFrom(rlang,list2)
325318
importFrom(rlang,set_names)
326319
importFrom(rlang,sym)
327320
importFrom(stats,as.formula)
328-
importFrom(stats,family)
329321
importFrom(stats,lm)
330-
importFrom(stats,median)
331322
importFrom(stats,model.frame)
332323
importFrom(stats,na.omit)
333324
importFrom(stats,poly)
334325
importFrom(stats,predict)
335-
importFrom(stats,qnorm)
336326
importFrom(stats,quantile)
337327
importFrom(stats,residuals)
338328
importFrom(tibble,as_tibble)
@@ -347,12 +337,11 @@ importFrom(tidyr,unnest)
347337
importFrom(tidyselect,all_of)
348338
importFrom(utils,capture.output)
349339
importFrom(vctrs,as_list_of)
350-
importFrom(vctrs,field)
351-
importFrom(vctrs,new_rcrd)
352340
importFrom(vctrs,new_vctr)
341+
importFrom(vctrs,vec_arith)
342+
importFrom(vctrs,vec_arith.numeric)
353343
importFrom(vctrs,vec_cast)
354-
importFrom(vctrs,vec_data)
355-
importFrom(vctrs,vec_ptype_abbr)
356-
importFrom(vctrs,vec_ptype_full)
344+
importFrom(vctrs,vec_math)
345+
importFrom(vctrs,vec_proxy_equal)
357346
importFrom(vctrs,vec_recycle_common)
358347
importFrom(workflows,extract_preprocessor)

NEWS.md

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
1717
has an `na_rm` argument.
1818
- Moves `epiprocess` out of depends (#440). No internals have changed, but downstream
1919
users may need to add `library(epiprocess)` to existing code.
20+
- Removes dependence on the `distributional` package, replacing the quantiles
21+
with `hardhat::quantile_pred()`. Some associated functions are deprecated with
22+
`lifecycle` messages.
2023

2124
## Improvements
2225

@@ -28,6 +31,8 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
2831
- Add `reference_date` as an argument to `epi_recipe()`
2932
- Add `step_climate()` to create "climate" predictor in forecast workflows
3033
- Add `climatological_forecaster()` to automatically create climate baselines
34+
- Replace `dist_quantiles()` with `hardhat::quantile_pred()`
35+
- Allow `quantile()` to threshold to an interval if desired (#434)
3136

3237
## Bug fixes
3338

R/autoplot.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ plot_bands <- function(
243243
ntarget_dates <- dplyr::n_distinct(predictions$time_value)
244244

245245
predictions <- predictions %>%
246-
mutate(.pred_distn = dist_quantiles(quantile(.pred_distn, levels), levels)) %>%
246+
mutate(.pred_distn = quantile_pred(quantile(.pred_distn, levels), levels)) %>%
247247
pivot_quantiles_wider(.pred_distn)
248248
qnames <- setdiff(names(predictions), innames)
249249

R/climatological_forecaster.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ climatological_forecaster <- function(epi_data,
148148
.by = all_of(args_list$quantile_by_key)
149149
) %>%
150150
rename(.pred_distn = climate_pred) %>%
151-
mutate(.pred_distn = dist_quantiles(.pred_distn, args_list$quantile_levels))
151+
mutate(.pred_distn = hardhat::quantile_pred(do.call(rbind, .pred_distn), args_list$quantile_levels))
152152
# combine them together
153153
climate_table <- climate_center %>%
154154
left_join(climate_quantiles, by = c(".idx", args_list$quantile_by_key)) %>%

0 commit comments

Comments
 (0)