Skip to content

Climatological #436

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 60 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
463734c
add lubridate
dajmcdon Dec 3, 2024
a64b6db
style on short line
dajmcdon Dec 3, 2024
3f2c1c1
add a hidden column to track the time_value of the outcome
dajmcdon Dec 3, 2024
4af6a8a
typo in documentation and error msg
dajmcdon Dec 3, 2024
301e651
adding predictor drafted
dajmcdon Dec 3, 2024
6cb7897
remove ability for `...` to be empty in adjust_latency
dajmcdon Dec 3, 2024
426f0c7
add/remove hidden target_time_value column
dajmcdon Dec 3, 2024
fef636c
finish climate predictor draft
dajmcdon Dec 3, 2024
3c2c9b7
redocument
dajmcdon Dec 3, 2024
031b605
update rproj
dajmcdon Jan 17, 2025
c598840
drafted, needs refactor
dajmcdon Jan 17, 2025
83e3f8e
Merge branch 'dev' into climatological
dajmcdon Jan 31, 2025
26461c8
revert addition of hidden .target_time_value
dajmcdon Feb 4, 2025
a66d07f
climate prep/bake steps work as planned. does not adjust for aheads
dajmcdon Feb 4, 2025
10cd85f
tests pass
dajmcdon Feb 4, 2025
cd18833
rename objects
dajmcdon Feb 5, 2025
bcbda6d
climate predictor works as desired
dajmcdon Feb 6, 2025
2fabf45
rename test
dajmcdon Feb 6, 2025
ced85b4
more detailed documentation
dajmcdon Feb 6, 2025
01182d7
add another example
dajmcdon Feb 6, 2025
83a6ec8
use all_of in tidyselect
dajmcdon Feb 7, 2025
3d3c2b4
simplify docs, quantiles
dajmcdon Feb 8, 2025
950f363
merge dev
dajmcdon Feb 10, 2025
dab8d43
merge dev epi_recipe
dajmcdon Feb 10, 2025
d6725a8
refactor the forecaster
dajmcdon Feb 10, 2025
0be6acf
missing autoplot branch
dajmcdon Feb 10, 2025
d464c19
test args list
dajmcdon Feb 11, 2025
7afbde8
add reasonable examples
dajmcdon Feb 11, 2025
151d8ea
tests pass
dajmcdon Feb 11, 2025
381a298
add snapshot tests
dajmcdon Feb 11, 2025
83e0ad7
redocument, add news
dajmcdon Feb 11, 2025
d56d488
prefix with recipes, aside to rename object
dajmcdon Feb 11, 2025
c1cf5ba
muffle dplyr select warnings
dajmcdon Feb 11, 2025
4a348c8
shifting must happen before joining to avoid duplicated rows
dajmcdon Feb 11, 2025
46b2a2e
ignore renviron
dajmcdon Feb 11, 2025
5f76be3
months is in base, so we ensure we use lubridate
dajmcdon Feb 11, 2025
77dbcc4
rebuild readme
dajmcdon Feb 11, 2025
c98b47c
satisfy styler
dajmcdon Feb 11, 2025
48ea5ca
add a print method
dajmcdon Feb 12, 2025
7089c2f
David's suggestions
dsweber2 Feb 12, 2025
60d6aeb
time_type defaulting to the epi_df's time_type
dsweber2 Feb 13, 2025
759a3b8
unneeded else branch
dsweber2 Feb 14, 2025
4477403
Merge pull request #441 from cmu-delphi/climate_suggestions
dsweber2 Feb 14, 2025
d072839
Merge branch 'dev' into climatological
dajmcdon Feb 15, 2025
5d062db
fu styler!!
dajmcdon Feb 16, 2025
21c67cd
deletion from news
dajmcdon Feb 16, 2025
05f0490
redocument, update snapshots
dajmcdon Feb 16, 2025
cfad1f1
update snaps for upstream package
dajmcdon Feb 16, 2025
bece1fe
compute the .pred_distn using residuals. document the default
dajmcdon Feb 19, 2025
5e3ed56
fix rlang bug, more detailed examples
dajmcdon Feb 19, 2025
8238703
pass checks
dajmcdon Feb 19, 2025
08fcd01
once more, FU styler
dajmcdon Feb 19, 2025
a5dea72
step_climate leap weeks/days
dsweber2 Feb 27, 2025
b3db007
same for climatological_forecaster
dsweber2 Feb 27, 2025
fda832f
feb 29 is day 60, so the boundary is 59-60
dsweber2 Feb 27, 2025
49882f2
Dan's feedback, < a full year, test monthly agg
dsweber2 Mar 3, 2025
6424f39
pipe R dependency
dsweber2 Mar 5, 2025
7c9d1c6
-1 -> 999
dsweber2 Mar 5, 2025
7e10b52
Merge pull request #445 from cmu-delphi/leap_time_handling
dsweber2 Mar 11, 2025
03d50b2
version bump, minor doc update
dsweber2 Mar 11, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ inst/doc
.Rprofile
renv.lock
renv/
.Renviron
4 changes: 2 additions & 2 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.10
Version: 0.1.11
Authors@R: c(
person("Daniel J.", "McDonald", , "[email protected]", role = c("aut", "cre")),
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),
Expand Down Expand Up @@ -38,6 +38,7 @@ Imports:
glue,
hardhat (>= 1.3.0),
lifecycle,
lubridate,
magrittr,
recipes (>= 1.0.4),
rlang (>= 1.1.0),
Expand All @@ -54,7 +55,6 @@ Suggests:
fs,
grf,
knitr,
lubridate,
poissonreg,
purrr,
quantreg,
Expand Down
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ S3method(autoplot,epi_workflow)
S3method(bake,check_enough_train_data)
S3method(bake,epi_recipe)
S3method(bake,step_adjust_latency)
S3method(bake,step_climate)
S3method(bake,step_epi_ahead)
S3method(bake,step_epi_lag)
S3method(bake,step_epi_slide)
Expand Down Expand Up @@ -59,6 +60,7 @@ S3method(predict,flatline)
S3method(prep,check_enough_train_data)
S3method(prep,epi_recipe)
S3method(prep,step_adjust_latency)
S3method(prep,step_climate)
S3method(prep,step_epi_ahead)
S3method(prep,step_epi_lag)
S3method(prep,step_epi_slide)
Expand All @@ -72,6 +74,7 @@ S3method(print,arx_fcast)
S3method(print,canned_epipred)
S3method(print,cdc_baseline_fcast)
S3method(print,check_enough_train_data)
S3method(print,climate_fcast)
S3method(print,epi_recipe)
S3method(print,epi_workflow)
S3method(print,flat_fcast)
Expand All @@ -89,6 +92,7 @@ S3method(print,layer_residual_quantiles)
S3method(print,layer_threshold)
S3method(print,layer_unnest)
S3method(print,step_adjust_latency)
S3method(print,step_climate)
S3method(print,step_epi_ahead)
S3method(print,step_epi_lag)
S3method(print,step_epi_slide)
Expand Down Expand Up @@ -150,6 +154,8 @@ export(cdc_baseline_args_list)
export(cdc_baseline_forecaster)
export(check_enough_train_data)
export(clean_f_name)
export(climate_args_list)
export(climatological_forecaster)
export(default_epi_recipe_blueprint)
export(detect_layer)
export(dist_quantiles)
Expand Down Expand Up @@ -198,6 +204,7 @@ export(remove_model)
export(slather)
export(smooth_quantile_reg)
export(step_adjust_latency)
export(step_climate)
export(step_epi_ahead)
export(step_epi_lag)
export(step_epi_naomit)
Expand Down Expand Up @@ -272,6 +279,10 @@ importFrom(glue,glue)
importFrom(hardhat,extract_recipe)
importFrom(hardhat,refresh_blueprint)
importFrom(hardhat,run_mold)
importFrom(lubridate,"%m-%")
importFrom(lubridate,leap_year)
importFrom(lubridate,month)
importFrom(lubridate,yday)
importFrom(magrittr,"%>%")
importFrom(magrittr,extract2)
importFrom(recipes,bake)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
`data(<dataset name>)`, but can be accessed with
`data(<dataset name>, package = "epidatasets")`, `epidatasets::<dataset name>`
or, after loading the package, the name of the dataset alone (#382).
- `step_adjust_latency()` no longer allows empty column selection.
- Addresses upstream breaking changes from cmu-delphi/epiprocess#595 (`growth_rate()`).
`step_growth_rate()` has lost its `additional_gr_args_list` argument and now
has an `na_rm` argument.
Expand All @@ -23,8 +24,11 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
- Fix `quantile_reg()` producing error when asked to output just median-level predictions.
- (temporary) ahead negative is allowed for `step_epi_ahead` until we have `step_epi_shift`
- 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

## Bug fixes

- Shifting no columns results in no error for either `step_epi_ahead` and `step_epi_lag`
- Quantiles produced by `grf` were sometimes out of order.
- dist_quantiles can have all `NA` values without causing unrelated errors
Expand Down
3 changes: 2 additions & 1 deletion R/arx_forecaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ arx_forecaster <- function(
#'
#' @return An unfitted `epi_workflow`.
#' @export
#' @seealso [arx_forecaster()]
#' @seealso [arx_forecaster()], [arx_args_list()]
#'
#' @examples
#' library(dplyr)
Expand Down Expand Up @@ -283,6 +283,7 @@ arx_fcast_epi_workflow <- function(
#'
#' @return A list containing updated parameter choices with class `arx_flist`.
#' @export
#' @seealso [arx_forecaster()]
#'
#' @examples
#' arx_args_list()
Expand Down
9 changes: 5 additions & 4 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ autoplot.epi_workflow <- function(
shift <- -as.numeric(old_name_y[2])
new_name_y <- paste(old_name_y[-c(1:2)], collapse = "_")
edf <- rename(edf, !!new_name_y := !!names(y))
} else {
new_name_y <- names(y)
shift <- 0
}

if (!is.null(shift)) {
edf <- mutate(edf, time_value = time_value + shift)
}
other_keys <- setdiff(key_colnames(object), c("geo_value", "time_value"))
edf <- mutate(edf, time_value = time_value + shift)
other_keys <- key_colnames(object, exclude = c("geo_value", "time_value"))
edf <- as_epi_df(edf,
as_of = object$fit$meta$as_of,
other_keys = other_keys
Expand Down
62 changes: 32 additions & 30 deletions R/canned-epipred.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,39 @@ print.canned_epipred <- function(x, name, ...) {
"At forecast date{?s}: {.val {fds}},",
"For target date{?s}: {.val {tds}},"
))
fit_recipe <- extract_recipe(x$epi_workflow)
if (detect_step(fit_recipe, "adjust_latency")) {
is_adj_latency <- map_lgl(fit_recipe$steps, function(x) inherits(x, "step_adjust_latency"))
latency_step <- fit_recipe$steps[is_adj_latency][[1]]
# all steps after adjust_latency
later_steps <- fit_recipe$steps[-(1:which(is_adj_latency))]
if (latency_step$method == "extend_ahead") {
step_names <- "step_epi_ahead"
type_str <- "Aheads"
} else if (latency_step$method == "extend_lags") {
step_names <- "step_epi_lag"
type_str <- "Lags"
} else {
step_names <- ""
type_str <- "columns locf"
}
later_steps[[1]]$columns
valid_columns <- later_steps %>%
keep(function(x) inherits(x, step_names)) %>%
purrr::map("columns") %>%
reduce(c)
latency_per_base_col <- latency_step$latency_table %>%
filter(col_name %in% valid_columns) %>%
mutate(latency = abs(latency))
if (latency_step$method != "locf" && nrow(latency_per_base_col) > 1) {
intro_text <- glue::glue("{type_str} adjusted per column: ")
} else if (latency_step$method != "locf") {
intro_text <- glue::glue("{type_str} adjusted for ")
if ("actions" %in% names(x$pre) && "recipe" %in% names(x$pre$actions)) {
fit_recipe <- extract_recipe(x$epi_workflow)
if (detect_step(fit_recipe, "adjust_latency")) {
is_adj_latency <- map_lgl(fit_recipe$steps, function(x) inherits(x, "step_adjust_latency"))
latency_step <- fit_recipe$steps[is_adj_latency][[1]]
# all steps after adjust_latency
later_steps <- fit_recipe$steps[-(1:which(is_adj_latency))]
if (latency_step$method == "extend_ahead") {
step_names <- "step_epi_ahead"
type_str <- "Aheads"
} else if (latency_step$method == "extend_lags") {
step_names <- "step_epi_lag"
type_str <- "Lags"
} else {
step_names <- ""
type_str <- "columns locf"
}
later_steps[[1]]$columns
valid_columns <- later_steps %>%
keep(function(x) inherits(x, step_names)) %>%
purrr::map("columns") %>%
reduce(c)
latency_per_base_col <- latency_step$latency_table %>%
filter(col_name %in% valid_columns) %>%
mutate(latency = abs(latency))
if (latency_step$method != "locf" && nrow(latency_per_base_col) > 1) {
intro_text <- glue::glue("{type_str} adjusted per column: ")
} else if (latency_step$method != "locf") {
intro_text <- glue::glue("{type_str} adjusted for ")
}
latency_info <- paste0(intro_text, paste(apply(latency_per_base_col, 1, paste0, collapse = "="), collapse = ", "))
cli::cli_ul(latency_info)
}
latency_info <- paste0(intro_text, paste(apply(latency_per_base_col, 1, paste0, collapse = "="), collapse = ", "))
cli::cli_ul(latency_info)
}
cli::cli_text("")
}
Loading