-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add check and warning for PMFs longer than the data #998
base: main
Are you sure you want to change the base?
Changes from all commits
ce419de
100e141
c5f6152
4530762
2ef6f3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ | |
} | ||
assert_numeric(attr(dist, "cdf_cutoff"), lower = 0, upper = 1) | ||
# Check that `dist` has a finite maximum | ||
if (any(is.infinite(max(dist))) && !(attr(dist, "cdf_cutoff") > 0)) { | ||
cli_abort( | ||
c( | ||
"i" = "All distributions passed to the model need to have a | ||
|
@@ -180,3 +180,54 @@ | |
) | ||
} | ||
} | ||
|
||
|
||
#' Check that supplied PMFs are not longer than the data | ||
#' | ||
#' @param ... Delay distributions | ||
#' @inheritParams estimate_infections | ||
#' @importFrom cli cli_warn col_red | ||
#' | ||
#' @returns Called for its side effects | ||
#' @keywords internal | ||
check_pmf_length_against_data <- function(..., data) { | ||
delays <- list(...) | ||
flat_delays <- do.call(c, delays) | ||
# Track which component each delay came from | ||
delay_names <- rep(names(delays), vapply(delays, EpiNow2:::ndist, numeric(1))) | ||
Check warning on line 197 in R/checks.R
|
||
names(flat_delays) <- delay_names | ||
# Find the non-parametric distributions | ||
np_delays <- which(unname(vapply( | ||
flat_delays, function(x) { | ||
get_distribution(x) == "nonparametric" | ||
}, logical(1) | ||
))) | ||
|
||
if (length(np_delays) == 0) return(invisible()) | ||
|
||
# Check lengths and collect info about exceeding PMFs | ||
pmf_longer_than_data <- vapply(flat_delays[np_delays], function(x) { | ||
length(x$pmf) > nrow(data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't we need to also check if the total reporting delay is longer than the data or the case where two distributions are passed to the generation time (not sure this is something you can actually do?) |
||
}, logical(1)) | ||
|
||
if (any(pmf_longer_than_data)) { | ||
# Get details for each long PMF | ||
long_pmf_lengths <- vapply( | ||
flat_delays[np_delays][pmf_longer_than_data], function(x) { | ||
length(x$pmf) | ||
}, numeric(1) | ||
) | ||
} | ||
|
||
cli::cli_warn( | ||
c( | ||
"!" = "You have supplied PMFs that are longer than the data. ", | ||
"{names(long_pmf_lengths)} {?has/have} length{?s} | ||
{.val {long_pmf_lengths}} but data has | ||
{.val {nrow(data)}} rows.", | ||
"i" = "{cli::col_red('These will be trimmed to match the rows in the | ||
data. To remove this message, make sure the PMFs have the same length | ||
as the data')}" | ||
) | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you dont need ::: for internal functions. This is throwing a valid linting issue