From b09c702b838dc8bda5e69d86d98f66dda7541193 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 3 Jul 2023 14:56:45 -0500 Subject: [PATCH] shorten seeding time (#413) * shorten seeding time * replace example with test * add news item and bump version * Update NEWS.md --------- Co-authored-by: Sam Abbott --- DESCRIPTION | 2 +- NEWS.md | 1 + R/get.R | 5 +++-- tests/testthat/test-seeding-time.R | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/testthat/test-seeding-time.R diff --git a/DESCRIPTION b/DESCRIPTION index de3af42a1..cf9dcddf0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: EpiNow2 Title: Estimate Real-Time Case Counts and Time-Varying Epidemiological Parameters -Version: 1.3.6.7000 +Version: 1.3.6.8000 Authors@R: c(person(given = "Sam", family = "Abbott", diff --git a/NEWS.md b/NEWS.md index b428f3b2e..1b685f2ea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ This release is in development. For a stable release install 1.3.5 from CRAN. * [pak](https://pak.r-lib.org/) is now suggested for installing the developmental version of the package. By @jamesmbaazam in #407 and reviewed by @seabbs. This has been successfully tested on MacOS Ventura, Ubuntu 20.04, and Windows 10. Users are advised to use `remotes::install_github("epiforecasts/EpiNow2")` if `pak` fails and if both fail, raise an issue. * `dist_fit()`'s `samples` argument now takes a default value of 1000 instead of NULL. If a supplied `samples` is less than 1000, it is changed to 1000 and a warning is thrown to indicate the change. By @jamesmbazam in #389 and reviewed by @seabbs. * The internal distribution interface has been streamlined to reduce code duplication. By @sbfnk in #363 and reviewed by @seabbs. +* A small bug has been fixed where the seeding time was one day too long. By @sbfnk in #413 and reviewed by @seabbs. # EpiNow2 1.3.5 diff --git a/R/get.R b/R/get.R index bf233076c..a13d08af3 100644 --- a/R/get.R +++ b/R/get.R @@ -318,10 +318,11 @@ get_seeding_time <- function(delays, generation_time) { } else { seeding_time <- as.integer(seeding_time) } - ## make sure we have at least gt_max seeding time + ## make sure we have at least (length of total gt pmf - 1) seeding time seeding_time <- max( seeding_time, - sum(generation_time$max) + sum(generation_time$np_pmf_max) + sum(generation_time$max) + sum(generation_time$np_pmf_max) - + length(generation_time$max) - length(generation_time$np_pmf_max) ) return(seeding_time) } diff --git a/tests/testthat/test-seeding-time.R b/tests/testthat/test-seeding-time.R new file mode 100644 index 000000000..5fe43a1d7 --- /dev/null +++ b/tests/testthat/test-seeding-time.R @@ -0,0 +1,14 @@ +test_that("Seeding times are correctly calculated", { + gt1 <- dist_spec(mean = 5, sd = 1, max = 10) + gt2 <- dist_spec(mean = 10, sd = 2, max = 15) + delay1 <- dist_spec(mean = 5, sd = 1, max = 10) + delay2 <- dist_spec(mean = 7, sd = 3, max = 15) + expect_equal(get_seeding_time(delay1, gt1 + gt2), 23L) ## 10 + 15 - 1 - 1 + expect_equal(get_seeding_time(delay1 + delay2, gt1), 12L) ## 5 + 7 +}) + +test_that("Short seeding times are rounded up to 1", { + delay <- dist_spec(mean = 0.5, sd = 1, max = 2) + gt <- dist_spec(mean = 1) + expect_equal(get_seeding_time(delay, gt), 1L) +})