Skip to content

Directly calculated growth #610

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

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test for exp(r)==R with fixed gt of 1 day
  • Loading branch information
sbfnk committed Mar 18, 2024
commit 7103a39cd042eb3fbeba28fb94d309c21bc926a9
22 changes: 20 additions & 2 deletions tests/testthat/test-estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ futile.logger::flog.threshold("FATAL")

reported_cases <- EpiNow2::example_confirmed[1:30]

default_estimate_infections <- function(..., add_stan = list(), delay = TRUE) {
default_estimate_infections <- function(..., add_stan = list(), gt = TRUE,
delay = TRUE) {
futile.logger::flog.threshold("FATAL")

def_stan <- list(
Expand All @@ -15,7 +16,9 @@ default_estimate_infections <- function(..., add_stan = list(), delay = TRUE) {
stan_args <- do.call(stan_opts, def_stan)

suppressWarnings(estimate_infections(...,
generation_time = generation_time_opts(example_generation_time),
generation_time = fifelse(
gt, generation_time_opts(example_generation_time), generation_time_opts()
),
delays = ifelse(delay, list(delay_opts(example_reporting_delay)), list(delay_opts()))[[1]],
stan = stan_args, verbose = FALSE
))
Expand All @@ -27,6 +30,7 @@ test_estimate_infections <- function(...) {
expect_true(nrow(out$samples) > 0)
expect_true(nrow(out$summarised) > 0)
expect_true(nrow(out$observations) > 0)
invisible(out)
}

# Test functionality ------------------------------------------------------
Expand Down Expand Up @@ -89,6 +93,20 @@ test_that("estimate_infections successfully returns estimates using a random wal
test_estimate_infections(reported_cases, gp = NULL, rt = rt_opts(rw = 7))
})

test_that("estimate_infections works without setting a generation time", {
skip_on_cran()
df <- test_estimate_infections(reported_cases, gt = FALSE, delay = FALSE)
## check exp(r) == R
growth_rate <- df$samples[variable == "growth_rate"][,
list(date, sample, growth_rate = value)
]
R <- df$samples[variable == "R"][,
list(date, sample, R = value)
]
combined <- merge(growth_rate, R, by = c("date", "sample"), all = FALSE)
expect_equal(exp(combined$growth_rate), combined$R)
})

test_that("estimate_infections fails as expected when given a very short timeout", {
skip_on_cran()
expect_error(output <- capture.output(suppressMessages(
Expand Down
Loading