Skip to content

Commit

Permalink
Truncate PMFs longer than the data
Browse files Browse the repository at this point in the history
To the length of the data and throw a warning rather than an error.
This change allows us to run on old right-truncation estimates.
  • Loading branch information
zsusswein committed Oct 2, 2024
1 parent 0e65fb2 commit 7f0a180
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions R/fit_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,24 @@ format_right_truncation <- function(pmf, data) {
# silently removed if length of the PMF was longer than the data,
# effectively eliminating the right-truncation correction

cli::cli_abort(
trunc_idx <- nrow(data) - 1
cli::cli_warn(
c(
"Removing right-truncation PMF elements after {.val {trunc_idx}}",
"Right truncation PMF longer than the data",
"PMF length: {.val {length(pmf)}}",
"Data length: {.val {nrow(data)}}",
"PMF can only be up to length as the data"
"PMF can only be up to the length of the data"
),
class = "right_trunc_too_long"
)
suppressWarnings({
EpiNow2::trunc_opts(
dist = EpiNow2::dist_spec(
pmf = pmf[seq_len(trunc_idx)]
)
)
})
} else {
suppressWarnings({
EpiNow2::trunc_opts(
Expand Down

0 comments on commit 7f0a180

Please sign in to comment.