-
Notifications
You must be signed in to change notification settings - Fork 0
testing forecasters on simple datasets #32
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
452d6cd
feat: check for sufficient training data
dsweber2 a8119a7
test: generic forecaster data tests
dsweber2 fad5be8
fix: confirm_insufficient data moved earlier
dsweber2 f641b29
lint: whitespace
dsweber2 4323e12
tests: too stringent with `tiny_sd`, increased tol
dsweber2 5801e39
fix: need the content of `outcome` not the name
dsweber2 4c9bdec
docs: forgot to run
dsweber2 9767d90
docs: doc all the params
dsweber2 9d27064
feat+test: make a functional flatline forecaster
dsweber2 b60b500
style: rename poorly named test files
dsweber2 f4ceaa6
fix: cleaning random cruft
dsweber2 bab8d66
fix: substantive suggestions
dsweber2 29528ae
fix: namespace and docs
dsweber2 b2fd743
fix: level,tau->quantile_level
dsweber2 15caf84
fix: unused test value
dsweber2 f7d8318
style: run styler on this
dsweber2 cc0c955
tests: document the tests a little better
dsweber2 0481615
test: forecaster_testing not in targets
dsweber2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
^renv$ | ||
^renv\.lock$ | ||
^LICENSE\.md$ | ||
^.lintr$ | ||
^.renvignore$ | ||
^.github$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' flatline forecaster (aka baseline) | ||
#' @description | ||
#' a minimal forecaster whose median is just the last value | ||
#' does not support `lags` as a parameter, but otherwise has the same parameters as `arx_forecaster` | ||
#' @inheritParams scaled_pop | ||
#' @importFrom rlang sym | ||
#' @export | ||
flatline_fc <- function(epi_data, | ||
outcome, | ||
extra_sources = "", | ||
ahead = 1, | ||
trainer = parsnip::linear_reg(), | ||
quantile_levels = covidhub_probs(), | ||
...) { | ||
# perform any preprocessing not supported by epipredict | ||
# one that every forecaster will need to handle: how to manage max(time_value) | ||
# that's older than the `as_of` date | ||
epidataAhead <- extend_ahead(epi_data, ahead) | ||
# see latency_adjusting for other examples | ||
# this next part is basically unavoidable boilerplate you'll want to copy | ||
epi_data <- epidataAhead[[1]] | ||
effective_ahead <- epidataAhead[[2]] | ||
args_input <- list(...) | ||
# edge case where there is no data or less data than the lags; eventually epipredict will handle this | ||
if (confirm_insufficient_data(epi_data, effective_ahead, args_input)) { | ||
null_result <- tibble( | ||
geo_value = character(), | ||
forecast_date = Date(), | ||
target_end_date = Date(), | ||
quantile = numeric(), | ||
value = numeric() | ||
) | ||
return(null_result) | ||
} | ||
args_input[["ahead"]] <- effective_ahead | ||
args_input[["quantile_levels"]] <- quantile_levels | ||
args_list <- do.call(flatline_args_list, args_input) | ||
# if you want to ignore extra_sources, setting predictors is the way to do it | ||
predictors <- c(outcome, extra_sources) | ||
argsPredictorsTrainer <- perform_sanity_checks(epi_data, outcome, predictors, NULL, args_list) | ||
args_list <- argsPredictorsTrainer[[1]] | ||
predictors <- argsPredictorsTrainer[[2]] | ||
# end of the copypasta | ||
# finally, any other pre-processing (e.g. smoothing) that isn't performed by | ||
# epipredict | ||
|
||
# since this is just the flatline, we don't need much of anything | ||
res <- flatline_forecaster(epi_data, outcome = outcome, args_list = args_list) | ||
true_forecast_date <- attributes(epi_data)$metadata$as_of | ||
pred <- format_storage(res$predictions, true_forecast_date) | ||
# (geo_value, forecast_date, target_end_date, quantile, value) | ||
# finally, any postprocessing not supported by epipredict e.g. calibration | ||
return(pred) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.