Skip to content

improve handling of seeding time in simulate_infections() #627

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 9 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
adjust initial infections to exp growth
  • Loading branch information
sbfnk committed Mar 27, 2024
commit 5aa839fc8f1e729214c1d19f774bc248030e9cbe
11 changes: 9 additions & 2 deletions R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
#' `date`). Column `R` must be numeric and `date` must be in date format. If
#' not all days between the first and last day in the `date` are present,
#' it will be assumed that R stays the same until the next given date.
#' @param initial_infections numeric; the initial number of infections.
#' @param initial_infections numeric; the initial number of infections (i.e.
#' before `R` applies). Note that results returned start the day after, i.e.
#' the initial number of infections is not reported again. See also
#' `seeding_time`
#' @param day_of_week_effect either `NULL` (no day of the week effect) or a
#' numerical vector of length specified in [obs_opts()] as `week_length`
#' (default: 7) if `week_effect` is set to TRUE. Each element of the vector
Expand Down Expand Up @@ -115,16 +118,20 @@ simulate_infections <- function(estimates, R, initial_infections,
## estimate initial growth from initial reproduction number if seeding time
## is greater than 1
initial_growth <- (R$R[1] - 1) / mean(generation_time)
## adjust initial infections for initial exponential growth
log_initial_infections <- log(initial_infections) -
(seeding_time - 1) * initial_growth
} else {
initial_growth <- numeric(0)
log_initial_infections <- log(initial_infections)
}

data <- list(
n = 1,
t = nrow(R) + seeding_time,
seeding_time = seeding_time,
future_time = 0,
initial_infections = array(log(initial_infections), dim = c(1, 1)),
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
Expand Down
5 changes: 4 additions & 1 deletion man/simulate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.