Skip to content
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

shorten seeding time #413

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions R/get.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
14 changes: 14 additions & 0 deletions tests/testthat/test-seeding-time.R
Original file line number Diff line number Diff line change
@@ -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)
})