diff --git a/R/simulate_infections.R b/R/simulate_infections.R index f3b66cc3f..57ad2f0fa 100644 --- a/R/simulate_infections.R +++ b/R/simulate_infections.R @@ -69,7 +69,7 @@ simulate_infections <- function(estimates, R, initial_infections, CrIs = c(0.2, 0.5, 0.9), backend = "rstan", seeding_time = NULL, - pop = 0, ...) { + pop = Fixed(0), ...) { ## deprecated usage if (!missing(estimates)) { deprecate_stop( @@ -125,7 +125,7 @@ simulate_infections <- function(estimates, R, initial_infections, initial_infections = array(log_initial_infections, dim = c(1, 1)), initial_growth = array(initial_growth, dim = c(1, length(initial_growth))), R = array(R$R, dim = c(1, nrow(R))), - pop = pop + use_pop = as.integer(pop != Fixed(0)) ) data <- c(data, create_stan_delays( diff --git a/inst/stan/data/rt.stan b/inst/stan/data/rt.stan index 07dadc036..541187522 100644 --- a/inst/stan/data/rt.stan +++ b/inst/stan/data/rt.stan @@ -6,4 +6,4 @@ int future_fixed; // is underlying future Rt assumed to be fixed int fixed_from; // Reference date for when Rt estimation should be fixed int use_pop; // use population size - int gt_id; // id of generation time \ No newline at end of file + int gt_id; // id of generation time diff --git a/inst/stan/data/simulation_rt.stan b/inst/stan/data/simulation_rt.stan index 3beae3161..fdae11e2a 100644 --- a/inst/stan/data/simulation_rt.stan +++ b/inst/stan/data/simulation_rt.stan @@ -2,6 +2,6 @@ array[n, seeding_time > 1 ? 1 : 0] real initial_growth; //initial growth matrix[n, t - seeding_time] R; // reproduction number - int pop; // susceptible population + int use_pop; // use population size int gt_id; // id of generation time diff --git a/inst/stan/simulate_infections.stan b/inst/stan/simulate_infections.stan index b3cd57985..29513195a 100644 --- a/inst/stan/simulate_infections.stan +++ b/inst/stan/simulate_infections.stan @@ -51,7 +51,7 @@ generated quantities { params_value, params ); - real pop = get_param( + vector[n] pop = get_param( pop_id, params_fixed_lookup, params_variable_lookup, params_value, params ); @@ -68,7 +68,7 @@ generated quantities { infections[i] = to_row_vector(generate_infections( to_vector(R[i]), seeding_time, gt_rev_pmf, initial_infections[i], - initial_growth[i], pop, use_pop, future_time + initial_growth[i], pop[i], use_pop, future_time )); if (delay_id) { diff --git a/man/EpiNow2-package.Rd b/man/EpiNow2-package.Rd index b0c820c1b..5e27df68a 100644 --- a/man/EpiNow2-package.Rd +++ b/man/EpiNow2-package.Rd @@ -43,7 +43,7 @@ Other contributors: \item Paul Mee \email{paul.mee@lshtm.ac.uk} [contributor] \item Peter Ellis \email{peter.ellis2013nz@gmail.com} [contributor] \item Pietro Monticone \email{pietro.monticone@edu.unito.it} [contributor] - \item Lloyd Chapman \email{lloyd.chapman1@lshtm.ac.uk} [contributor] + \item Lloyd Chapman \email{lloyd.chapman1@lshtm.ac.uk } [contributor] \item Andrew Johnson \email{andrew.johnson@arjohnsonau.com} [contributor] \item Kaitlyn Johnson \email{johnsonkaitlyne9@gmail.com} (\href{https://orcid.org/0000-0001-8011-0012}{ORCID}) [contributor] } diff --git a/man/rt_opts.Rd b/man/rt_opts.Rd index c48cfe21e..3155f9101 100644 --- a/man/rt_opts.Rd +++ b/man/rt_opts.Rd @@ -11,7 +11,7 @@ rt_opts( use_breakpoints = TRUE, future = "latest", gp_on = c("R_t-1", "R0"), - pop = 0 + pop = Fixed(0) ) } \arguments{ @@ -50,9 +50,9 @@ Rt = Rt-1 * GP), and applying the Gaussian process to a global mean (i.e Rt but the method relying on a global mean will revert to this for real time estimates, which may not be desirable.} -\item{pop}{Integer, defaults to 0. Susceptible population initially present. -Used to adjust Rt estimates when otherwise fixed based on the proportion of -the population that is susceptible. When set to 0 no population adjustment +\item{pop}{A \verb{} giving the initial susceptible population size. +Used to adjust Rt estimates based on the proportion of the population that +is susceptible. Defaults to \code{Fixed(0)} which means no population adjustment is done.} } \value{ diff --git a/man/simulate_infections.Rd b/man/simulate_infections.Rd index bc012013f..e0e34ef23 100644 --- a/man/simulate_infections.Rd +++ b/man/simulate_infections.Rd @@ -16,7 +16,7 @@ simulate_infections( CrIs = c(0.2, 0.5, 0.9), backend = "rstan", seeding_time = NULL, - pop = 0, + pop = Fixed(0), ... ) } @@ -74,9 +74,9 @@ R given) of \code{seeding_time} days is assumed to have followed exponential growth roughly in line with the growth rate implied by the first value of R.} -\item{pop}{Integer, defaults to 0. Susceptible population initially present. -Used to adjust Rt estimates when otherwise fixed based on the proportion of -the population that is susceptible. When set to 0 no population adjustment +\item{pop}{A \verb{} giving the initial susceptible population size. +Used to adjust Rt estimates based on the proportion of the population that +is susceptible. Defaults to \code{Fixed(0)} which means no population adjustment is done.} \item{...}{deprecated; only included for backward compatibility} diff --git a/tests/testthat/test-create_rt_date.R b/tests/testthat/test-create_rt_date.R index 3fc47b1cc..c63020f97 100644 --- a/tests/testthat/test-create_rt_date.R +++ b/tests/testthat/test-create_rt_date.R @@ -27,13 +27,13 @@ test_that("create_rt_data handles custom rt_opts correctly", { use_breakpoints = FALSE, future = "project", gp_on = "R0", - pop = 1000000 + pop = Normal(mean = 1000000, sd = 100) ) result <- create_rt_data(rt = custom_rt, horizon = 7) expect_equal(result$estimate_r, 0) - expect_equal(result$pop, 1000000) + expect_equal(result$use_pop, 1) expect_equal(result$stationary, 1) expect_equal(result$future_time, 7) }) diff --git a/tests/testthat/test-rt_opts.R b/tests/testthat/test-rt_opts.R index 69fb1183c..e35c5824c 100644 --- a/tests/testthat/test-rt_opts.R +++ b/tests/testthat/test-rt_opts.R @@ -19,7 +19,7 @@ test_that("rt_opts handles custom inputs correctly", { use_breakpoints = FALSE, future = "project", gp_on = "R0", - pop = 1000000 + pop = Normal(mean = 1000000, sd = 100) )) expect_null(result$prior) @@ -27,10 +27,17 @@ test_that("rt_opts handles custom inputs correctly", { expect_equal(result$rw, 7) expect_true(result$use_breakpoints) # Should be TRUE when rw > 0 expect_equal(result$future, "project") - expect_equal(result$pop, 1000000) + expect_equal(result$pop, Normal(mean = 1000000, sd = 100)) expect_equal(result$gp_on, "R0") }) +test_that("rt_opts warns when pop is passed as numeric", { + expect_warning( + rt_opts(pop = 1000), + "Specifying `pop` as a numeric value is deprecated" + ) +}) + test_that("rt_opts sets use_breakpoints to TRUE when rw > 0", { result <- rt_opts(rw = 3, use_breakpoints = FALSE) expect_true(result$use_breakpoints) @@ -59,8 +66,7 @@ test_that("rt_opts returns object of correct class", { }) test_that("rt_opts handles edge cases correctly", { - result <- rt_opts(rw = 0.1, pop = -1) + result <- rt_opts(rw = 0.1) expect_equal(result$rw, 0.1) - expect_equal(result$pop, -1) expect_true(result$use_breakpoints) }) diff --git a/vignettes/estimate_infections_options.Rmd.orig b/vignettes/estimate_infections_options.Rmd.orig index 0cd532013..622e47aa2 100644 --- a/vignettes/estimate_infections_options.Rmd.orig +++ b/vignettes/estimate_infections_options.Rmd.orig @@ -154,7 +154,7 @@ dep <- estimate_infections(reported_cases, delays = delay_opts(delay), rt = rt_opts( prior = rt_prior, - pop = 1000000, future = "latest" + pop = Normal(mean = 1000000, sd = 1000), future = "latest" ) ) # summarise results