From 3867d5d2fba774ed1a193b26fcddadec5a91efa7 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 3 Jul 2023 12:47:20 +0100 Subject: [PATCH 1/4] shorten seeding time --- R/get.R | 10 ++++++++-- man/get_seeding_time.Rd | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/R/get.R b/R/get.R index bf233076c..e376b55e6 100644 --- a/R/get.R +++ b/R/get.R @@ -310,6 +310,11 @@ get_regions_with_most_reports <- function(reported_cases, ##' @param generation_time Generation time as specified using `dist_spec` ##' @return An integer seeding time ##' @author Sebastian Funk +##' @examples +##' gt1 <- dist_spec(mean = 5, sd = 1, max = 15) +##' gt2 <- dist_spec(mean = 10, sd = 2, max = 10) +##' delays <- dist_spec(mean = 5, sd = 1, max = 15) +##' get_seeding_time(delays, gt1 + gt2) get_seeding_time <- function(delays, generation_time) { # Estimate the mean delay ----------------------------------------------- seeding_time <- sum(mean(delays)) @@ -318,10 +323,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/man/get_seeding_time.Rd b/man/get_seeding_time.Rd index 77c7f51b6..53a9dca4f 100644 --- a/man/get_seeding_time.Rd +++ b/man/get_seeding_time.Rd @@ -18,6 +18,12 @@ An integer seeding time The seeding time is set to the mean of the specified delays, constrained to be at least the maximum generation time } +\examples{ +gt1 <- dist_spec(mean = 5, sd = 1, max = 15) +gt2 <- dist_spec(mean = 10, sd = 2, max = 10) +delays <- dist_spec(mean = 5, sd = 1, max = 15) +get_seeding_time(delays, gt1 + gt2) +} \author{ Sebastian Funk } From 1c3de1a820533980e3ed3345d206d7e411075861 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 3 Jul 2023 16:42:59 +0100 Subject: [PATCH 2/4] replace example with test --- R/get.R | 5 ----- man/get_seeding_time.Rd | 6 ------ tests/testthat/test-seeding-time.R | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 tests/testthat/test-seeding-time.R diff --git a/R/get.R b/R/get.R index e376b55e6..a13d08af3 100644 --- a/R/get.R +++ b/R/get.R @@ -310,11 +310,6 @@ get_regions_with_most_reports <- function(reported_cases, ##' @param generation_time Generation time as specified using `dist_spec` ##' @return An integer seeding time ##' @author Sebastian Funk -##' @examples -##' gt1 <- dist_spec(mean = 5, sd = 1, max = 15) -##' gt2 <- dist_spec(mean = 10, sd = 2, max = 10) -##' delays <- dist_spec(mean = 5, sd = 1, max = 15) -##' get_seeding_time(delays, gt1 + gt2) get_seeding_time <- function(delays, generation_time) { # Estimate the mean delay ----------------------------------------------- seeding_time <- sum(mean(delays)) diff --git a/man/get_seeding_time.Rd b/man/get_seeding_time.Rd index 53a9dca4f..77c7f51b6 100644 --- a/man/get_seeding_time.Rd +++ b/man/get_seeding_time.Rd @@ -18,12 +18,6 @@ An integer seeding time The seeding time is set to the mean of the specified delays, constrained to be at least the maximum generation time } -\examples{ -gt1 <- dist_spec(mean = 5, sd = 1, max = 15) -gt2 <- dist_spec(mean = 10, sd = 2, max = 10) -delays <- dist_spec(mean = 5, sd = 1, max = 15) -get_seeding_time(delays, gt1 + gt2) -} \author{ Sebastian Funk } 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) +}) From 897f4b1c4bc0d7565ffc51dcff65b95f32c18d9d Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Mon, 3 Jul 2023 20:50:11 +0100 Subject: [PATCH 3/4] add news item and bump version --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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..e9c29ee29 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 too long. By @sbfnk in #413 and reviewed by @seabbs. # EpiNow2 1.3.5 From 73c8187380108b83b27871a3526dc889aac1be0e Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Mon, 3 Jul 2023 21:55:57 +0200 Subject: [PATCH 4/4] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e9c29ee29..1b685f2ea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,7 +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 too long. By @sbfnk in #413 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