Skip to content

hardhat quantiles #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: epipredict
Title: Basic epidemiology forecasting methods
Version: 0.1.11
Version: 0.1.12
Authors@R: c(
person("Daniel J.", "McDonald", , "[email protected]", role = c("aut", "cre")),
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -30,13 +30,12 @@ Depends:
Imports:
checkmate,
cli,
distributional,
dplyr,
epiprocess (>= 0.10.4),
generics,
ggplot2,
glue,
hardhat (>= 1.3.0),
hardhat (>= 1.4.1),
lifecycle,
lubridate,
magrittr,
Expand Down Expand Up @@ -77,6 +76,5 @@ Remotes:
Config/Needs/website: cmu-delphi/delphidocs
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
51 changes: 20 additions & 31 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

S3method(Add_model,epi_workflow)
S3method(Add_model,workflow)
S3method(Math,dist_quantiles)
S3method(Ops,dist_quantiles)
S3method(Remove_model,epi_workflow)
S3method(Remove_model,workflow)
S3method(Update_model,epi_workflow)
Expand Down Expand Up @@ -41,20 +39,14 @@ S3method(extract_frosting,default)
S3method(extract_frosting,epi_workflow)
S3method(extract_layers,frosting)
S3method(extract_layers,workflow)
S3method(extrapolate_quantiles,dist_default)
S3method(extrapolate_quantiles,dist_quantiles)
S3method(extrapolate_quantiles,distribution)
S3method(extrapolate_quantiles,quantile_pred)
S3method(fit,epi_workflow)
S3method(flusight_hub_formatter,canned_epipred)
S3method(flusight_hub_formatter,data.frame)
S3method(forecast,epi_workflow)
S3method(format,dist_quantiles)
S3method(is.na,dist_quantiles)
S3method(is.na,distribution)
S3method(key_colnames,epi_workflow)
S3method(key_colnames,recipe)
S3method(mean,dist_quantiles)
S3method(median,dist_quantiles)
S3method(mean,quantile_pred)
S3method(predict,epi_workflow)
S3method(predict,flatline)
S3method(prep,check_enough_train_data)
Expand Down Expand Up @@ -86,7 +78,6 @@ S3method(print,layer_naomit)
S3method(print,layer_point_from_distn)
S3method(print,layer_population_scaling)
S3method(print,layer_predict)
S3method(print,layer_predictive_distn)
S3method(print,layer_quantile_distn)
S3method(print,layer_residual_quantiles)
S3method(print,layer_threshold)
Expand All @@ -101,7 +92,7 @@ S3method(print,step_lag_difference)
S3method(print,step_naomit)
S3method(print,step_population_scaling)
S3method(print,step_training_window)
S3method(quantile,dist_quantiles)
S3method(quantile,quantile_pred)
S3method(refresh_blueprint,default_epi_recipe_blueprint)
S3method(residuals,flatline)
S3method(run_mold,default_epi_recipe_blueprint)
Expand All @@ -112,25 +103,22 @@ S3method(slather,layer_naomit)
S3method(slather,layer_point_from_distn)
S3method(slather,layer_population_scaling)
S3method(slather,layer_predict)
S3method(slather,layer_predictive_distn)
S3method(slather,layer_quantile_distn)
S3method(slather,layer_residual_quantiles)
S3method(slather,layer_threshold)
S3method(slather,layer_unnest)
S3method(snap,default)
S3method(snap,dist_default)
S3method(snap,dist_quantiles)
S3method(snap,distribution)
S3method(snap,quantile_pred)
S3method(tidy,check_enough_train_data)
S3method(tidy,frosting)
S3method(tidy,layer)
S3method(update,layer)
S3method(vec_ptype_abbr,dist_quantiles)
S3method(vec_ptype_full,dist_quantiles)
S3method(weighted_interval_score,default)
S3method(weighted_interval_score,dist_default)
S3method(weighted_interval_score,dist_quantiles)
S3method(weighted_interval_score,distribution)
S3method(vec_arith,quantile_pred)
S3method(vec_arith.numeric,quantile_pred)
S3method(vec_arith.quantile_pred,numeric)
S3method(vec_math,quantile_pred)
S3method(vec_proxy_equal,quantile_pred)
S3method(weighted_interval_score,quantile_pred)
export("%>%")
export(Add_model)
export(Remove_model)
Expand Down Expand Up @@ -167,6 +155,7 @@ export(epi_workflow)
export(extract_argument)
export(extract_frosting)
export(extract_layers)
export(extract_quantile_levels)
export(extrapolate_quantiles)
export(filter)
export(fit)
Expand Down Expand Up @@ -203,6 +192,7 @@ export(pivot_quantiles_longer)
export(pivot_quantiles_wider)
export(pivot_wider)
export(prep)
export(quantile_pred)
export(quantile_reg)
export(rand_id)
export(remove_epi_recipe)
Expand All @@ -212,6 +202,7 @@ export(rename)
export(select)
export(slather)
export(smooth_quantile_reg)
export(snap)
export(step_adjust_latency)
export(step_climate)
export(step_epi_ahead)
Expand All @@ -230,7 +221,6 @@ export(update_frosting)
export(update_model)
export(validate_layer)
export(weighted_interval_score)
import(distributional)
import(epidatasets)
import(epiprocess)
import(parsnip)
Expand Down Expand Up @@ -290,9 +280,12 @@ importFrom(ggplot2,geom_linerange)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_ribbon)
importFrom(glue,glue)
importFrom(hardhat,extract_quantile_levels)
importFrom(hardhat,extract_recipe)
importFrom(hardhat,quantile_pred)
importFrom(hardhat,refresh_blueprint)
importFrom(hardhat,run_mold)
importFrom(lifecycle,deprecated)
importFrom(lubridate,"%m-%")
importFrom(lubridate,leap_year)
importFrom(lubridate,month)
Expand Down Expand Up @@ -325,14 +318,11 @@ importFrom(rlang,list2)
importFrom(rlang,set_names)
importFrom(rlang,sym)
importFrom(stats,as.formula)
importFrom(stats,family)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,model.frame)
importFrom(stats,na.omit)
importFrom(stats,poly)
importFrom(stats,predict)
importFrom(stats,qnorm)
importFrom(stats,quantile)
importFrom(stats,residuals)
importFrom(tibble,as_tibble)
Expand All @@ -347,12 +337,11 @@ importFrom(tidyr,unnest)
importFrom(tidyselect,all_of)
importFrom(utils,capture.output)
importFrom(vctrs,as_list_of)
importFrom(vctrs,field)
importFrom(vctrs,new_rcrd)
importFrom(vctrs,new_vctr)
importFrom(vctrs,vec_arith)
importFrom(vctrs,vec_arith.numeric)
importFrom(vctrs,vec_cast)
importFrom(vctrs,vec_data)
importFrom(vctrs,vec_ptype_abbr)
importFrom(vctrs,vec_ptype_full)
importFrom(vctrs,vec_math)
importFrom(vctrs,vec_proxy_equal)
importFrom(vctrs,vec_recycle_common)
importFrom(workflows,extract_preprocessor)
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
has an `na_rm` argument.
- Moves `epiprocess` out of depends (#440). No internals have changed, but downstream
users may need to add `library(epiprocess)` to existing code.
- Removes dependence on the `distributional` package, replacing the quantiles
with `hardhat::quantile_pred()`. Some associated functions are deprecated with
`lifecycle` messages.

## Improvements

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

## Bug fixes

Expand Down
2 changes: 1 addition & 1 deletion R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ plot_bands <- function(
ntarget_dates <- dplyr::n_distinct(predictions$time_value)

predictions <- predictions %>%
mutate(.pred_distn = dist_quantiles(quantile(.pred_distn, levels), levels)) %>%
mutate(.pred_distn = quantile_pred(quantile(.pred_distn, levels), levels)) %>%
pivot_quantiles_wider(.pred_distn)
qnames <- setdiff(names(predictions), innames)

Expand Down
2 changes: 1 addition & 1 deletion R/climatological_forecaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ climatological_forecaster <- function(epi_data,
.by = all_of(args_list$quantile_by_key)
) %>%
rename(.pred_distn = climate_pred) %>%
mutate(.pred_distn = dist_quantiles(.pred_distn, args_list$quantile_levels))
mutate(.pred_distn = hardhat::quantile_pred(do.call(rbind, .pred_distn), args_list$quantile_levels))
# combine them together
climate_table <- climate_center %>%
left_join(climate_quantiles, by = c(".idx", args_list$quantile_by_key)) %>%
Expand Down
Loading