From 1f3e7b0ddfd3bc6da4b4465bdb1df7d79218199d Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:54:50 +0100 Subject: [PATCH 01/37] added time_varying_death_risk to create_config, WIP #36 --- R/create_config.R | 7 +++++-- man/create_config.Rd | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/R/create_config.R b/R/create_config.R index 94d9c5e3..4bfce12a 100644 --- a/R/create_config.R +++ b/R/create_config.R @@ -4,7 +4,8 @@ #' around time windows around infections (time of first contact and last #' contact with infector), and the distribution of the Cycle threshold (Ct) #' value from a Real-time PCR or quantitative PCR (qPCR) for confirmed -#' cases. +#' cases, the network effect in the simulation, and if there is a time-varying +#' death risk. #' #' Accepted arguments and their defaults are: #' * `last_contact_distribution = "pois"` @@ -14,6 +15,7 @@ #' * `ct_distribution = "norm"` #' * `ct_distribution_params = c(mean = 25, sd = 2)` #' * `network = "adjusted"` +#' * `time_varying_death_risk = NA` #' #' These parameters do not warrant their own arguments in #' [sim_linelist()] as they rarely need to be changed from their default @@ -57,7 +59,8 @@ create_config <- function(...) { first_contact_distribution_params = c(lambda = 3), ct_distribution = "norm", ct_distribution_params = c(mean = 25, sd = 2), - network = "adjusted" + network = "adjusted", + time_varying_death_risk = NA ) # capture dynamic dots diff --git a/man/create_config.Rd b/man/create_config.Rd index f2e449bb..ad0507d1 100644 --- a/man/create_config.Rd +++ b/man/create_config.Rd @@ -22,7 +22,8 @@ The \code{config} argument in \code{\link[=sim_linelist]{sim_linelist()}} contro around time windows around infections (time of first contact and last contact with infector), and the distribution of the Cycle threshold (Ct) value from a Real-time PCR or quantitative PCR (qPCR) for confirmed -cases. +cases, the network effect in the simulation, and if there is a time-varying +death risk. Accepted arguments and their defaults are: \itemize{ @@ -33,6 +34,7 @@ Accepted arguments and their defaults are: \item \code{ct_distribution = "norm"} \item \code{ct_distribution_params = c(mean = 25, sd = 2)} \item \code{network = "adjusted"} +\item \code{time_varying_death_risk = 1} } These parameters do not warrant their own arguments in From 05a7fc9e9dc4a2783a5a3b1d7cfab2b4948ec068 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:55:07 +0100 Subject: [PATCH 02/37] updated create_config tests --- tests/testthat/test-create_config.R | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-create_config.R b/tests/testthat/test-create_config.R index 6d82b971..2dc1e616 100644 --- a/tests/testthat/test-create_config.R +++ b/tests/testthat/test-create_config.R @@ -1,13 +1,14 @@ test_that("create_config works as expected with defaults", { config <- create_config() expect_type(config, type = "list") - expect_length(config, 7) + expect_length(config, 8) expect_named( config, c( "last_contact_distribution", "last_contact_distribution_params", "first_contact_distribution", "first_contact_distribution_params", - "ct_distribution", "ct_distribution_params", "network" + "ct_distribution", "ct_distribution_params", "network", + "time_varying_death_risk" ) ) }) @@ -15,13 +16,14 @@ test_that("create_config works as expected with defaults", { test_that("create_config works as expected modifying element", { config <- create_config(last_contact_distribution = "geom") expect_type(config, type = "list") - expect_length(config, 7) + expect_length(config, 8) expect_named( config, c( "last_contact_distribution", "last_contact_distribution_params", "first_contact_distribution", "first_contact_distribution_params", - "ct_distribution", "ct_distribution_params", "network" + "ct_distribution", "ct_distribution_params", "network", + "time_varying_death_risk" ) ) expect_identical(config$last_contact_distribution, "geom") @@ -35,13 +37,14 @@ test_that("create_config works as expected with spliced list", { ) ) expect_type(config, type = "list") - expect_length(config, 7) + expect_length(config, 8) expect_named( config, c( "last_contact_distribution", "last_contact_distribution_params", "first_contact_distribution", "first_contact_distribution_params", - "ct_distribution", "ct_distribution_params", "network" + "ct_distribution", "ct_distribution_params", "network", + "time_varying_death_risk" ) ) expect_identical(config$ct_distribution, "lnorm") @@ -55,13 +58,14 @@ test_that("create_config works as expected with spliced list", { ) ) expect_type(config, type = "list") - expect_length(config, 7) + expect_length(config, 8) expect_named( config, c( "last_contact_distribution", "last_contact_distribution_params", "first_contact_distribution", "first_contact_distribution_params", - "ct_distribution", "ct_distribution_params", "network" + "ct_distribution", "ct_distribution_params", "network", + "time_varying_death_risk" ) ) expect_identical(config$last_contact_distribution, "geom") From 3a4e371488ae4837c6132505be15ebd9e805bb12 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:56:11 +0100 Subject: [PATCH 03/37] updated .add_outcome to use time-varying death risk if specified in config, WIP #36 --- R/add_cols.R | 29 ++++++++++++++++++++++++++++- man/dot-add_date.Rd | 6 +++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/R/add_cols.R b/R/add_cols.R index 9d77b98b..8d41b0f2 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -122,7 +122,8 @@ NULL onset_to_death, onset_to_recovery, hosp_death_risk, - non_hosp_death_risk) { + non_hosp_death_risk, + config) { infected_idx <- .data$infected == "infected" num_infected <- sum(infected_idx) .data$outcome <- "contact" @@ -142,6 +143,32 @@ NULL replace = FALSE, size = risk * sum(idx) ) + + if (is.function(config$time_varying_death_risk)) { + # check time-varying function + .check_func_req_args(config$time_varying_death_risk) + + # sample which deaths to keep with time-varying risk + prob_death <- config$time_varying_death_risk(.data$time[pop_sample]) + max_prob_death <- stats::optimise( + f = config$time_varying_death_risk, + interval = c(0, 100), + maximum = TRUE + )$objective + norm_prob_death <- prob_death / max_prob_death + # set all values > 1 and < 0 to 1 and 0 due to imprecision of optimise + # TODO: ideally this step would be removed as no values are 0 > x < 1 + norm_prob_death[norm_prob_death > 1] <- 1 + norm_prob_death[norm_prob_death < 0] <- 0 + death_sample <- stats::rbinom( + n = pop_sample, + size = 1, + prob = norm_prob_death + ) + # subset deaths given sampling (logical conversion for vec subsetting) + pop_sample <- pop_sample[as.logical(death_sample)] + } + .data$outcome[pop_sample] <- "died" .data$outcome_time[pop_sample] <- .data$time[pop_sample] + onset_to_death(length(pop_sample)) diff --git a/man/dot-add_date.Rd b/man/dot-add_date.Rd index 64e77276..eca68683 100644 --- a/man/dot-add_date.Rd +++ b/man/dot-add_date.Rd @@ -22,7 +22,8 @@ onset_to_death, onset_to_recovery, hosp_death_risk, - non_hosp_death_risk + non_hosp_death_risk, + config ) } \arguments{ @@ -73,6 +74,9 @@ specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples for more information.} + +\item{config}{A list of settings to adjust the randomly sampled delays and +Ct values (if \code{add_ct = TRUE}). See \code{\link[=create_config]{create_config()}} for more information.} } \value{ A \verb{} with one more column than input into \code{.data}. From 7234292b3df74390ed757764dfac494e60de3036 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:56:27 +0100 Subject: [PATCH 04/37] updated .add_outcome tests --- tests/testthat/test-add_cols.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-add_cols.R b/tests/testthat/test-add_cols.R index c5d76efb..47350c45 100644 --- a/tests/testthat/test-add_cols.R +++ b/tests/testthat/test-add_cols.R @@ -182,7 +182,8 @@ test_that(".add_outcome works as expected", { onset_to_death = onset_to_death, onset_to_recovery = onset_to_recovery, hosp_death_risk = 0.5, - non_hosp_death_risk = 0.5 + non_hosp_death_risk = 0.5, + config = create_config() ) expect_s3_class(linelist, class = "data.frame") expect_type(linelist$outcome, type = "character") @@ -201,7 +202,8 @@ test_that(".add_outcome works as expected with different parameter", { onset_to_death = onset_to_death, onset_to_recovery = onset_to_recovery, hosp_death_risk = 0.9, - non_hosp_death_risk = 0.1 + non_hosp_death_risk = 0.1, + config = create_config() ) expect_s3_class(linelist, class = "data.frame") expect_type(linelist$outcome, type = "character") From 9ff4656bb842f72720a219bae31a7e32e47ee16c Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:56:46 +0100 Subject: [PATCH 05/37] added config argument to .add_outcome call in .sim_internal --- R/sim_internal.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/sim_internal.R b/R/sim_internal.R index 9f97bf53..73f77d90 100644 --- a/R/sim_internal.R +++ b/R/sim_internal.R @@ -115,7 +115,8 @@ onset_to_death = onset_to_death, onset_to_recovery = onset_to_recovery, hosp_death_risk = hosp_death_risk, - non_hosp_death_risk = non_hosp_death_risk + non_hosp_death_risk = non_hosp_death_risk, + config = config ) # add hospitalisation and death dates From f89c743860e1d13514f9c1cf11f659310696d509 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 17:59:24 +0100 Subject: [PATCH 06/37] added bullet point on type checking the config list to the design-principles vignette --- vignettes/design-principles.Rmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vignettes/design-principles.Rmd b/vignettes/design-principles.Rmd index a8eeef22..ce0d9a68 100644 --- a/vignettes/design-principles.Rmd +++ b/vignettes/design-principles.Rmd @@ -42,6 +42,8 @@ The simulation functions either return a `` or a `list` of ` Date: Thu, 11 Apr 2024 17:56:18 +0100 Subject: [PATCH 07/37] updated create_config documentation --- man/create_config.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/create_config.Rd b/man/create_config.Rd index ad0507d1..f2a3ecc2 100644 --- a/man/create_config.Rd +++ b/man/create_config.Rd @@ -34,7 +34,7 @@ Accepted arguments and their defaults are: \item \code{ct_distribution = "norm"} \item \code{ct_distribution_params = c(mean = 25, sd = 2)} \item \code{network = "adjusted"} -\item \code{time_varying_death_risk = 1} +\item \code{time_varying_death_risk = NA} } These parameters do not warrant their own arguments in From 042c7dc1300977a36999d44a791a6bec4fc93cbb Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 11 Apr 2024 17:56:52 +0100 Subject: [PATCH 08/37] updated wording of input checking for create_config point in design-principles vignette --- vignettes/design-principles.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/design-principles.Rmd b/vignettes/design-principles.Rmd index ce0d9a68..f20fb54c 100644 --- a/vignettes/design-principles.Rmd +++ b/vignettes/design-principles.Rmd @@ -42,7 +42,7 @@ The simulation functions either return a `` or a `list` of ` Date: Thu, 11 Apr 2024 17:57:16 +0100 Subject: [PATCH 09/37] added first draft of time-varying-cfr vignette, relates #36 --- vignettes/time-varying-cfr.Rmd | 413 +++++++++++++++++++++++++++++++++ 1 file changed, 413 insertions(+) create mode 100644 vignettes/time-varying-cfr.Rmd diff --git a/vignettes/time-varying-cfr.Rmd b/vignettes/time-varying-cfr.Rmd new file mode 100644 index 00000000..ce5b72ce --- /dev/null +++ b/vignettes/time-varying-cfr.Rmd @@ -0,0 +1,413 @@ +--- +title: "Time-varying case fatality risk" +output: + bookdown::html_vignette2: + code_folding: show +pkgdown: + as_is: true +vignette: > + %\VignetteIndexEntry{Time-varying case fatality risk} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +::: {.alert .alert-info} +If you are unfamiliar with the {simulist} package or the `sim_linelist()` function [Get Started vignette](simulist.html) is a great place to start. +::: + +This vignette demonstrates how to use the time-varying case fatality risk and gives an overview of the methodologically details. + +::: {.alert .alert-secondary} + +The {simulist} R package uses an individual-based branching process simulation to generate contacts and cases for line list and contact tracing data. The time-varying case fatality risk feature provides a way to incorporate aspects of epidemics where the risk of death may decrease through time, potentially due to improved medical treatment, vaccination or viral evolution. It is also possible to model increasing case fatality risk through time, or a step-wise risk function where the risk of death shifts between states. + +The time-varying case fatality risk implemented in this package is not meant to explicitly model these factors, but rather to give the user an option to more closely resemble fatality risk through the course of an epidemic, Possibly because there data on this, or just to simulate data that has these characteristics. + +See the [{epidemics} R package](https://epiverse-trace.github.io/epidemics/index.html) for a population-level epidemic simulation package with explicit interventions and vaccinations. + +::: + +Given that setting a time-varying case fatality risk is not needed for most use cases of the {simulist} R package, this feature uses the `config` argument in the `sim_*()` functions. Therefore, the time-varying case fatality risk can be set when calling `create_config()` (see below for details). + +```{r setup} +library(simulist) +library(epiparameter) +library(tidyr) +library(dplyr) +library(incidence2) +library(ggplot2) +``` + +First we will demonstrate the default setting of a constant case fatality risk throughout an epidemic. + +We load the required delay distributions using the {epiparameter} package, by either manually creating them (contact distribution and infectious period), or load them from the {epiparameter} library of epidemiological parameters (onset-to-hospitalisation and onset-to-death). + +```{r, read-delay-dists} +contact_distribution <- epidist( + disease = "COVID-19", + epi_dist = "contact distribution", + prob_distribution = "pois", + prob_distribution_params = c(mean = 2) +) + +infect_period <- epidist( + disease = "COVID-19", + epi_dist = "infectious period", + prob_distribution = "gamma", + prob_distribution_params = c(shape = 3, scale = 3) +) + +# get onset to hospital admission from {epiparameter} database +onset_to_hosp <- epidist_db( + disease = "COVID-19", + epi_dist = "onset to hospitalisation", + single_epidist = TRUE +) + +# get onset to death from {epiparameter} database +onset_to_death <- epidist_db( + disease = "COVID-19", + epi_dist = "onset to death", + single_epidist = TRUE +) +``` + +We set the seed to ensure we have the same output each time the vignette is rendered. When using {simulist}, setting the seed is not required unless you need to simulate the same line list multiple times. + +```{r, set-seed} +set.seed(1) +``` + +## Constant case fatality risk + +When calling the `create_config()` function the default output contains a list element named `time_varying_death_risk` set to `NA`. This corresponds to a constant case fatality risk over time, which is controlled by the `hosp_death_risk` and `non_hosp_death_risk` arguments. The defaults for these two arguments are: + +* death risk when hospitalised (`hosp_death_risk`): `0.5` (50%) +* death risk outside of hospitals (`non_hosp_death_risk`): `0.05` (5%) + +In this example we set them explicitly to be clear which risks we're using, but otherwise the `hosp_death_risk`, `non_hosp_death_risk` and `config` do not need to be specified and can use their default values. + +For all examples in this vignette we will set the epidemic size to be between 500 and 1,000 cases, to ensure that we can clearly see the case fatality patterns in the data. + +::: {.alert .alert-info} +See the [Get Started vignette section on Controlling Outbreak Size](simulist.html#Controlling-outbreak-size) for more information on this. +::: + +```{r, sim-linelist} +linelist <- sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = 0.5, + non_hosp_death_risk = 0.05, + outbreak_size = c(500, 1000), + config = create_config() +) + +head(linelist) +``` + +To visualise the incidence of cases and deaths over time we will use the [{incidence2} R package](https://www.reconverse.org/incidence2/). + +::: {.alert .alert-info} +For more information on using {incidence2} to plot line list data see the [Visualising simulated data](vis-linelist.html) vignette. +::: + +Before converting the line list `` to an `` object we need to ungroup the outcome columns into their own columns using the [{tidyr}](https://tidyr.tidyverse.org/) and [{dplyr}](https://dplyr.tidyverse.org/) R package from the [Tidyverse](https://www.tidyverse.org/). + +```{r, reshape-linelist} +linelist <- linelist %>% + pivot_wider( + names_from = outcome, + values_from = date_outcome + ) %>% + rename( + date_death = died, + date_recovery = recovered + ) +``` + +```{r, plot-onset-hospitalisation, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.5 and the risk for non-hospitalised individuals is 0.05, and these risks are constant through time.", fig.width = 8, fig.height = 5} +daily <- incidence( + linelist, + date_index = c( + onset = "date_onset", + death = "date_death" + ), + interval = "daily" +) +daily <- complete_dates(daily) +plot(daily) +``` + +## Higher risk of case fatality + +We repeat the above simulation but increase the risk of case fatality for both hospitalised (`hosp_death_risk`) and non-hospitalised (`non_hosp_death_risk`) individuals infected. + +```{r, sim-linelist-higher-death-risk} +linelist <- sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = 0.9, + non_hosp_death_risk = 0.75, + outbreak_size = c(500, 1000), + config = create_config() +) + +# first 6 rows of linelist +head(linelist) +``` + +```{r, reshape-linelist-higher-death-risk} +linelist <- linelist %>% + pivot_wider( + names_from = outcome, + values_from = date_outcome + ) %>% + rename( + date_death = died, + date_recovery = recovered + ) +``` + +```{r, plot-onset-death-higher-risk, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.9 and the risk for non-hospitalised individuals is 0.75, and these risks are constant through time.", fig.width = 8, fig.height = 5} +daily <- incidence( + linelist, + date_index = c( + onset = "date_onset", + death = "date_death" + ), + interval = "daily" +) +daily <- complete_dates(daily) +plot(daily) +``` + +## Continuous time-varying case fatality risk + +Now we've seen what the constant case fatality risk simulations look like, we can simulate with a time-varying function for the risk. + +This is setup by calling the `create_config()` function, and providing an anonymous function with a single argument for the time of the simulation which maps to a probability, propensity or risk at each time value to `time_varying_death_risk`. + +The `create_config()` function has no named arguments, and the argument you are modifying needs to be matched by name exactly (case sensitive). See `?create_config()` for documentation. + +```{r, setup-time-varying-cfr} +config <- create_config( + time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) +) +``` + +Here we set the case fatality risk to exponentially decrease through time at a rate ($\lambda$) of 0.05. This will provide a shallow (monotonic) decline of case fatality through the simulated epidemic. + +```{r, plot-exponential-dist, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +exp_df <- data.frame( + time = 1:150, + value = config$time_varying_death_risk(1:150) +) +ggplot(exp_df) + + geom_point(mapping = aes(x = time, y = value)) + + scale_y_continuous(name = "Value") + + scale_x_continuous(name = "Time (Days)") + + theme_bw() +``` + +::: {.alert .alert-info} + +_Advanced_ + +The time-varying case fatality risk function reduces the death risk specified by `hosp_death_risk` and `non_hosp_death_risk`, in such as a way that the risks (`*_risk`) given by the user now operate as the maximum risk. The maximum values of the user-supplied time-varying function is the same as the risks specified. + +In the example below `hosp_death_risk` is `0.9` and `non_hosp_death_risk` is `0.75`, and the time-varying case fatality risk function is an exponential decline. This means that on day 0 of the epidemic (i.e. first infection seeds the outbreak) the risks will be `0.9` and `0.75`. But any time after the start of the epidemic ($t_0 + \Delta t$) the risks will be lower, and when the exponential function approaches zero the risk of a case dying will also go to zero. + +The time-varying function supplied to `create_config(time_varying_death_risk = )` does not need to evaluate to between 0 and 1 because internally the function is normalised. + +::: + +Simulating with the time-varying case fatality risk: + +```{r, sim-linelist-time-varying-cfr} +linelist <- sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = 0.9, + non_hosp_death_risk = 0.75, + outbreak_size = c(500, 1000), + config = config +) + +head(linelist) +``` + +```{r, reshape-linelist-time-varying-cfr} +linelist <- linelist %>% + pivot_wider( + names_from = outcome, + values_from = date_outcome + ) %>% + rename( + date_death = died, + date_recovery = recovered + ) +``` + +```{r, plot-onset-death-time-varying-cfr, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +daily <- incidence( + linelist, + date_index = c( + onset = "date_onset", + death = "date_death" + ), + interval = "daily" +) +daily <- complete_dates(daily) +plot(daily) +``` + +## Stepwise time-varying case fatality risk + +In addition to a continuously varying case fatality risk function, the simulation can also work with stepwise (or piecewise) functions. This is where the risk will instantaneously change at a given point in time to another risk level. + +To achieve this, we again specify an anonymous function in `create_config()`, but have the risk of a case dying be equal to the `hosp_death_risk` and `non_hosp_death_risk` for the first 60 days of the outbreak and then become zero (i.e. if an individual is infected after day 60 they will definitely recover). + +```{r, setup-time-varying-cfr-stepwise} +config <- create_config( + time_varying_death_risk = function(x) ifelse(test = x < 60, yes = 1, no = 0) +) +``` + +```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +stepwise_df <- data.frame( + time = 1:150, + value = config$time_varying_death_risk(1:150) +) +ggplot(stepwise_df) + + geom_point(mapping = aes(x = time, y = value)) + + scale_y_continuous(name = "Value") + + scale_x_continuous(name = "Time (Days)") + + theme_bw() +``` + +Simulating with the stepwise time-varying case fatality risk: + +```{r, sim-linelist-time-varying-cfr-stepwise} +linelist <- sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = 0.9, + non_hosp_death_risk = 0.75, + outbreak_size = c(500, 1000), + config = config +) + +head(linelist) +``` + +```{r, reshape-linelist-time-varying-cfr-stepwise} +linelist <- linelist %>% + pivot_wider( + names_from = outcome, + values_from = date_outcome + ) %>% + rename( + date_death = died, + date_recovery = recovered + ) +``` + +```{r, plot-onset-death-time-varying-cfr-stepwise, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +daily <- incidence( + linelist, + date_index = c( + onset = "date_onset", + death = "date_death" + ), + interval = "daily" +) +daily <- complete_dates(daily) +plot(daily) +``` + +The same stepwise function can also be used to specify time windows were the risk of death is reduced. Here we specify the risk of death is equal to the `hosp_death_risk` and `non_hosp_death_risk` in the first 50 days of the epidemic, then between day 50 and day 100 the risk is reduced by half, and then from day 100 onwards the risk goes back to the rates specified by `hosp_death_risk` and `non_hosp_death_risk`. + +```{r, setup-time-varying-cfr-stepwise-window} +config <- create_config( + time_varying_death_risk = function(x) { + ifelse(test = x > 50 & x < 100, yes = 0.5, no = 1) + } +) +``` + +```{r, plot-stepwise-dist-window, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +stepwise_df <- data.frame( + time = 1:150, + value = config$time_varying_death_risk(1:150) +) +ggplot(stepwise_df) + + geom_point(mapping = aes(x = time, y = value)) + + scale_y_continuous(name = "Value", limits = c(0, 1)) + + scale_x_continuous(name = "Time (Days)") + + theme_bw() +``` + +Simulating with the stepwise time-varying case fatality risk: + +```{r, sim-linelist-time-varying-cfr-stepwise-window} +linelist <- sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = 0.9, + non_hosp_death_risk = 0.75, + outbreak_size = c(500, 1000), + config = config +) + +head(linelist) +``` + +```{r, reshape-linelist-time-varying-cfr-stepwise-window} +linelist <- linelist %>% + pivot_wider( + names_from = outcome, + values_from = date_outcome + ) %>% + rename( + date_death = died, + date_recovery = recovered + ) +``` + +```{r, plot-onset-death-time-varying-cfr-stepwise-window, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +daily <- incidence( + linelist, + date_index = c( + onset = "date_onset", + death = "date_death" + ), + interval = "daily" +) +daily <- complete_dates(daily) +plot(daily) +``` + +The implementation of the time-varying case fatality rate in the simulation functions (`sim_linelist()` and `sim_outbreak()`) is flexible to many functional forms. If there are other ways to have a time-varying case fatality risk that are not currently possible please make an [issue](https://github.com/epiverse-trace/simulist/issues) or [pull request](https://github.com/epiverse-trace/simulist/pulls). Currently the hospitalisation risk is assumed constant over time can cannot be adjusted to be time-varying like the death risk, if this is a feature you would like included in the {simulist} R package please make the request in an [issue](https://github.com/epiverse-trace/simulist/issues). From 4b845fbf585a8640715425db8b1f503b991b3e50 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 11 Apr 2024 17:57:35 +0100 Subject: [PATCH 10/37] added time-varying-cfr vignette to _pkgdown.yml reference --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 7f62032a..e30026ef 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -23,6 +23,7 @@ articles: contents: - age-strat-risks - age-struct-pop + - time-varying-cfr - vis-linelist - title: Developer Documentation navbar: Developer Documentation From 51882034e547dc722ecbfbb4aae1bd4a922f5173 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 11 Apr 2024 17:57:45 +0100 Subject: [PATCH 11/37] updated WORDLIST --- inst/WORDLIST | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index 32bc7226..9be08749 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -10,6 +10,7 @@ Ct ct db dist +dplyr epi Epi epicontacts @@ -58,6 +59,7 @@ svg tabset testthat threejs +tidyr Tidyverse visNetwork yaml From 421b6fb7a3ceb22a3a159fd354fb9a446d7faa66 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 12 Apr 2024 17:23:29 +0100 Subject: [PATCH 12/37] updated hosp_death_risk and non_hosp_death_risk documentation to include time-varying rates, relates #36 --- R/sim_linelist.R | 8 ++++++-- man/dot-add_date.Rd | 8 ++++++-- man/dot-check_sim_input.Rd | 8 ++++++-- man/dot-cross_check_sim_input.Rd | 8 ++++++-- man/dot-sim_internal.Rd | 8 ++++++-- man/sim_linelist.Rd | 8 ++++++-- man/sim_outbreak.Rd | 8 ++++++-- 7 files changed, 42 insertions(+), 14 deletions(-) diff --git a/R/sim_linelist.R b/R/sim_linelist.R index 7495c546..4d244be2 100644 --- a/R/sim_linelist.R +++ b/R/sim_linelist.R @@ -53,13 +53,17 @@ #' specific hospitalised death risks Default is 50% death risk in hospitals #' (`0.5`) for the entire population. If the `onset_to_death` argument is set #' to `NA` this argument should also be set to `NA`. See details and examples -#' for more information. +#' for more information. If a time-varying death risk is specified in the +#' `config` the `hosp_death_risk` is interpreted as the maximum risk across +#' the epidemic. #' @param non_hosp_death_risk Either a single `numeric` for the death risk for #' outside of hospitals across the population, or a `` with age #' specific death risks outside of hospitals. Default is 5% death risk outside #' of hospitals (`0.05`) for the entire population. If the `onset_to_death` #' argument is set to `NA` this argument should also be set to `NA`. See -#' details and examples for more information. +#' details and examples for more information. If a time-varying death risk is +#' specified in the `config` the `non_hosp_death_risk` is interpreted as the +#' maximum risk across the epidemic. #' @param outbreak_start_date A `date` for the start of the outbreak. #' @param add_names A `logical` boolean for whether to add names to each row #' of the line list. Default is `TRUE`. diff --git a/man/dot-add_date.Rd b/man/dot-add_date.Rd index eca68683..f0a87cf7 100644 --- a/man/dot-add_date.Rd +++ b/man/dot-add_date.Rd @@ -66,14 +66,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} \item{config}{A list of settings to adjust the randomly sampled delays and Ct values (if \code{add_ct = TRUE}). See \code{\link[=create_config]{create_config()}} for more information.} diff --git a/man/dot-check_sim_input.Rd b/man/dot-check_sim_input.Rd index 3f4904de..2b44e8da 100644 --- a/man/dot-check_sim_input.Rd +++ b/man/dot-check_sim_input.Rd @@ -98,14 +98,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} \item{population_age}{Either a \code{numeric} vector with two elements or a \verb{} with age structure in the population. Use a \code{numeric} vector diff --git a/man/dot-cross_check_sim_input.Rd b/man/dot-cross_check_sim_input.Rd index 1f354975..c42419ef 100644 --- a/man/dot-cross_check_sim_input.Rd +++ b/man/dot-cross_check_sim_input.Rd @@ -33,14 +33,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} } \value{ Invisibly return the \code{onset_to_hosp} argument. The function is diff --git a/man/dot-sim_internal.Rd b/man/dot-sim_internal.Rd index 04668f25..6095f279 100644 --- a/man/dot-sim_internal.Rd +++ b/man/dot-sim_internal.Rd @@ -70,14 +70,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} \item{outbreak_start_date}{A \code{date} for the start of the outbreak.} diff --git a/man/sim_linelist.Rd b/man/sim_linelist.Rd index 03a371d4..b5f0dba9 100644 --- a/man/sim_linelist.Rd +++ b/man/sim_linelist.Rd @@ -64,14 +64,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} \item{outbreak_start_date}{A \code{date} for the start of the outbreak.} diff --git a/man/sim_outbreak.Rd b/man/sim_outbreak.Rd index ed2e5bca..224a93d0 100644 --- a/man/sim_outbreak.Rd +++ b/man/sim_outbreak.Rd @@ -66,14 +66,18 @@ hospitalised individuals across the population, or a \verb{} with ag specific hospitalised death risks Default is 50\% death risk in hospitals (\code{0.5}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples -for more information.} +for more information. If a time-varying death risk is specified in the +\code{config} the \code{hosp_death_risk} is interpreted as the maximum risk across +the epidemic.} \item{non_hosp_death_risk}{Either a single \code{numeric} for the death risk for outside of hospitals across the population, or a \verb{} with age specific death risks outside of hospitals. Default is 5\% death risk outside of hospitals (\code{0.05}) for the entire population. If the \code{onset_to_death} argument is set to \code{NA} this argument should also be set to \code{NA}. See -details and examples for more information.} +details and examples for more information. If a time-varying death risk is +specified in the \code{config} the \code{non_hosp_death_risk} is interpreted as the +maximum risk across the epidemic.} \item{outbreak_start_date}{A \code{date} for the start of the outbreak.} From 53adf84b7b293df4442c4425cf9a938ef5a874c6 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 12 Apr 2024 17:24:05 +0100 Subject: [PATCH 13/37] updated time-varying-cfr vignette figure captions, code folding and wording --- vignettes/time-varying-cfr.Rmd | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/vignettes/time-varying-cfr.Rmd b/vignettes/time-varying-cfr.Rmd index ce5b72ce..fa9940c3 100644 --- a/vignettes/time-varying-cfr.Rmd +++ b/vignettes/time-varying-cfr.Rmd @@ -22,13 +22,13 @@ knitr::opts_chunk$set( If you are unfamiliar with the {simulist} package or the `sim_linelist()` function [Get Started vignette](simulist.html) is a great place to start. ::: -This vignette demonstrates how to use the time-varying case fatality risk and gives an overview of the methodologically details. +This vignette demonstrates how to simulate line list data using the time-varying case fatality risk and gives an overview of the methodologically details. ::: {.alert .alert-secondary} -The {simulist} R package uses an individual-based branching process simulation to generate contacts and cases for line list and contact tracing data. The time-varying case fatality risk feature provides a way to incorporate aspects of epidemics where the risk of death may decrease through time, potentially due to improved medical treatment, vaccination or viral evolution. It is also possible to model increasing case fatality risk through time, or a step-wise risk function where the risk of death shifts between states. +The {simulist} R package uses an individual-based branching process simulation to generate contacts and cases for line list and contact tracing data. The time-varying case fatality risk feature provides a way to incorporate aspects of epidemics where the risk of death may decrease through time, potentially due to improved medical treatment, vaccination or viral evolution. It is also possible to model increasing case fatality risk through time, or a stepwise risk function where the risk of death shifts between states. -The time-varying case fatality risk implemented in this package is not meant to explicitly model these factors, but rather to give the user an option to more closely resemble fatality risk through the course of an epidemic, Possibly because there data on this, or just to simulate data that has these characteristics. +The time-varying case fatality risk implemented in this package is not meant to explicitly model these factors, but rather to give the user an option to more closely resemble fatality risk through the course of an epidemic, possibly because there is data on this, or just to simulate data that has these characteristics. See the [{epidemics} R package](https://epiverse-trace.github.io/epidemics/index.html) for a population-level epidemic simulation package with explicit interventions and vaccinations. @@ -113,6 +113,7 @@ linelist <- sim_linelist( config = create_config() ) +# first 6 rows of linelist head(linelist) ``` @@ -122,7 +123,7 @@ To visualise the incidence of cases and deaths over time we will use the [{incid For more information on using {incidence2} to plot line list data see the [Visualising simulated data](vis-linelist.html) vignette. ::: -Before converting the line list `` to an `` object we need to ungroup the outcome columns into their own columns using the [{tidyr}](https://tidyr.tidyverse.org/) and [{dplyr}](https://dplyr.tidyverse.org/) R package from the [Tidyverse](https://www.tidyverse.org/). +Before converting the line list `` to an `` object we need to ungroup the outcome columns into their own columns using the [{tidyr}](https://tidyr.tidyverse.org/) and [{dplyr}](https://dplyr.tidyverse.org/) R packages from the [Tidyverse](https://www.tidyverse.org/). ```{r, reshape-linelist} linelist <- linelist %>% @@ -136,7 +137,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-hospitalisation, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.5 and the risk for non-hospitalised individuals is 0.05, and these risks are constant through time.", fig.width = 8, fig.height = 5} +```{r, plot-onset-hospitalisation, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.5 and the risk for non-hospitalised individuals is 0.05, and these risks are constant through time.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -166,7 +167,6 @@ linelist <- sim_linelist( config = create_config() ) -# first 6 rows of linelist head(linelist) ``` @@ -182,7 +182,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-death-higher-risk, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.9 and the risk for non-hospitalised individuals is 0.75, and these risks are constant through time.", fig.width = 8, fig.height = 5} +```{r, plot-onset-death-higher-risk, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. Case fatality risk for hospitalised individuals is 0.9 and the risk for non-hospitalised individuals is 0.75, and these risks are constant through time.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -199,7 +199,7 @@ plot(daily) Now we've seen what the constant case fatality risk simulations look like, we can simulate with a time-varying function for the risk. -This is setup by calling the `create_config()` function, and providing an anonymous function with a single argument for the time of the simulation which maps to a probability, propensity or risk at each time value to `time_varying_death_risk`. +This is setup by calling the `create_config()` function, and providing an anonymous function with a single argument to `time_varying_death_risk` for the time of the simulation which maps to a probability, propensity or risk scaling factor at each time value. The `create_config()` function has no named arguments, and the argument you are modifying needs to be matched by name exactly (case sensitive). See `?create_config()` for documentation. @@ -211,7 +211,7 @@ config <- create_config( Here we set the case fatality risk to exponentially decrease through time at a rate ($\lambda$) of 0.05. This will provide a shallow (monotonic) decline of case fatality through the simulated epidemic. -```{r, plot-exponential-dist, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +```{r, plot-exponential-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values at day 0 and decline through time, with risk approaching zero at around day 100.", fig.width = 8, fig.height = 5} exp_df <- data.frame( time = 1:150, value = config$time_varying_death_risk(1:150) @@ -265,7 +265,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-death-time-varying-cfr, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +```{r, plot-onset-death-time-varying-cfr, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. The maximum case fatality risk for hospitalised individuals is 0.9 and for non-hospitalised individuals is 0.75, and these decline exponentially through time.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -290,7 +290,7 @@ config <- create_config( ) ``` -```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values from day 0 to day 60, and then become 0 onwards.", fig.width = 8, fig.height = 5} stepwise_df <- data.frame( time = 1:150, value = config$time_varying_death_risk(1:150) @@ -332,7 +332,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-death-time-varying-cfr-stepwise, class.source = 'fold-hide', fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +```{r, plot-onset-death-time-varying-cfr-stepwise, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. The maximum case fatality risk for hospitalised individuals is 0.9 and for non-hospitalised individuals is 0.75, and these rates remain constant from days 0 to 60, and then go to 0 from day 60 onwards.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -355,7 +355,7 @@ config <- create_config( ) ``` -```{r, plot-stepwise-dist-window, class.source = 'fold-hide', fig.width = 8, fig.height = 5} +```{r, plot-stepwise-dist-window, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values from day 0 to day 50, and then half the risks from day 50 to day 100, and then return to their maximum value from day 100 onwards.", fig.width = 8, fig.height = 5} stepwise_df <- data.frame( time = 1:150, value = config$time_varying_death_risk(1:150) @@ -397,7 +397,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-death-time-varying-cfr-stepwise-window, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths.", fig.width = 8, fig.height = 5} +```{r, plot-onset-death-time-varying-cfr-stepwise-window, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. The maximum case fatality risk for hospitalised individuals is 0.9 and for non-hospitalised individuals is 0.75, and these rates remain constant from days 0 to 50, and then from days 50 to 100 the case fatality risk is halved (i.e `hosp_death_risk` = 0.45 and `non_hosp_death_risk` = 0.375), before going back to their original risks from day 100 onwards.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -410,4 +410,6 @@ daily <- complete_dates(daily) plot(daily) ``` +This vignette does not explore applying a time-varying case fatality risk to age-stratified fatality risks, but this is possible with the `sim_linelist()` and `sim_outbreak()` functions. See the [Age-stratified hospitalisation and death risks vignette](age-strat-risks.html) and combine with instructions from this vignette on setting in a time-varying function using `create_config()`. + The implementation of the time-varying case fatality rate in the simulation functions (`sim_linelist()` and `sim_outbreak()`) is flexible to many functional forms. If there are other ways to have a time-varying case fatality risk that are not currently possible please make an [issue](https://github.com/epiverse-trace/simulist/issues) or [pull request](https://github.com/epiverse-trace/simulist/pulls). Currently the hospitalisation risk is assumed constant over time can cannot be adjusted to be time-varying like the death risk, if this is a feature you would like included in the {simulist} R package please make the request in an [issue](https://github.com/epiverse-trace/simulist/issues). From 5751f1c08723c354e0c1a4ead850d74e2eb83462 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 12 Apr 2024 17:24:26 +0100 Subject: [PATCH 14/37] fix .add_outcome test by adding config argument --- tests/testthat/test-add_cols.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-add_cols.R b/tests/testthat/test-add_cols.R index 47350c45..0d21dcf6 100644 --- a/tests/testthat/test-add_cols.R +++ b/tests/testthat/test-add_cols.R @@ -232,7 +232,8 @@ test_that(".add_outcome works as expected with age-strat risks", { onset_to_death = onset_to_death, onset_to_recover = onset_to_recovery, hosp_death_risk = age_dep_hosp_death_risk, - non_hosp_death_risk = age_dep_non_hosp_death_risk + non_hosp_death_risk = age_dep_non_hosp_death_risk, + config = create_config() ) expect_s3_class(linelist, class = "data.frame") expect_type(linelist$outcome, type = "character") From fc1f60f6db91e5cb7b5c1a41426d3c3ff237e361 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 12 Apr 2024 17:25:30 +0100 Subject: [PATCH 15/37] updating .add_outcome to include time-varying cfr for age-strat risks and fixing indexing bug --- R/add_cols.R | 105 ++++++++++++++++++++++++++++----------------------- 1 file changed, 57 insertions(+), 48 deletions(-) diff --git a/R/add_cols.R b/R/add_cols.R index 8d41b0f2..7725ee6e 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -131,69 +131,78 @@ NULL .data$outcome[infected_idx] <- "recovered" .data$outcome_time[infected_idx] <- .data$time[infected_idx] + onset_to_recovery(num_infected) - hosp_idx <- !is.na(.data$hospitalisation) - non_hosp_idx <- is.na(.data$hospitalisation) + hosp_idx <- !is.na(.data$hospitalisation) & infected_idx + non_hosp_idx <- is.na(.data$hospitalisation) & infected_idx - apply_death_risk <- function(.data, risk, idx) { + # define functions used only by .add_outcome + time_varying_risk <- function(.data, died_idx, config) { + # check time-varying function + .check_func_req_args(config$time_varying_death_risk) + + # sample which deaths to keep with time-varying risk + prob_death <- config$time_varying_death_risk(.data$time[died_idx]) + max_prob_death <- stats::optimise( + f = config$time_varying_death_risk, + interval = c(0, 100), + maximum = TRUE + )$objective + norm_prob_death <- prob_death / max_prob_death + # set all values > 1 and < 0 to 1 and 0 due to imprecision of optimise + # TODO: ideally this step would be removed as no values are 0 > x < 1 + norm_prob_death[norm_prob_death > 1] <- 1 + norm_prob_death[norm_prob_death < 0] <- 0 + sampled_died <- stats::rbinom( + n = died_idx, + size = 1, + prob = norm_prob_death + ) + # subset deaths given sampling (logical conversion for vec subsetting) + died_idx <- died_idx[as.logical(sampled_died)] + + # return sample of deaths + died_idx + } + + apply_death_risk <- function(.data, risk, idx, config) { if (!is_na(risk)) { + # single population risk is a special case of the age-strat risk + # convert population risk to data.frame to apply the same operations to both if (is.numeric(risk)) { + risk <- data.frame( + min_age = min(.data$age), + max_age = max(.data$age), + risk = risk + ) + } + for (i in seq_len(nrow(risk))) { + age_bracket <- risk$min_age[i]:risk$max_age[i] + age_group_idx <- which(.data$age %in% age_bracket & idx) # size is converted to an integer internally in sample() - pop_sample <- sample( - which(idx), + died_idx <- sample( + age_group_idx, replace = FALSE, - size = risk * sum(idx) + size = risk$risk[i] * length(age_group_idx) ) - if (is.function(config$time_varying_death_risk)) { - # check time-varying function - .check_func_req_args(config$time_varying_death_risk) - - # sample which deaths to keep with time-varying risk - prob_death <- config$time_varying_death_risk(.data$time[pop_sample]) - max_prob_death <- stats::optimise( - f = config$time_varying_death_risk, - interval = c(0, 100), - maximum = TRUE - )$objective - norm_prob_death <- prob_death / max_prob_death - # set all values > 1 and < 0 to 1 and 0 due to imprecision of optimise - # TODO: ideally this step would be removed as no values are 0 > x < 1 - norm_prob_death[norm_prob_death > 1] <- 1 - norm_prob_death[norm_prob_death < 0] <- 0 - death_sample <- stats::rbinom( - n = pop_sample, - size = 1, - prob = norm_prob_death - ) - # subset deaths given sampling (logical conversion for vec subsetting) - pop_sample <- pop_sample[as.logical(death_sample)] - } - - .data$outcome[pop_sample] <- "died" - .data$outcome_time[pop_sample] <- .data$time[pop_sample] + - onset_to_death(length(pop_sample)) - } else { - for (i in seq_len(nrow(risk))) { - age_bracket <- risk$min_age[i]:risk$max_age[i] - age_group <- which(.data$age %in% age_bracket & idx) - # size is converted to an integer internally in sample() - age_group_sample <- sample( - age_group, - replace = FALSE, - size = risk$risk[i] * length(age_group) + died_idx <- time_varying_risk( + .data, + died_idx = died_idx, + config = config ) - .data$outcome[age_group_sample] <- "died" - .data$outcome_time[age_group_sample] <- .data$time[age_group_sample] + - onset_to_death(length(age_group_sample)) } + .data$outcome[died_idx] <- "died" + .data$outcome_time[died_idx] <- .data$time[died_idx] + + onset_to_death(length(died_idx)) } } .data } - .data <- apply_death_risk(.data, risk = hosp_death_risk, idx = hosp_idx) .data <- apply_death_risk( - .data, risk = non_hosp_death_risk, idx = non_hosp_idx + .data, risk = hosp_death_risk, idx = hosp_idx, config = config + ) + .data <- apply_death_risk( + .data, risk = non_hosp_death_risk, idx = non_hosp_idx, config = config ) # return data From d7fbc0579f9d6def0d4b6ee41292343e82b69dad Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 12 Apr 2024 17:26:07 +0100 Subject: [PATCH 16/37] linting --- R/add_cols.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/add_cols.R b/R/add_cols.R index 7725ee6e..57e6fab3 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -166,7 +166,7 @@ NULL apply_death_risk <- function(.data, risk, idx, config) { if (!is_na(risk)) { # single population risk is a special case of the age-strat risk - # convert population risk to data.frame to apply the same operations to both + # convert population risk to data.frame to apply the same operations if (is.numeric(risk)) { risk <- data.frame( min_age = min(.data$age), From 39556ff1ab23910e0d33bfab7ee114a1b85c1c41 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:27:37 +0100 Subject: [PATCH 17/37] ensure .check_func_req_args errors with incorrect function argument number --- R/checkers.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/checkers.R b/R/checkers.R index 0fdefa6f..996cba0f 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -204,10 +204,16 @@ # using formals(args(fn)) to allow checking args of builtin primitives # for which formals(fn) would return NULL and cause the check to error # errors non-informatively for specials such as `if` - checkmate::test_function(func) && + valid_func <- checkmate::test_function(func) && sum(mapply(function(x, y) { # nolint undesirable function is.name(x) && y != "..." }, formals(args(func)), names(formals(args(func))))) == n_req_args + if (!valid_func) { + stop( + "Anonymous functions supplied must have ", n_req_args, " argument(s).", + call. = FALSE + ) + } } #' Cross check the onset-to-hospitalisation or -death arguments are From 19937760ae2014a11ccbaf82f45bf561723fb30a Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:34:32 +0100 Subject: [PATCH 18/37] added tests for .check_func_req_args --- tests/testthat/test-checkers.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/testthat/test-checkers.R b/tests/testthat/test-checkers.R index cab951fb..8710d9e0 100644 --- a/tests/testthat/test-checkers.R +++ b/tests/testthat/test-checkers.R @@ -444,3 +444,25 @@ test_that(".cross_check_sim_input warns as expected", { ) ) }) + +test_that(".check_func_req_args works as expected", { + expect_silent(.check_func_req_args(func = function(x) x + 1, n_req_args = 1)) + expect_null(.check_func_req_args(func = function(x) x + 1, n_req_args = 1)) +}) + +test_that(".check_func_req_args works with more than 1 req args", { + fn <- function(x, y) x + y + expect_silent(.check_func_req_args(func = fn, n_req_args = 2)) + expect_null(.check_func_req_args(func = fn, n_req_args = 2)) +}) + +test_that(".check_func_req_args fails as expected", { + expect_error( + .check_func_req_args(func = function(x) x + 1, n_req_args = 2), + regexp = "(Anonymous functions supplied must have)*(2)*(argument)" + ) + expect_error( + .check_func_req_args(func = function(x, y) x + y, n_req_args = 1), + regexp = "(Anonymous functions supplied must have)*(1)*(argument)" + ) +}) From 480e2e1ab6bc8461441f516c04fdba77042b2614 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:35:10 +0100 Subject: [PATCH 19/37] fixed time-varying death idx sampling --- R/add_cols.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/add_cols.R b/R/add_cols.R index 57e6fab3..27c694fa 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -152,7 +152,7 @@ NULL norm_prob_death[norm_prob_death > 1] <- 1 norm_prob_death[norm_prob_death < 0] <- 0 sampled_died <- stats::rbinom( - n = died_idx, + n = length(died_idx), size = 1, prob = norm_prob_death ) From fb9e328d09c4a43b95682dd5865daa7ba1af0cc5 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:35:22 +0100 Subject: [PATCH 20/37] updated WORDLIST --- inst/WORDLIST | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inst/WORDLIST b/inst/WORDLIST index 9be08749..32bcd2d2 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,14 +1,19 @@ +aes apyramid bookdown +bw +cfr CMD codecov Codecov com +config CoV COVID Ct ct db +df dist dplyr epi From 0cfd972500b189014b9e18001edb8d49fe8e1966 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:35:54 +0100 Subject: [PATCH 21/37] added nolint flags and echo expression to time-varying-cfr vignette ifelse --- vignettes/time-varying-cfr.Rmd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vignettes/time-varying-cfr.Rmd b/vignettes/time-varying-cfr.Rmd index fa9940c3..1c8e4235 100644 --- a/vignettes/time-varying-cfr.Rmd +++ b/vignettes/time-varying-cfr.Rmd @@ -284,10 +284,12 @@ In addition to a continuously varying case fatality risk function, the simulatio To achieve this, we again specify an anonymous function in `create_config()`, but have the risk of a case dying be equal to the `hosp_death_risk` and `non_hosp_death_risk` for the first 60 days of the outbreak and then become zero (i.e. if an individual is infected after day 60 they will definitely recover). -```{r, setup-time-varying-cfr-stepwise} +```{r, setup-time-varying-cfr-stepwise, echo=2} +# nolint start redundant_ifelse_linter ifelse used for consistency with other examples config <- create_config( time_varying_death_risk = function(x) ifelse(test = x < 60, yes = 1, no = 0) ) +# nolint end ``` ```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values from day 0 to day 60, and then become 0 onwards.", fig.width = 8, fig.height = 5} From bfcf571137605448866f0dc743c255617cf30cd9 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:36:38 +0100 Subject: [PATCH 22/37] added sim_linelist tests for time-varying cfr --- tests/testthat/test-sim_linelist.R | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/testthat/test-sim_linelist.R b/tests/testthat/test-sim_linelist.R index 7da1396f..7d71e37d 100644 --- a/tests/testthat/test-sim_linelist.R +++ b/tests/testthat/test-sim_linelist.R @@ -410,3 +410,57 @@ test_that("sim_linest date_death column is NA when onset_to_death is NA", { ) expect_true(all(is.na(ll$date_death))) }) + +test_that("sim_linelist works as expected with time-varying cfr", { + set.seed(1) + expect_snapshot( + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + config = create_config( + time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) + ) + ) + ) +}) + +test_that("sim_linelist works as expected with time-varying cfr & age-strat", { + set.seed(1) + age_dep_hosp_death_risk <- data.frame( + age_limit = c(1, 5, 80), + risk = c(0.1, 0.05, 0.2) + ) + expect_snapshot( + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + hosp_death_risk = age_dep_hosp_death_risk, + config = create_config( + time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) + ) + ) + ) +}) + +test_that("sim_linelist fails as expected with time-varying cfr", { + expect_error( + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + config = create_config( + time_varying_death_risk = function(x, y) dexp(x = x, rate = 0.05) + ) + ), + regexp = "(Anonymous functions supplied must have)*(1)*(argument)" + ) + +}) From 15b0b1b0a27c5275e12862e36f5f6f124d87ab37 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Tue, 16 Apr 2024 17:36:53 +0100 Subject: [PATCH 23/37] updated snapshots for sim_linelist tests --- tests/testthat/_snaps/sim_linelist.md | 116 +++++++++++++++++++++----- 1 file changed, 93 insertions(+), 23 deletions(-) diff --git a/tests/testthat/_snaps/sim_linelist.md b/tests/testthat/_snaps/sim_linelist.md index 7b4b5ae4..ca174b23 100644 --- a/tests/testthat/_snaps/sim_linelist.md +++ b/tests/testthat/_snaps/sim_linelist.md @@ -175,31 +175,31 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, hosp_risk = age_dep_hosp_risk, population_age = age_struct) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Taylor Swift probable m 44 2023-01-01 recovered - 2 2 Devion Thomas confirmed m 13 2023-01-01 recovered - 3 3 Dustin Bellow confirmed m 22 2023-01-01 recovered - 4 5 Shabaan el-Laham confirmed m 85 2023-01-01 2023-01-01 recovered - 5 6 Nadheera el-Wakim confirmed f 41 2023-01-01 recovered - 6 8 Mariah Makris confirmed f 89 2023-01-01 recovered - 7 11 Devyn Garcia Mayen confirmed m 69 2023-01-01 recovered - 8 12 Kaylynn Grip suspected f 23 2023-01-01 recovered - 9 13 Bryce Lehmkuhl probable m 9 2023-01-01 recovered - 10 18 Aaliyah Trent confirmed f 62 2023-01-02 recovered - 11 20 Ignacio Abeyta confirmed m 52 2023-01-02 recovered - 12 22 Tiffany Wolfchief probable f 76 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gene Than probable m 44 2023-01-01 recovered + 2 2 Caleb Fredericks probable m 13 2023-01-01 recovered + 3 3 Jaisean Venable suspected m 22 2023-01-01 recovered + 4 5 Taylor Swift probable m 85 2023-01-01 2023-01-01 recovered + 5 6 Korren Bailey confirmed f 41 2023-01-01 recovered + 6 8 Madison Zahn confirmed f 89 2023-01-01 recovered + 7 11 Dustin Bellow confirmed m 69 2023-01-01 recovered + 8 12 Ryanna Hart confirmed f 23 2023-01-01 recovered + 9 13 Rafael Garcia confirmed m 9 2023-01-01 recovered + 10 18 Ashlan Hendon confirmed f 62 2023-01-02 recovered + 11 20 Tieran Moorer suspected m 52 2023-01-02 recovered + 12 22 Paige Reich probable f 76 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA - 2 2022-12-30 2023-01-05 24.9 - 3 2022-12-30 2023-01-02 24.9 - 4 2022-12-29 2023-01-02 24.9 - 5 2023-01-01 2023-01-03 24.9 - 6 2023-01-03 2023-01-04 24.9 - 7 2023-01-04 2023-01-05 24.9 - 8 2023-01-01 2023-01-04 NA - 9 2022-12-31 2023-01-03 NA - 10 2022-12-30 2023-01-03 24.9 - 11 2023-01-01 2023-01-04 24.9 + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 24 + 6 2023-01-03 2023-01-04 24 + 7 2023-01-04 2023-01-05 24 + 8 2023-01-01 2023-01-04 24 + 9 2022-12-31 2023-01-03 24 + 10 2022-12-30 2023-01-03 24 + 11 2023-01-01 2023-01-04 NA 12 2023-01-01 2023-01-03 NA # sim_linelist works as expected with modified config @@ -271,3 +271,73 @@ 11 recovered 2023-01-04 2023-01-07 25.6 12 died 2023-01-16 2023-01-03 2023-01-05 NA +# sim_linelist works as expected with time-varying cfr + + Code + sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, + prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + config = create_config(time_varying_death_risk = function(x) dexp(x = x, + rate = 0.05))) + Output + id case_name case_type sex age date_onset date_admission + 1 1 Devyn Chavez probable m 35 2023-01-01 + 2 2 Bryce Cunniff confirmed m 43 2023-01-01 + 3 3 Ignacio Garcia Mayen confirmed m 1 2023-01-01 + 4 5 Jacob Kills In Sight probable m 78 2023-01-01 + 5 6 Tiffany Harrison confirmed f 22 2023-01-01 + 6 8 Caroline Hergenreter suspected f 28 2023-01-01 + 7 11 Khristopher Kelley probable m 46 2023-01-01 2023-01-13 + 8 12 Carolyn Moore confirmed f 67 2023-01-01 + 9 13 Tyler Carlson confirmed m 86 2023-01-01 2023-01-01 + 10 18 Chantelle Vazquez-Luevano confirmed f 60 2023-01-02 + 11 20 David Abeyta suspected m 49 2023-01-02 + 12 22 Megan Riggenbach confirmed f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered NA + 2 recovered 2022-12-30 2023-01-05 25 + 3 recovered 2022-12-30 2023-01-02 25 + 4 recovered 2022-12-29 2023-01-02 NA + 5 recovered 2023-01-01 2023-01-03 25 + 6 recovered 2023-01-03 2023-01-04 NA + 7 recovered 2023-01-04 2023-01-05 NA + 8 recovered 2023-01-01 2023-01-04 25 + 9 recovered 2022-12-31 2023-01-03 25 + 10 recovered 2022-12-30 2023-01-03 25 + 11 recovered 2023-01-01 2023-01-04 NA + 12 died 2023-01-15 2023-01-01 2023-01-03 25 + +# sim_linelist works as expected with time-varying cfr & age-strat + + Code + sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, + prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + hosp_death_risk = age_dep_hosp_death_risk, config = create_config( + time_varying_death_risk = function(x) dexp(x = x, rate = 0.05))) + Output + id case_name case_type sex age date_onset date_admission + 1 1 Bryce Lehmkuhl probable m 35 2023-01-01 + 2 2 Dennison Bellow confirmed m 43 2023-01-01 + 3 3 Damion Long suspected m 1 2023-01-01 + 4 5 Ignacio Garcia Mayen probable m 78 2023-01-01 + 5 6 Carolyn Moore confirmed f 22 2023-01-01 + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 + 7 11 David Abeyta confirmed m 46 2023-01-01 2023-01-13 + 8 12 Kendra To suspected f 67 2023-01-01 + 9 13 Morgan Kills In Sight confirmed m 86 2023-01-01 2023-01-01 + 10 18 Dominique Raymond confirmed f 60 2023-01-02 + 11 20 Jackson Peterson probable m 49 2023-01-02 + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered NA + 2 recovered 2022-12-30 2023-01-05 24 + 3 recovered 2022-12-30 2023-01-02 NA + 4 recovered 2022-12-29 2023-01-02 NA + 5 recovered 2023-01-01 2023-01-03 24 + 6 recovered 2023-01-03 2023-01-04 24 + 7 recovered 2023-01-04 2023-01-05 24 + 8 recovered 2023-01-01 2023-01-04 NA + 9 recovered 2022-12-31 2023-01-03 24 + 10 recovered 2022-12-30 2023-01-03 24 + 11 recovered 2023-01-01 2023-01-04 NA + 12 recovered 2023-01-01 2023-01-03 NA + From a50d3bbe8f41388a09d2c2bcab27db84fa8507ab Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 19 Apr 2024 11:30:32 +0100 Subject: [PATCH 24/37] added comments to .add_outcome --- R/add_cols.R | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/R/add_cols.R b/R/add_cols.R index 27c694fa..12443ad5 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -134,23 +134,30 @@ NULL hosp_idx <- !is.na(.data$hospitalisation) & infected_idx non_hosp_idx <- is.na(.data$hospitalisation) & infected_idx - # define functions used only by .add_outcome + # internal function only called in .add_outcome() (by apply_death_risk()) + # deaths are sampled in apply_death_risk() before calling time_varying_risk() + # time_varying_risk() subset deaths given time-varying death risk time_varying_risk <- function(.data, died_idx, config) { # check time-varying function .check_func_req_args(config$time_varying_death_risk) - # sample which deaths to keep with time-varying risk + # evaluate time-varying death risk function for each infection time of an + # individual that is sampled to die prob_death <- config$time_varying_death_risk(.data$time[died_idx]) + # determine maximum possible value of the time-varying death risk function max_prob_death <- stats::optimise( f = config$time_varying_death_risk, interval = c(0, 100), maximum = TRUE )$objective + # normalise probability of death to ensure values are [0, 1] + # used as probabilities for binomial sampling norm_prob_death <- prob_death / max_prob_death # set all values > 1 and < 0 to 1 and 0 due to imprecision of optimise # TODO: ideally this step would be removed as no values are 0 > x < 1 norm_prob_death[norm_prob_death > 1] <- 1 norm_prob_death[norm_prob_death < 0] <- 0 + # sample which deaths are kept using normalised probability of death sampled_died <- stats::rbinom( n = length(died_idx), size = 1, @@ -163,6 +170,9 @@ NULL died_idx } + # internal function only called in .add_outcome() + # assign deaths using population or age-stratified death risk + # if risk is NA then no deaths are assigned apply_death_risk <- function(.data, risk, idx, config) { if (!is_na(risk)) { # single population risk is a special case of the age-strat risk @@ -174,6 +184,7 @@ NULL risk = risk ) } + # loop through each age group and sample which cases die for (i in seq_len(nrow(risk))) { age_bracket <- risk$min_age[i]:risk$max_age[i] age_group_idx <- which(.data$age %in% age_bracket & idx) @@ -184,6 +195,7 @@ NULL size = risk$risk[i] * length(age_group_idx) ) if (is.function(config$time_varying_death_risk)) { + # subset sampled deaths with time-varying death risk function died_idx <- time_varying_risk( .data, died_idx = died_idx, From c44b26c58f6d131a06da2c31cb43375f5cfd8851 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 19 Apr 2024 12:12:54 +0100 Subject: [PATCH 25/37] update time_varying_death_risk default in create_config to NULL --- R/create_config.R | 4 ++-- man/create_config.Rd | 2 +- vignettes/time-varying-cfr.Rmd | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/create_config.R b/R/create_config.R index 4bfce12a..107b88b2 100644 --- a/R/create_config.R +++ b/R/create_config.R @@ -15,7 +15,7 @@ #' * `ct_distribution = "norm"` #' * `ct_distribution_params = c(mean = 25, sd = 2)` #' * `network = "adjusted"` -#' * `time_varying_death_risk = NA` +#' * `time_varying_death_risk = NULL` #' #' These parameters do not warrant their own arguments in #' [sim_linelist()] as they rarely need to be changed from their default @@ -60,7 +60,7 @@ create_config <- function(...) { ct_distribution = "norm", ct_distribution_params = c(mean = 25, sd = 2), network = "adjusted", - time_varying_death_risk = NA + time_varying_death_risk = NULL ) # capture dynamic dots diff --git a/man/create_config.Rd b/man/create_config.Rd index f2a3ecc2..291c4ecb 100644 --- a/man/create_config.Rd +++ b/man/create_config.Rd @@ -34,7 +34,7 @@ Accepted arguments and their defaults are: \item \code{ct_distribution = "norm"} \item \code{ct_distribution_params = c(mean = 25, sd = 2)} \item \code{network = "adjusted"} -\item \code{time_varying_death_risk = NA} +\item \code{time_varying_death_risk = NULL} } These parameters do not warrant their own arguments in diff --git a/vignettes/time-varying-cfr.Rmd b/vignettes/time-varying-cfr.Rmd index 1c8e4235..08b99e60 100644 --- a/vignettes/time-varying-cfr.Rmd +++ b/vignettes/time-varying-cfr.Rmd @@ -87,7 +87,7 @@ set.seed(1) ## Constant case fatality risk -When calling the `create_config()` function the default output contains a list element named `time_varying_death_risk` set to `NA`. This corresponds to a constant case fatality risk over time, which is controlled by the `hosp_death_risk` and `non_hosp_death_risk` arguments. The defaults for these two arguments are: +When calling the `create_config()` function the default output contains a list element named `time_varying_death_risk` set to `NULL`. This corresponds to a constant case fatality risk over time, which is controlled by the `hosp_death_risk` and `non_hosp_death_risk` arguments. The defaults for these two arguments are: * death risk when hospitalised (`hosp_death_risk`): `0.5` (50%) * death risk outside of hospitals (`non_hosp_death_risk`): `0.05` (5%) From c7727d790f5107e5e8f2bfb62537a9efbde34872 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 19 Apr 2024 12:26:42 +0100 Subject: [PATCH 26/37] explicitly add number of required args in .check.func_req_args call in time_varying_risk --- R/add_cols.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/add_cols.R b/R/add_cols.R index 12443ad5..3e0a5311 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -139,7 +139,7 @@ NULL # time_varying_risk() subset deaths given time-varying death risk time_varying_risk <- function(.data, died_idx, config) { # check time-varying function - .check_func_req_args(config$time_varying_death_risk) + .check_func_req_args(config$time_varying_death_risk, n_req_args = 1) # evaluate time-varying death risk function for each infection time of an # individual that is sampled to die From 3d3745989be5c515d73bdeebb7f1c3d5667af889 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 22 Apr 2024 17:35:57 +0100 Subject: [PATCH 27/37] simplify time-varying cfr and remove time_varying_risk internal function --- R/add_cols.R | 71 ++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/R/add_cols.R b/R/add_cols.R index 3e0a5311..520f711b 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -134,42 +134,6 @@ NULL hosp_idx <- !is.na(.data$hospitalisation) & infected_idx non_hosp_idx <- is.na(.data$hospitalisation) & infected_idx - # internal function only called in .add_outcome() (by apply_death_risk()) - # deaths are sampled in apply_death_risk() before calling time_varying_risk() - # time_varying_risk() subset deaths given time-varying death risk - time_varying_risk <- function(.data, died_idx, config) { - # check time-varying function - .check_func_req_args(config$time_varying_death_risk, n_req_args = 1) - - # evaluate time-varying death risk function for each infection time of an - # individual that is sampled to die - prob_death <- config$time_varying_death_risk(.data$time[died_idx]) - # determine maximum possible value of the time-varying death risk function - max_prob_death <- stats::optimise( - f = config$time_varying_death_risk, - interval = c(0, 100), - maximum = TRUE - )$objective - # normalise probability of death to ensure values are [0, 1] - # used as probabilities for binomial sampling - norm_prob_death <- prob_death / max_prob_death - # set all values > 1 and < 0 to 1 and 0 due to imprecision of optimise - # TODO: ideally this step would be removed as no values are 0 > x < 1 - norm_prob_death[norm_prob_death > 1] <- 1 - norm_prob_death[norm_prob_death < 0] <- 0 - # sample which deaths are kept using normalised probability of death - sampled_died <- stats::rbinom( - n = length(died_idx), - size = 1, - prob = norm_prob_death - ) - # subset deaths given sampling (logical conversion for vec subsetting) - died_idx <- died_idx[as.logical(sampled_died)] - - # return sample of deaths - died_idx - } - # internal function only called in .add_outcome() # assign deaths using population or age-stratified death risk # if risk is NA then no deaths are assigned @@ -188,20 +152,33 @@ NULL for (i in seq_len(nrow(risk))) { age_bracket <- risk$min_age[i]:risk$max_age[i] age_group_idx <- which(.data$age %in% age_bracket & idx) - # size is converted to an integer internally in sample() - died_idx <- sample( - age_group_idx, - replace = FALSE, - size = risk$risk[i] * length(age_group_idx) - ) + if (is.function(config$time_varying_death_risk)) { - # subset sampled deaths with time-varying death risk function - died_idx <- time_varying_risk( - .data, - died_idx = died_idx, - config = config + .check_func_req_args(config$time_varying_death_risk, n_req_args = 2) + risk_ <- config$time_varying_death_risk( + risk = risk$risk[i], + time = .data$time[age_group_idx] ) + valid_risk <- checkmate::test_numeric( + risk_, + lower = 0, + upper = 1, + any.missing = FALSE + ) + if (!valid_risk) { + stop( + "Time-varying death risk outside [0,1]. \n", + "Check time-varying function.", + call. = FALSE + ) + } + } else { + risk_ <- rep(risk$risk[i], times = length(age_group_idx)) } + + # sample individuals in the risk category (e.g. hosp) to die given risk + died_idx <- stats::rbinom(n = length(risk_), size = 1, prob = risk_) + died_idx <- age_group_idx[as.logical(died_idx)] .data$outcome[died_idx] <- "died" .data$outcome_time[died_idx] <- .data$time[died_idx] + onset_to_death(length(died_idx)) From be7dfb5f7c46fff5b7118e0ef9c4d2739037aa10 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 22 Apr 2024 17:36:22 +0100 Subject: [PATCH 28/37] add lower and upper bound checks for *_risk arguments --- R/checkers.R | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/R/checkers.R b/R/checkers.R index 996cba0f..50efdc83 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -160,15 +160,23 @@ "The values in the case_type_prob vector must sum to 1" = sum(case_type_probs) == 1, "hosp_risk must be a single numeric or a data.frame" = - is.numeric(hosp_risk) && length(hosp_risk) == 1 || - is.data.frame(hosp_risk) || is_na(hosp_risk), + is.numeric(hosp_risk) || is.data.frame(hosp_risk) || is_na(hosp_risk), "hosp_death_risk must be a single numeric or a data.frame" = - is.numeric(hosp_death_risk) && length(hosp_death_risk) == 1 || - is.data.frame(hosp_death_risk) || is_na(hosp_death_risk), + is.numeric(hosp_death_risk) || is.data.frame(hosp_death_risk) || + is_na(hosp_death_risk), "non_hosp_death_risk must be a single numeric or a data.frame" = - is.numeric(non_hosp_death_risk) && length(non_hosp_death_risk) == 1 || - is.data.frame(non_hosp_death_risk) || is_na(non_hosp_death_risk) + is.numeric(non_hosp_death_risk) || is.data.frame(non_hosp_death_risk) || + is_na(non_hosp_death_risk) ) + if (is.numeric(hosp_risk)) { + checkmate::assert_number(hosp_risk, lower = 0, upper = 1) + } + if (is.numeric(hosp_death_risk)) { + checkmate::assert_number(hosp_death_risk, lower = 0, upper = 1) + } + if (is.numeric(non_hosp_death_risk)) { + checkmate::assert_number(non_hosp_death_risk, lower = 0, upper = 1) + } } if (sim_type %in% c("contacts", "outbreak")) { From 04b5fc2eb78f193c8bfae8be4a7464d826cfc0ba Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 22 Apr 2024 17:37:00 +0100 Subject: [PATCH 29/37] updated time-varying-cfr vignette to use new time_varying_death_risk function signature --- vignettes/time-varying-cfr.Rmd | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/vignettes/time-varying-cfr.Rmd b/vignettes/time-varying-cfr.Rmd index 08b99e60..b7f20b79 100644 --- a/vignettes/time-varying-cfr.Rmd +++ b/vignettes/time-varying-cfr.Rmd @@ -22,7 +22,7 @@ knitr::opts_chunk$set( If you are unfamiliar with the {simulist} package or the `sim_linelist()` function [Get Started vignette](simulist.html) is a great place to start. ::: -This vignette demonstrates how to simulate line list data using the time-varying case fatality risk and gives an overview of the methodologically details. +This vignette demonstrates how to simulate line list data using the time-varying case fatality risk and gives an overview of the methodological details. ::: {.alert .alert-secondary} @@ -199,22 +199,22 @@ plot(daily) Now we've seen what the constant case fatality risk simulations look like, we can simulate with a time-varying function for the risk. -This is setup by calling the `create_config()` function, and providing an anonymous function with a single argument to `time_varying_death_risk` for the time of the simulation which maps to a probability, propensity or risk scaling factor at each time value. +This is setup by calling the `create_config()` function, and providing an anonymous function with two arguments, `risk` and `time`, to `time_varying_death_risk`. This function will then use the relevant risk (e.g. `hosp_death_risk`) and the time an individual is infected and calculates the probability (or risk) of death. The `create_config()` function has no named arguments, and the argument you are modifying needs to be matched by name exactly (case sensitive). See `?create_config()` for documentation. ```{r, setup-time-varying-cfr} config <- create_config( - time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) + time_varying_death_risk = function(risk, time) risk * exp(-0.05 * time) ) ``` -Here we set the case fatality risk to exponentially decrease through time at a rate ($\lambda$) of 0.05. This will provide a shallow (monotonic) decline of case fatality through the simulated epidemic. +Here we set the case fatality risk to exponentially decrease through time. This will provide a shallow (monotonic) decline of case fatality through the simulated epidemic. -```{r, plot-exponential-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values at day 0 and decline through time, with risk approaching zero at around day 100.", fig.width = 8, fig.height = 5} +```{r, plot-exponential-dist, class.source = 'fold-hide', fig.cap="The time-varying hospitalised case fatality risk function (`config$time_varying_death_risk`) throughout the epidemic. In this case the hospitalised risks (`hosp_death_risk`) are at their maximum value at day 0 and decline through time, with risk approaching zero at around day 100.", fig.width = 8, fig.height = 5} exp_df <- data.frame( time = 1:150, - value = config$time_varying_death_risk(1:150) + value = config$time_varying_death_risk(risk = 0.9, time = 1:150) ) ggplot(exp_df) + geom_point(mapping = aes(x = time, y = value)) + @@ -227,12 +227,10 @@ ggplot(exp_df) + _Advanced_ -The time-varying case fatality risk function reduces the death risk specified by `hosp_death_risk` and `non_hosp_death_risk`, in such as a way that the risks (`*_risk`) given by the user now operate as the maximum risk. The maximum values of the user-supplied time-varying function is the same as the risks specified. +The time-varying case fatality risk function modifies the the death risk specified by `hosp_death_risk` and `non_hosp_death_risk`. In this example, the user-supplied `hosp_death_risk` and `non_hosp_death_risk` are the maximum values, because the user-supplied time-varying function is declining over time, however, a user-supplied function may also increase over time, or fluctuate. The requirements are that the time-varying case fatality risk for both hospitalised and non-hospitalised infections must be between 0 and 1, otherwise the function will error. In the example below `hosp_death_risk` is `0.9` and `non_hosp_death_risk` is `0.75`, and the time-varying case fatality risk function is an exponential decline. This means that on day 0 of the epidemic (i.e. first infection seeds the outbreak) the risks will be `0.9` and `0.75`. But any time after the start of the epidemic ($t_0 + \Delta t$) the risks will be lower, and when the exponential function approaches zero the risk of a case dying will also go to zero. -The time-varying function supplied to `create_config(time_varying_death_risk = )` does not need to evaluate to between 0 and 1 because internally the function is normalised. - ::: Simulating with the time-varying case fatality risk: @@ -265,7 +263,7 @@ linelist <- linelist %>% ) ``` -```{r, plot-onset-death-time-varying-cfr, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. The maximum case fatality risk for hospitalised individuals is 0.9 and for non-hospitalised individuals is 0.75, and these decline exponentially through time.", fig.width = 8, fig.height = 5} +```{r, plot-onset-death-time-varying-cfr, fig.cap="Daily incidence of cases from symptom onset and incidence of deaths. The baseline case fatality risk for hospitalised individuals is 0.9 and for non-hospitalised individuals is 0.75, and these decline exponentially through time.", fig.width = 8, fig.height = 5} daily <- incidence( linelist, date_index = c( @@ -282,20 +280,20 @@ plot(daily) In addition to a continuously varying case fatality risk function, the simulation can also work with stepwise (or piecewise) functions. This is where the risk will instantaneously change at a given point in time to another risk level. -To achieve this, we again specify an anonymous function in `create_config()`, but have the risk of a case dying be equal to the `hosp_death_risk` and `non_hosp_death_risk` for the first 60 days of the outbreak and then become zero (i.e. if an individual is infected after day 60 they will definitely recover). +To achieve this, we again specify an anonymous function in `create_config()`, but have the risk of a case dying set as the baseline `hosp_death_risk` and `non_hosp_death_risk` for the first 60 days of the outbreak and then become zero (i.e. if an individual is infected after day 60 they will definitely recover). ```{r, setup-time-varying-cfr-stepwise, echo=2} # nolint start redundant_ifelse_linter ifelse used for consistency with other examples config <- create_config( - time_varying_death_risk = function(x) ifelse(test = x < 60, yes = 1, no = 0) + time_varying_death_risk = function(risk, time) ifelse(test = time < 60, yes = risk, no = 0) ) # nolint end ``` -```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values from day 0 to day 60, and then become 0 onwards.", fig.width = 8, fig.height = 5} +```{r, plot-stepwise-dist, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) for the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their user-supplied values from day 0 to day 60, and then become 0 onwards.", fig.width = 8, fig.height = 5} stepwise_df <- data.frame( time = 1:150, - value = config$time_varying_death_risk(1:150) + value = config$time_varying_death_risk(risk = 0.9, time = 1:150) ) ggplot(stepwise_df) + geom_point(mapping = aes(x = time, y = value)) + @@ -347,12 +345,12 @@ daily <- complete_dates(daily) plot(daily) ``` -The same stepwise function can also be used to specify time windows were the risk of death is reduced. Here we specify the risk of death is equal to the `hosp_death_risk` and `non_hosp_death_risk` in the first 50 days of the epidemic, then between day 50 and day 100 the risk is reduced by half, and then from day 100 onwards the risk goes back to the rates specified by `hosp_death_risk` and `non_hosp_death_risk`. +The same stepwise function can also be used to specify time windows were the risk of death is reduced. Here we specify the `hosp_death_risk` and `non_hosp_death_risk` in the first 50 days of the epidemic, then between day 50 and day 100 the risk is reduced by half, and then from day 100 onwards the risk goes back to the rates specified by `hosp_death_risk` and `non_hosp_death_risk`. ```{r, setup-time-varying-cfr-stepwise-window} config <- create_config( - time_varying_death_risk = function(x) { - ifelse(test = x > 50 & x < 100, yes = 0.5, no = 1) + time_varying_death_risk = function(risk, time) { + ifelse(test = time > 50 & time < 100, yes = risk * 0.5, no = risk) } ) ``` @@ -360,7 +358,7 @@ config <- create_config( ```{r, plot-stepwise-dist-window, class.source = 'fold-hide', fig.cap="The time-varying case fatality risk function (`config$time_varying_death_risk`) which scales the hospitalised death risk (`hosp_death_risk`) and non-hospitalised death risk (`non_hosp_death_risk`) throughout the epidemic. In this case the risks are at their maximum, user-supplied, values from day 0 to day 50, and then half the risks from day 50 to day 100, and then return to their maximum value from day 100 onwards.", fig.width = 8, fig.height = 5} stepwise_df <- data.frame( time = 1:150, - value = config$time_varying_death_risk(1:150) + value = config$time_varying_death_risk(risk = 0.9, time = 1:150) ) ggplot(stepwise_df) + geom_point(mapping = aes(x = time, y = value)) + From e2c1c148cc1b115e5194b7d3f79f5e81564f557d Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 22 Apr 2024 17:38:04 +0100 Subject: [PATCH 30/37] updated sim_linelist tests and snapshots for updated time-varying cfr --- tests/testthat/_snaps/sim_linelist.md | 452 +++++++++++++------------- tests/testthat/test-sim_linelist.R | 22 +- 2 files changed, 243 insertions(+), 231 deletions(-) diff --git a/tests/testthat/_snaps/sim_linelist.md b/tests/testthat/_snaps/sim_linelist.md index ca174b23..ce75f02d 100644 --- a/tests/testthat/_snaps/sim_linelist.md +++ b/tests/testthat/_snaps/sim_linelist.md @@ -4,32 +4,32 @@ sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death) Output - id case_name case_type sex age date_onset date_admission - 1 1 Damion Hamm confirmed m 35 2023-01-01 - 2 2 Ignacio Hernandez confirmed m 43 2023-01-01 - 3 3 Bryce Donnelly confirmed m 1 2023-01-01 - 4 5 David Arrieta confirmed m 78 2023-01-01 - 5 6 Kristina Vazquez Pallares confirmed f 22 2023-01-01 - 6 8 Nusaiba el-Farah suspected f 28 2023-01-01 - 7 11 Dominic Kills In Sight probable m 46 2023-01-01 2023-01-13 - 8 12 Violet Watts confirmed f 67 2023-01-01 - 9 13 Khristopher Cunniff confirmed m 86 2023-01-01 2023-01-01 - 10 18 Paige Reich probable f 60 2023-01-02 - 11 20 Jackson Carlson confirmed m 49 2023-01-02 - 12 22 Cassandra Smith suspected f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered 25.6 - 2 recovered 2022-12-30 2023-01-05 25.6 - 3 recovered 2022-12-30 2023-01-02 25.6 - 4 recovered 2022-12-29 2023-01-02 25.6 - 5 recovered 2023-01-01 2023-01-03 25.6 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25.6 - 9 recovered 2022-12-31 2023-01-03 25.6 - 10 recovered 2022-12-30 2023-01-03 NA - 11 recovered 2023-01-01 2023-01-04 25.6 - 12 died 2023-01-16 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gabriel Black probable m 35 2023-01-01 recovered + 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered + 3 3 Cody Morales suspected m 1 2023-01-01 recovered + 4 5 Joewid Le probable m 78 2023-01-01 recovered + 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered + 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered + 8 12 Kendra To suspected f 67 2023-01-01 recovered + 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died + 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered + 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 24 + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 24 + 6 2023-01-03 2023-01-04 24 + 7 2023-01-04 2023-01-05 24 + 8 2023-01-01 2023-01-04 NA + 9 2023-01-09 2022-12-31 2023-01-03 24 + 10 2022-12-30 2023-01-03 24 + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 NA # sim_linelist works as expected with age-strat risks @@ -39,32 +39,32 @@ hosp_risk = age_dep_hosp_risk, hosp_death_risk = age_dep_hosp_death_risk, non_hosp_death_risk = age_dep_non_hosp_death_risk) Output - id case_name case_type sex age date_onset date_admission - 1 1 David Garcia Mayen probable m 35 2023-01-01 - 2 2 Rory Kills In Sight confirmed m 43 2023-01-01 - 3 3 Sheldon Martinez confirmed m 1 2023-01-01 2023-01-11 - 4 5 Bryce Cunniff probable m 78 2023-01-01 - 5 6 Lien Whitworth confirmed f 22 2023-01-01 - 6 8 Tiffany Weiss suspected f 28 2023-01-01 - 7 11 Cleatus Kacprowicz probable m 46 2023-01-01 - 8 12 Taylor Moore confirmed f 67 2023-01-01 - 9 13 Tyler Carlson confirmed m 86 2023-01-01 2023-01-01 - 10 18 Grayson Lovelace confirmed f 60 2023-01-02 - 11 20 Abdul Maalik al-Ishak suspected m 49 2023-01-02 2023-01-09 - 12 22 Kendra Newton confirmed f 7 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered NA - 2 recovered 2022-12-30 2023-01-05 25 - 3 recovered 2022-12-30 2023-01-02 25 - 4 recovered 2022-12-29 2023-01-02 NA - 5 recovered 2023-01-01 2023-01-03 25 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25 - 9 recovered 2022-12-31 2023-01-03 25 - 10 recovered 2022-12-30 2023-01-03 25 - 11 recovered 2023-01-01 2023-01-04 NA - 12 recovered 2023-01-01 2023-01-03 25 + id case_name case_type sex age date_onset date_admission outcome + 1 1 Micheal Smallwood probable m 35 2023-01-01 recovered + 2 2 Kyle Foster confirmed m 43 2023-01-01 recovered + 3 3 Ghaamid el-Kaiser suspected m 1 2023-01-01 2023-01-11 died + 4 5 Faatih el-Riaz confirmed m 78 2023-01-01 recovered + 5 6 Hope Arshad suspected f 22 2023-01-01 recovered + 6 8 Shanta Holiday probable f 28 2023-01-01 recovered + 7 11 Aiman al-Demian probable m 46 2023-01-01 recovered + 8 12 Chandra Kilian suspected f 67 2023-01-01 recovered + 9 13 Wajdi el-Diab confirmed m 86 2023-01-01 2023-01-01 recovered + 10 18 Kanani Nguyen confirmed f 60 2023-01-02 recovered + 11 20 Raaid el-Vaziri probable m 49 2023-01-02 2023-01-09 recovered + 12 22 Annie Carter probable f 7 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 24.1 + 3 2023-01-14 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 24.1 + 5 2023-01-01 2023-01-03 NA + 6 2023-01-03 2023-01-04 NA + 7 2023-01-04 2023-01-05 NA + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 24.1 + 10 2022-12-30 2023-01-03 24.1 + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 NA # sim_linelist works as expected without Ct @@ -73,32 +73,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, add_ct = FALSE) Output - id case_name case_type sex age date_onset date_admission - 1 1 Damion Hamm confirmed m 35 2023-01-01 - 2 2 Ignacio Hernandez confirmed m 43 2023-01-01 - 3 3 Bryce Donnelly confirmed m 1 2023-01-01 - 4 5 David Arrieta confirmed m 78 2023-01-01 - 5 6 Kristina Vazquez Pallares confirmed f 22 2023-01-01 - 6 8 Nusaiba el-Farah suspected f 28 2023-01-01 - 7 11 Dominic Kills In Sight probable m 46 2023-01-01 2023-01-13 - 8 12 Violet Watts confirmed f 67 2023-01-01 - 9 13 Khristopher Cunniff confirmed m 86 2023-01-01 2023-01-01 - 10 18 Paige Reich probable f 60 2023-01-02 - 11 20 Jackson Carlson confirmed m 49 2023-01-02 - 12 22 Cassandra Smith suspected f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact - 1 recovered - 2 recovered 2022-12-30 2023-01-05 - 3 recovered 2022-12-30 2023-01-02 - 4 recovered 2022-12-29 2023-01-02 - 5 recovered 2023-01-01 2023-01-03 - 6 recovered 2023-01-03 2023-01-04 - 7 recovered 2023-01-04 2023-01-05 - 8 recovered 2023-01-01 2023-01-04 - 9 recovered 2022-12-31 2023-01-03 - 10 recovered 2022-12-30 2023-01-03 - 11 recovered 2023-01-01 2023-01-04 - 12 died 2023-01-16 2023-01-01 2023-01-03 + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gabriel Black probable m 35 2023-01-01 recovered + 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered + 3 3 Cody Morales suspected m 1 2023-01-01 recovered + 4 5 Joewid Le probable m 78 2023-01-01 recovered + 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered + 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered + 8 12 Kendra To suspected f 67 2023-01-01 recovered + 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died + 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered + 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact + 1 + 2 2022-12-30 2023-01-05 + 3 2022-12-30 2023-01-02 + 4 2022-12-29 2023-01-02 + 5 2023-01-01 2023-01-03 + 6 2023-01-03 2023-01-04 + 7 2023-01-04 2023-01-05 + 8 2023-01-01 2023-01-04 + 9 2023-01-09 2022-12-31 2023-01-03 + 10 2022-12-30 2023-01-03 + 11 2023-01-01 2023-01-04 + 12 2023-01-01 2023-01-03 # sim_linelist works as expected with anonymous @@ -109,30 +109,30 @@ Output id case_type sex age date_onset date_admission outcome date_outcome 1 1 confirmed m 35 2023-01-01 recovered - 2 2 confirmed m 43 2023-01-01 recovered - 3 3 confirmed m 1 2023-01-01 recovered + 2 2 probable m 43 2023-01-01 recovered + 3 3 probable m 1 2023-01-01 recovered 4 5 confirmed m 78 2023-01-01 recovered - 5 6 suspected f 22 2023-01-01 recovered - 6 8 probable f 28 2023-01-01 recovered + 5 6 confirmed f 22 2023-01-01 recovered + 6 8 confirmed f 28 2023-01-01 recovered 7 11 confirmed m 46 2023-01-01 2023-01-13 recovered 8 12 confirmed f 67 2023-01-01 recovered - 9 13 probable m 86 2023-01-01 2023-01-01 recovered - 10 18 probable f 60 2023-01-02 recovered + 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-09 + 10 18 confirmed f 60 2023-01-02 recovered 11 20 confirmed m 49 2023-01-02 recovered - 12 22 confirmed f 7 2023-01-02 2023-01-02 died 2023-01-16 + 12 22 confirmed f 7 2023-01-02 2023-01-02 recovered date_first_contact date_last_contact ct_value - 1 25.7 - 2 2022-12-30 2023-01-05 25.7 - 3 2022-12-30 2023-01-02 25.7 - 4 2022-12-29 2023-01-02 25.7 - 5 2023-01-01 2023-01-03 NA - 6 2023-01-03 2023-01-04 NA - 7 2023-01-04 2023-01-05 25.7 - 8 2023-01-01 2023-01-04 25.7 - 9 2022-12-31 2023-01-03 NA - 10 2022-12-30 2023-01-03 NA - 11 2023-01-01 2023-01-04 25.7 - 12 2023-01-01 2023-01-03 25.7 + 1 24.9 + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 24.9 + 5 2023-01-01 2023-01-03 24.9 + 6 2023-01-03 2023-01-04 24.9 + 7 2023-01-04 2023-01-05 24.9 + 8 2023-01-01 2023-01-04 24.9 + 9 2022-12-31 2023-01-03 24.9 + 10 2022-12-30 2023-01-03 24.9 + 11 2023-01-01 2023-01-04 24.9 + 12 2023-01-01 2023-01-03 24.9 # sim_linelist works as expected with age structure @@ -140,58 +140,24 @@ sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, population_age = age_struct) - Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Mark Beard confirmed m 44 2023-01-01 recovered - 2 2 Brian Mccracken confirmed m 13 2023-01-01 recovered - 3 3 Jesus Garduno confirmed m 22 2023-01-01 2023-01-09 died - 4 5 Taalib al-Naqvi confirmed m 85 2023-01-01 recovered - 5 6 Kelly Geist confirmed f 41 2023-01-01 recovered - 6 8 Madison Krause suspected f 89 2023-01-01 2023-01-02 recovered - 7 11 Jonathon Lujano probable m 69 2023-01-01 recovered - 8 12 Ashlan Allen confirmed f 23 2023-01-01 recovered - 9 13 Dhaahir el-Hariri confirmed m 9 2023-01-01 recovered - 10 18 Korren Hart probable f 62 2023-01-02 recovered - 11 20 Isaac Huff confirmed m 52 2023-01-02 2023-01-15 recovered - 12 22 Ryanna Watts suspected f 76 2023-01-02 recovered - date_outcome date_first_contact date_last_contact ct_value - 1 25.6 - 2 2022-12-30 2023-01-05 25.6 - 3 2023-01-09 2022-12-30 2023-01-02 25.6 - 4 2022-12-29 2023-01-02 25.6 - 5 2023-01-01 2023-01-03 25.6 - 6 2023-01-03 2023-01-04 NA - 7 2023-01-04 2023-01-05 NA - 8 2023-01-01 2023-01-04 25.6 - 9 2022-12-31 2023-01-03 25.6 - 10 2022-12-30 2023-01-03 NA - 11 2023-01-01 2023-01-04 25.6 - 12 2023-01-01 2023-01-03 NA - -# sim_linelist works as expected with age-strat risks & age struct - - Code - sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, - prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, - hosp_risk = age_dep_hosp_risk, population_age = age_struct) Output id case_name case_type sex age date_onset date_admission outcome 1 1 Gene Than probable m 44 2023-01-01 recovered 2 2 Caleb Fredericks probable m 13 2023-01-01 recovered - 3 3 Jaisean Venable suspected m 22 2023-01-01 recovered - 4 5 Taylor Swift probable m 85 2023-01-01 2023-01-01 recovered + 3 3 Jaisean Venable suspected m 22 2023-01-01 2023-01-09 died + 4 5 Taylor Swift probable m 85 2023-01-01 recovered 5 6 Korren Bailey confirmed f 41 2023-01-01 recovered - 6 8 Madison Zahn confirmed f 89 2023-01-01 recovered + 6 8 Madison Zahn confirmed f 89 2023-01-01 2023-01-02 recovered 7 11 Dustin Bellow confirmed m 69 2023-01-01 recovered 8 12 Ryanna Hart confirmed f 23 2023-01-01 recovered 9 13 Rafael Garcia confirmed m 9 2023-01-01 recovered 10 18 Ashlan Hendon confirmed f 62 2023-01-02 recovered - 11 20 Tieran Moorer suspected m 52 2023-01-02 recovered + 11 20 Tieran Moorer suspected m 52 2023-01-02 2023-01-15 recovered 12 22 Paige Reich probable f 76 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA 2 2022-12-30 2023-01-05 NA - 3 2022-12-30 2023-01-02 NA + 3 2023-01-12 2022-12-30 2023-01-02 NA 4 2022-12-29 2023-01-02 NA 5 2023-01-01 2023-01-03 24 6 2023-01-03 2023-01-04 24 @@ -202,6 +168,40 @@ 11 2023-01-01 2023-01-04 NA 12 2023-01-01 2023-01-03 NA +# sim_linelist works as expected with age-strat risks & age struct + + Code + sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, + prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + hosp_risk = age_dep_hosp_risk, population_age = age_struct) + Output + id case_name case_type sex age date_onset date_admission + 1 1 Damion Hamm confirmed m 44 2023-01-01 + 2 2 Ignacio Hernandez confirmed m 13 2023-01-01 + 3 3 Bryce Donnelly confirmed m 22 2023-01-01 + 4 5 David Arrieta confirmed m 85 2023-01-01 2023-01-01 + 5 6 Kristina Vazquez Pallares confirmed f 41 2023-01-01 + 6 8 Nusaiba el-Farah suspected f 89 2023-01-01 + 7 11 Dominic Kills In Sight probable m 69 2023-01-01 + 8 12 Violet Watts confirmed f 23 2023-01-01 + 9 13 Khristopher Cunniff confirmed m 9 2023-01-01 + 10 18 Paige Reich probable f 62 2023-01-02 + 11 20 Jackson Carlson confirmed m 52 2023-01-02 + 12 22 Cassandra Smith suspected f 76 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered 25.6 + 2 recovered 2022-12-30 2023-01-05 25.6 + 3 recovered 2022-12-30 2023-01-02 25.6 + 4 died 2023-01-25 2022-12-29 2023-01-02 25.6 + 5 recovered 2023-01-01 2023-01-03 25.6 + 6 recovered 2023-01-03 2023-01-04 NA + 7 recovered 2023-01-04 2023-01-05 NA + 8 recovered 2023-01-01 2023-01-04 25.6 + 9 recovered 2022-12-31 2023-01-03 25.6 + 10 recovered 2022-12-30 2023-01-03 NA + 11 recovered 2023-01-01 2023-01-04 25.6 + 12 recovered 2023-01-01 2023-01-03 NA + # sim_linelist works as expected with modified config Code @@ -210,32 +210,32 @@ config = create_config(last_contact_distribution = "geom", last_contact_distribution_params = c(prob = 0.5))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Lilibeth Depoyster suspected f 20 2023-01-01 - 2 2 Mubarak el-Othman confirmed m 24 2023-01-01 - 3 3 Tae Woo Karman confirmed m 51 2023-01-01 2023-01-07 - 4 5 Raakaan el-Vaziri suspected m 16 2023-01-01 - 5 6 Jaasim al-Shams confirmed m 83 2023-01-01 - 6 8 Jared Chambers confirmed m 48 2023-01-01 - 7 11 Muneer al-Miah confirmed m 77 2023-01-01 2023-01-01 - 8 12 Abdul Khaliq al-Youssef confirmed m 90 2023-01-01 - 9 13 Cheyenne Garcia confirmed f 66 2023-01-01 - 10 18 Shaakira al-Gaber probable f 31 2023-01-02 2023-01-02 - 11 20 Miguel Stimack suspected m 46 2023-01-02 - 12 22 Benito Casarez confirmed m 75 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered NA - 2 recovered 2022-12-30 2023-01-01 25.1 - 3 died 2023-01-10 2022-12-31 2023-01-02 25.1 - 4 recovered 2022-12-30 2023-01-02 NA - 5 recovered 2022-12-31 2023-01-01 25.1 - 6 recovered 2022-12-31 2023-01-01 25.1 - 7 recovered 2022-12-30 2023-01-02 25.1 - 8 recovered 2022-12-30 2023-01-01 25.1 - 9 recovered 2022-12-29 2023-01-01 25.1 - 10 recovered 2022-12-30 2023-01-01 NA - 11 recovered 2022-12-30 2023-01-01 NA - 12 recovered 2022-12-30 2023-01-02 25.1 + id case_name case_type sex age date_onset date_admission outcome + 1 1 Maazina el-Kader probable f 20 2023-01-01 recovered + 2 2 Muneeb al-Youssef confirmed m 24 2023-01-01 recovered + 3 3 Francisco Huerta suspected m 51 2023-01-01 2023-01-07 recovered + 4 5 Sean Sundara confirmed m 16 2023-01-01 recovered + 5 6 Jack Walentine suspected m 83 2023-01-01 recovered + 6 8 Avery Temple probable m 48 2023-01-01 recovered + 7 11 Robert Gonzales probable m 77 2023-01-01 2023-01-01 recovered + 8 12 Timothy Cheek suspected m 90 2023-01-01 recovered + 9 13 Courtney Smith confirmed f 66 2023-01-01 recovered + 10 18 Jasra al-Hadi confirmed f 31 2023-01-02 2023-01-02 recovered + 11 20 Codie Patterson probable m 46 2023-01-02 recovered + 12 22 Eric Childs probable m 75 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-01 24.1 + 3 2022-12-31 2023-01-02 NA + 4 2022-12-30 2023-01-02 24.1 + 5 2022-12-31 2023-01-01 NA + 6 2022-12-31 2023-01-01 NA + 7 2022-12-30 2023-01-02 NA + 8 2022-12-30 2023-01-01 NA + 9 2022-12-29 2023-01-01 24.1 + 10 2022-12-30 2023-01-01 24.1 + 11 2022-12-30 2023-01-01 NA + 12 2022-12-30 2023-01-02 NA # sim_linelist works as expected with modified config parameters @@ -244,67 +244,67 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, config = create_config(last_contact_distribution_params = c(lambda = 5))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Damion Hamm confirmed m 35 2023-01-01 - 2 2 Ignacio Hernandez confirmed m 43 2023-01-01 - 3 3 Bryce Donnelly confirmed m 1 2023-01-01 - 4 5 David Arrieta confirmed m 78 2023-01-01 - 5 6 Kristina Vazquez Pallares confirmed f 22 2023-01-01 - 6 8 Nusaiba el-Farah suspected f 28 2023-01-01 - 7 11 Dominic Kills In Sight probable m 46 2023-01-01 2023-01-13 - 8 12 Violet Watts confirmed f 67 2023-01-01 - 9 13 Khristopher Cunniff confirmed m 86 2023-01-01 2023-01-01 - 10 18 Paige Reich probable f 60 2023-01-02 - 11 20 Jackson Carlson confirmed m 49 2023-01-02 - 12 22 Cassandra Smith suspected f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered 25.6 - 2 recovered 2023-01-01 2023-01-07 25.6 - 3 recovered 2022-12-31 2023-01-03 25.6 - 4 recovered 2022-12-31 2023-01-04 25.6 - 5 recovered 2023-01-02 2023-01-04 25.6 - 6 recovered 2023-01-06 2023-01-07 NA - 7 recovered 2023-01-07 2023-01-08 NA - 8 recovered 2023-01-03 2023-01-06 25.6 - 9 recovered 2023-01-02 2023-01-05 25.6 - 10 recovered 2023-01-01 2023-01-05 NA - 11 recovered 2023-01-04 2023-01-07 25.6 - 12 died 2023-01-16 2023-01-03 2023-01-05 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gabriel Black probable m 35 2023-01-01 recovered + 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered + 3 3 Cody Morales suspected m 1 2023-01-01 recovered + 4 5 Joewid Le probable m 78 2023-01-01 recovered + 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered + 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered + 8 12 Kendra To suspected f 67 2023-01-01 recovered + 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died + 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered + 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2023-01-01 2023-01-07 24 + 3 2022-12-31 2023-01-03 NA + 4 2022-12-31 2023-01-04 NA + 5 2023-01-02 2023-01-04 24 + 6 2023-01-06 2023-01-07 24 + 7 2023-01-07 2023-01-08 24 + 8 2023-01-03 2023-01-06 NA + 9 2023-01-09 2023-01-02 2023-01-05 24 + 10 2023-01-01 2023-01-05 24 + 11 2023-01-04 2023-01-07 NA + 12 2023-01-03 2023-01-05 NA # sim_linelist works as expected with time-varying cfr Code sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, - config = create_config(time_varying_death_risk = function(x) dexp(x = x, - rate = 0.05))) + config = create_config(time_varying_death_risk = function(risk, time) risk * + exp(-time))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Devyn Chavez probable m 35 2023-01-01 - 2 2 Bryce Cunniff confirmed m 43 2023-01-01 - 3 3 Ignacio Garcia Mayen confirmed m 1 2023-01-01 - 4 5 Jacob Kills In Sight probable m 78 2023-01-01 - 5 6 Tiffany Harrison confirmed f 22 2023-01-01 - 6 8 Caroline Hergenreter suspected f 28 2023-01-01 - 7 11 Khristopher Kelley probable m 46 2023-01-01 2023-01-13 - 8 12 Carolyn Moore confirmed f 67 2023-01-01 - 9 13 Tyler Carlson confirmed m 86 2023-01-01 2023-01-01 - 10 18 Chantelle Vazquez-Luevano confirmed f 60 2023-01-02 - 11 20 David Abeyta suspected m 49 2023-01-02 - 12 22 Megan Riggenbach confirmed f 7 2023-01-02 2023-01-02 + id case_name case_type sex age date_onset date_admission + 1 1 Bryce Kelley probable m 35 2023-01-01 + 2 2 Cleatus Kacprowicz confirmed m 43 2023-01-01 + 3 3 Khristopher Carlson suspected m 1 2023-01-01 + 4 5 Raynaldo Grano probable m 78 2023-01-01 + 5 6 Carolyn Moore confirmed f 22 2023-01-01 + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 + 7 11 Abdul Maalik al-Chahine confirmed m 46 2023-01-01 2023-01-13 + 8 12 Kendra To suspected f 67 2023-01-01 + 9 13 Joewid Le confirmed m 86 2023-01-01 2023-01-01 + 10 18 Dominique Raymond confirmed f 60 2023-01-02 + 11 20 Jackson Sheek probable m 49 2023-01-02 + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 outcome date_outcome date_first_contact date_last_contact ct_value 1 recovered NA - 2 recovered 2022-12-30 2023-01-05 25 - 3 recovered 2022-12-30 2023-01-02 25 + 2 recovered 2022-12-30 2023-01-05 24 + 3 recovered 2022-12-30 2023-01-02 NA 4 recovered 2022-12-29 2023-01-02 NA - 5 recovered 2023-01-01 2023-01-03 25 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25 - 9 recovered 2022-12-31 2023-01-03 25 - 10 recovered 2022-12-30 2023-01-03 25 + 5 recovered 2023-01-01 2023-01-03 24 + 6 recovered 2023-01-03 2023-01-04 24 + 7 recovered 2023-01-04 2023-01-05 24 + 8 recovered 2023-01-01 2023-01-04 NA + 9 recovered 2022-12-31 2023-01-03 24 + 10 recovered 2022-12-30 2023-01-03 24 11 recovered 2023-01-01 2023-01-04 NA - 12 died 2023-01-15 2023-01-01 2023-01-03 25 + 12 recovered 2023-01-01 2023-01-03 NA # sim_linelist works as expected with time-varying cfr & age-strat @@ -312,21 +312,21 @@ sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, hosp_death_risk = age_dep_hosp_death_risk, config = create_config( - time_varying_death_risk = function(x) dexp(x = x, rate = 0.05))) + time_varying_death_risk = function(risk, time) risk * exp(-time))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Bryce Lehmkuhl probable m 35 2023-01-01 - 2 2 Dennison Bellow confirmed m 43 2023-01-01 - 3 3 Damion Long suspected m 1 2023-01-01 - 4 5 Ignacio Garcia Mayen probable m 78 2023-01-01 - 5 6 Carolyn Moore confirmed f 22 2023-01-01 - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 - 7 11 David Abeyta confirmed m 46 2023-01-01 2023-01-13 - 8 12 Kendra To suspected f 67 2023-01-01 - 9 13 Morgan Kills In Sight confirmed m 86 2023-01-01 2023-01-01 - 10 18 Dominique Raymond confirmed f 60 2023-01-02 - 11 20 Jackson Peterson probable m 49 2023-01-02 - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 + id case_name case_type sex age date_onset date_admission + 1 1 Bryce Kelley probable m 35 2023-01-01 + 2 2 Cleatus Kacprowicz confirmed m 43 2023-01-01 + 3 3 Khristopher Carlson suspected m 1 2023-01-01 + 4 5 Raynaldo Grano probable m 78 2023-01-01 + 5 6 Carolyn Moore confirmed f 22 2023-01-01 + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 + 7 11 Abdul Maalik al-Chahine confirmed m 46 2023-01-01 2023-01-13 + 8 12 Kendra To suspected f 67 2023-01-01 + 9 13 Joewid Le confirmed m 86 2023-01-01 2023-01-01 + 10 18 Dominique Raymond confirmed f 60 2023-01-02 + 11 20 Jackson Sheek probable m 49 2023-01-02 + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 outcome date_outcome date_first_contact date_last_contact ct_value 1 recovered NA 2 recovered 2022-12-30 2023-01-05 24 diff --git a/tests/testthat/test-sim_linelist.R b/tests/testthat/test-sim_linelist.R index 7d71e37d..df58ec38 100644 --- a/tests/testthat/test-sim_linelist.R +++ b/tests/testthat/test-sim_linelist.R @@ -421,7 +421,7 @@ test_that("sim_linelist works as expected with time-varying cfr", { onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, config = create_config( - time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) + time_varying_death_risk = function(risk, time) risk * exp(-time) ) ) ) @@ -442,7 +442,7 @@ test_that("sim_linelist works as expected with time-varying cfr & age-strat", { onset_to_death = onset_to_death, hosp_death_risk = age_dep_hosp_death_risk, config = create_config( - time_varying_death_risk = function(x) dexp(x = x, rate = 0.05) + time_varying_death_risk = function(risk, time) risk * exp(-time) ) ) ) @@ -457,10 +457,22 @@ test_that("sim_linelist fails as expected with time-varying cfr", { onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, config = create_config( - time_varying_death_risk = function(x, y) dexp(x = x, rate = 0.05) + time_varying_death_risk = function(x, y, z) x + y + x ) ), - regexp = "(Anonymous functions supplied must have)*(1)*(argument)" + regexp = "(Anonymous functions supplied must have)*(2)*(argument)" + ) + expect_error( + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = onset_to_death, + config = create_config( + time_varying_death_risk = function(risk, time) risk * exp(time) + ) + ), + regexp = "(Time-varying)*(risk outside)*(0)*(1)*(Check time-varying func)", ) - }) From ed58c38bcfd947c3963c52bdf6971c0ab9a08ec0 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 22 Apr 2024 17:38:21 +0100 Subject: [PATCH 31/37] updated sim_outbreak snapshots for updated time-varying cfr --- tests/testthat/_snaps/sim_outbreak.md | 440 +++++++++++++------------- 1 file changed, 220 insertions(+), 220 deletions(-) diff --git a/tests/testthat/_snaps/sim_outbreak.md b/tests/testthat/_snaps/sim_outbreak.md index 73a8984f..8e97962f 100644 --- a/tests/testthat/_snaps/sim_outbreak.md +++ b/tests/testthat/_snaps/sim_outbreak.md @@ -5,78 +5,78 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death) Output $linelist - id case_name case_type sex age date_onset date_admission - 1 1 Damion Hamm confirmed m 35 2023-01-01 - 2 2 Ignacio Hernandez confirmed m 43 2023-01-01 - 3 3 Bryce Donnelly confirmed m 1 2023-01-01 - 4 5 David Arrieta confirmed m 78 2023-01-01 - 5 6 Kristina Vazquez Pallares confirmed f 22 2023-01-01 - 6 8 Nusaiba el-Farah suspected f 28 2023-01-01 - 7 11 Dominic Kills In Sight probable m 46 2023-01-01 2023-01-13 - 8 12 Violet Watts confirmed f 67 2023-01-01 - 9 13 Khristopher Cunniff confirmed m 86 2023-01-01 2023-01-01 - 10 18 Paige Reich probable f 60 2023-01-02 - 11 20 Jackson Carlson confirmed m 49 2023-01-02 - 12 22 Cassandra Smith suspected f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered 25.6 - 2 recovered 2022-12-30 2023-01-05 25.6 - 3 recovered 2022-12-30 2023-01-02 25.6 - 4 recovered 2022-12-29 2023-01-02 25.6 - 5 recovered 2023-01-01 2023-01-03 25.6 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25.6 - 9 recovered 2022-12-31 2023-01-03 25.6 - 10 recovered 2022-12-30 2023-01-03 NA - 11 recovered 2023-01-01 2023-01-04 25.6 - 12 died 2023-01-16 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gabriel Black probable m 35 2023-01-01 recovered + 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered + 3 3 Cody Morales suspected m 1 2023-01-01 recovered + 4 5 Joewid Le probable m 78 2023-01-01 recovered + 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered + 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered + 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered + 8 12 Kendra To suspected f 67 2023-01-01 recovered + 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died + 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered + 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered + 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 24 + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 24 + 6 2023-01-03 2023-01-04 24 + 7 2023-01-04 2023-01-05 24 + 8 2023-01-01 2023-01-04 NA + 9 2023-01-09 2022-12-31 2023-01-03 24 + 10 2022-12-30 2023-01-03 24 + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 NA $contacts - from to age sex - 1 Damion Hamm Ignacio Hernandez 43 m - 2 Damion Hamm Bryce Donnelly 1 m - 3 Ignacio Hernandez Ashlan Krause 29 f - 4 Ignacio Hernandez David Arrieta 78 m - 5 Bryce Donnelly Kristina Vazquez Pallares 22 f - 6 Bryce Donnelly Morgan Vermillion 70 m - 7 Bryce Donnelly Nusaiba el-Farah 28 f - 8 David Arrieta Ryanna Hart 37 f - 9 Kristina Vazquez Pallares Shan Klutke 61 f - 10 Nusaiba el-Farah Dominic Kills In Sight 46 m - 11 Nusaiba el-Farah Violet Watts 67 f - 12 Nusaiba el-Farah Khristopher Cunniff 86 m - 13 Dominic Kills In Sight Tyler Kelley 71 m - 14 Dominic Kills In Sight Janayva Allen 51 f - 15 Dominic Kills In Sight Sheldon Martinez 44 m - 16 Violet Watts Lien Saldanha 49 f - 17 Khristopher Cunniff Paige Reich 60 f - 18 Khristopher Cunniff Brianna Pollard 56 f - 19 Khristopher Cunniff Jackson Carlson 49 m - 20 Khristopher Cunniff Raynaldo Santistevan 50 m - 21 Paige Reich Cassandra Smith 7 f - date_first_contact date_last_contact was_case status - 1 2022-12-30 2023-01-05 Y case - 2 2022-12-30 2023-01-02 Y case - 3 2022-12-27 2023-01-03 N under_followup - 4 2022-12-29 2023-01-02 Y case - 5 2023-01-01 2023-01-03 Y case - 6 2022-12-30 2023-01-02 N under_followup - 7 2023-01-03 2023-01-04 Y case - 8 2023-01-06 2023-01-06 N lost_to_followup - 9 2023-01-01 2023-01-05 N under_followup - 10 2023-01-04 2023-01-05 Y case - 11 2023-01-01 2023-01-04 Y case - 12 2022-12-31 2023-01-03 Y case - 13 2022-12-28 2023-01-05 N under_followup - 14 2023-01-01 2023-01-04 N under_followup - 15 2023-01-02 2023-01-05 N lost_to_followup - 16 2023-01-02 2023-01-03 N under_followup - 17 2022-12-30 2023-01-03 Y case - 18 2023-01-06 2023-01-09 N lost_to_followup - 19 2023-01-01 2023-01-04 Y case - 20 2023-01-01 2023-01-03 N unknown - 21 2023-01-01 2023-01-03 Y case + from to age sex date_first_contact + 1 Gabriel Black Tyler Kelley 43 m 2022-12-30 + 2 Gabriel Black Cody Morales 1 m 2022-12-30 + 3 Tyler Kelley Taylor Graves 29 f 2022-12-27 + 4 Tyler Kelley Joewid Le 78 m 2022-12-29 + 5 Cody Morales Carolyn Moore 22 f 2023-01-01 + 6 Cody Morales Rushdi al-Ishak 70 m 2022-12-30 + 7 Cody Morales Cheyenne Sayavong 28 f 2023-01-03 + 8 Joewid Le Mercedes Lovelace 37 f 2023-01-06 + 9 Carolyn Moore Chantelle Vazquez-Luevano 61 f 2023-01-01 + 10 Cheyenne Sayavong Pierce Khanthavong 46 m 2023-01-04 + 11 Cheyenne Sayavong Kendra To 67 f 2023-01-01 + 12 Cheyenne Sayavong Preston Barringer 86 m 2022-12-31 + 13 Pierce Khanthavong Jackson Carlson 71 m 2022-12-28 + 14 Pierce Khanthavong Megan Hayes 51 f 2023-01-01 + 15 Pierce Khanthavong Sam Spencer 44 m 2023-01-02 + 16 Kendra To Amanda Larochelle 49 f 2023-01-02 + 17 Preston Barringer Dominique Raymond 60 f 2022-12-30 + 18 Preston Barringer Natalie Newton 56 f 2023-01-06 + 19 Preston Barringer Bassaam el-Majid 49 m 2023-01-01 + 20 Preston Barringer Qaaid al-Madani 50 m 2023-01-01 + 21 Dominique Raymond Susana Varela 7 f 2023-01-01 + date_last_contact was_case status + 1 2023-01-05 Y case + 2 2023-01-02 Y case + 3 2023-01-03 N unknown + 4 2023-01-02 Y case + 5 2023-01-03 Y case + 6 2023-01-02 N under_followup + 7 2023-01-04 Y case + 8 2023-01-06 N under_followup + 9 2023-01-05 N under_followup + 10 2023-01-05 Y case + 11 2023-01-04 Y case + 12 2023-01-03 Y case + 13 2023-01-05 N under_followup + 14 2023-01-04 N lost_to_followup + 15 2023-01-05 N under_followup + 16 2023-01-03 N under_followup + 17 2023-01-03 Y case + 18 2023-01-09 N unknown + 19 2023-01-04 Y case + 20 2023-01-03 N under_followup + 21 2023-01-03 Y case # sim_outbreak works as expected with add_names = FALSE @@ -89,54 +89,54 @@ $linelist id case_type sex age date_onset date_admission outcome date_outcome 1 1 confirmed m 35 2023-01-01 recovered - 2 2 confirmed m 43 2023-01-01 recovered - 3 3 confirmed m 1 2023-01-01 recovered + 2 2 probable m 43 2023-01-01 recovered + 3 3 probable m 1 2023-01-01 recovered 4 5 confirmed m 78 2023-01-01 recovered - 5 6 suspected f 22 2023-01-01 recovered - 6 8 probable f 28 2023-01-01 recovered + 5 6 confirmed f 22 2023-01-01 recovered + 6 8 confirmed f 28 2023-01-01 recovered 7 11 confirmed m 46 2023-01-01 2023-01-13 recovered 8 12 confirmed f 67 2023-01-01 recovered - 9 13 probable m 86 2023-01-01 2023-01-01 recovered - 10 18 probable f 60 2023-01-02 recovered + 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-09 + 10 18 confirmed f 60 2023-01-02 recovered 11 20 confirmed m 49 2023-01-02 recovered - 12 22 confirmed f 7 2023-01-02 2023-01-02 died 2023-01-16 + 12 22 confirmed f 7 2023-01-02 2023-01-02 recovered date_first_contact date_last_contact ct_value - 1 25.7 - 2 2022-12-30 2023-01-05 25.7 - 3 2022-12-30 2023-01-02 25.7 - 4 2022-12-29 2023-01-02 25.7 - 5 2023-01-01 2023-01-03 NA - 6 2023-01-03 2023-01-04 NA - 7 2023-01-04 2023-01-05 25.7 - 8 2023-01-01 2023-01-04 25.7 - 9 2022-12-31 2023-01-03 NA - 10 2022-12-30 2023-01-03 NA - 11 2023-01-01 2023-01-04 25.7 - 12 2023-01-01 2023-01-03 25.7 + 1 24.9 + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 24.9 + 5 2023-01-01 2023-01-03 24.9 + 6 2023-01-03 2023-01-04 24.9 + 7 2023-01-04 2023-01-05 24.9 + 8 2023-01-01 2023-01-04 24.9 + 9 2022-12-31 2023-01-03 24.9 + 10 2022-12-30 2023-01-03 24.9 + 11 2023-01-01 2023-01-04 24.9 + 12 2023-01-01 2023-01-03 24.9 $contacts - from to age sex date_first_contact - 1 John Sheldon Abdul Maalik al-Sarwar 43 m 2022-12-30 - 2 John Sheldon Jeffrey Le 1 m 2022-12-30 - 3 Abdul Maalik al-Sarwar Taylor Graves 29 f 2022-12-27 - 4 Abdul Maalik al-Sarwar Grayson Black 78 m 2022-12-29 - 5 Jeffrey Le Carolyn Moore 22 f 2023-01-01 - 6 Jeffrey Le Tyler Kelley 70 m 2022-12-30 - 7 Jeffrey Le Cheyenne Sayavong 28 f 2023-01-03 - 8 Grayson Black Mercedes Lovelace 37 f 2023-01-06 - 9 Carolyn Moore Chantelle Vazquez-Luevano 61 f 2023-01-01 - 10 Cheyenne Sayavong Jackson Carlson 46 m 2023-01-04 - 11 Cheyenne Sayavong Kendra To 67 f 2023-01-01 - 12 Cheyenne Sayavong Rushdi al-Bahri 86 m 2022-12-31 - 13 Jackson Carlson Bassaam el-Laham 71 m 2022-12-28 - 14 Jackson Carlson Megan Hayes 51 f 2023-01-01 - 15 Jackson Carlson John Khanthavong 44 m 2023-01-02 - 16 Kendra To Amanda Larochelle 49 f 2023-01-02 - 17 Rushdi al-Bahri Dominique Raymond 60 f 2022-12-30 - 18 Rushdi al-Bahri Natalie Newton 56 f 2023-01-06 - 19 Rushdi al-Bahri Qaaid al-Chahine 49 m 2023-01-01 - 20 Rushdi al-Bahri Abdul Kader el-Jabour 50 m 2023-01-01 - 21 Dominique Raymond Susana Varela 7 f 2023-01-01 + from to age sex date_first_contact + 1 Wajdi al-Demian Raaid el-Diab 43 m 2022-12-30 + 2 Wajdi al-Demian Nickolas Nault 1 m 2022-12-30 + 3 Raaid el-Diab Durine Cobb 29 f 2022-12-27 + 4 Raaid el-Diab Hee Kennedy 78 m 2022-12-29 + 5 Nickolas Nault Hope Arshad 22 f 2023-01-01 + 6 Nickolas Nault Mubarak el-Vaziri 70 m 2022-12-30 + 7 Nickolas Nault Shanta Holiday 28 f 2023-01-03 + 8 Hee Kennedy Darian Guyon 37 f 2023-01-06 + 9 Hope Arshad Mackenzie Ahn 61 f 2023-01-01 + 10 Shanta Holiday Raakaan al-Shams 46 m 2023-01-04 + 11 Shanta Holiday Chandra Kilian 67 f 2023-01-01 + 12 Shanta Holiday Ricardo Sanchez 86 m 2022-12-31 + 13 Raakaan al-Shams Tae Woo Nguyen 71 m 2022-12-28 + 14 Raakaan al-Shams Mikhaila Carlson 51 f 2023-01-01 + 15 Raakaan al-Shams Alexander Orio 44 m 2023-01-02 + 16 Chandra Kilian Alexandra Johnson 49 f 2023-01-02 + 17 Ricardo Sanchez Kanani Nguyen 60 f 2022-12-30 + 18 Ricardo Sanchez Nirvana Elizalde Villa 56 f 2023-01-06 + 19 Ricardo Sanchez Jared Chambers 49 m 2023-01-01 + 20 Ricardo Sanchez Thomas Morales 50 m 2023-01-01 + 21 Kanani Nguyen Annie Carter 7 f 2023-01-01 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case @@ -146,12 +146,12 @@ 6 2023-01-02 N under_followup 7 2023-01-04 Y case 8 2023-01-06 N unknown - 9 2023-01-05 N lost_to_followup + 9 2023-01-05 N under_followup 10 2023-01-05 Y case 11 2023-01-04 Y case 12 2023-01-03 Y case - 13 2023-01-05 N under_followup - 14 2023-01-04 N under_followup + 13 2023-01-05 N lost_to_followup + 14 2023-01-04 N lost_to_followup 15 2023-01-05 N under_followup 16 2023-01-03 N lost_to_followup 17 2023-01-03 Y case @@ -170,77 +170,77 @@ non_hosp_death_risk = age_dep_non_hosp_death_risk) Output $linelist - id case_name case_type sex age date_onset date_admission - 1 1 David Garcia Mayen probable m 35 2023-01-01 - 2 2 Rory Kills In Sight confirmed m 43 2023-01-01 - 3 3 Sheldon Martinez confirmed m 1 2023-01-01 2023-01-11 - 4 5 Bryce Cunniff probable m 78 2023-01-01 - 5 6 Lien Whitworth confirmed f 22 2023-01-01 - 6 8 Tiffany Weiss suspected f 28 2023-01-01 - 7 11 Cleatus Kacprowicz probable m 46 2023-01-01 - 8 12 Taylor Moore confirmed f 67 2023-01-01 - 9 13 Tyler Carlson confirmed m 86 2023-01-01 2023-01-01 - 10 18 Grayson Lovelace confirmed f 60 2023-01-02 - 11 20 Abdul Maalik al-Ishak suspected m 49 2023-01-02 2023-01-09 - 12 22 Kendra Newton confirmed f 7 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered NA - 2 recovered 2022-12-30 2023-01-05 25 - 3 recovered 2022-12-30 2023-01-02 25 - 4 recovered 2022-12-29 2023-01-02 NA - 5 recovered 2023-01-01 2023-01-03 25 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25 - 9 recovered 2022-12-31 2023-01-03 25 - 10 recovered 2022-12-30 2023-01-03 25 - 11 recovered 2023-01-01 2023-01-04 NA - 12 recovered 2023-01-01 2023-01-03 25 + id case_name case_type sex age date_onset date_admission outcome + 1 1 Micheal Smallwood probable m 35 2023-01-01 recovered + 2 2 Kyle Foster confirmed m 43 2023-01-01 recovered + 3 3 Ghaamid el-Kaiser suspected m 1 2023-01-01 2023-01-11 died + 4 5 Faatih el-Riaz confirmed m 78 2023-01-01 recovered + 5 6 Hope Arshad suspected f 22 2023-01-01 recovered + 6 8 Shanta Holiday probable f 28 2023-01-01 recovered + 7 11 Aiman al-Demian probable m 46 2023-01-01 recovered + 8 12 Chandra Kilian suspected f 67 2023-01-01 recovered + 9 13 Wajdi el-Diab confirmed m 86 2023-01-01 2023-01-01 recovered + 10 18 Kanani Nguyen confirmed f 60 2023-01-02 recovered + 11 20 Raaid el-Vaziri probable m 49 2023-01-02 2023-01-09 recovered + 12 22 Annie Carter probable f 7 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 24.1 + 3 2023-01-14 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 24.1 + 5 2023-01-01 2023-01-03 NA + 6 2023-01-03 2023-01-04 NA + 7 2023-01-04 2023-01-05 NA + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 24.1 + 10 2022-12-30 2023-01-03 24.1 + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 NA $contacts - from to age sex date_first_contact - 1 David Garcia Mayen Rory Kills In Sight 43 m 2022-12-30 - 2 David Garcia Mayen Sheldon Martinez 1 m 2022-12-30 - 3 Rory Kills In Sight Violet Harrison 29 f 2022-12-27 - 4 Rory Kills In Sight Bryce Cunniff 78 m 2022-12-29 - 5 Sheldon Martinez Lien Whitworth 22 f 2023-01-01 - 6 Sheldon Martinez Khristopher Kelley 70 m 2022-12-30 - 7 Sheldon Martinez Tiffany Weiss 28 f 2023-01-03 - 8 Bryce Cunniff Caroline Hergenreter 37 f 2023-01-06 - 9 Lien Whitworth Cassandra Sayavong 61 f 2023-01-01 - 10 Tiffany Weiss Cleatus Kacprowicz 46 m 2023-01-04 - 11 Tiffany Weiss Taylor Moore 67 f 2023-01-01 - 12 Tiffany Weiss Tyler Carlson 86 m 2022-12-31 - 13 Cleatus Kacprowicz Raynaldo Abeyta 71 m 2022-12-28 - 14 Cleatus Kacprowicz Carolyn Raymond 51 f 2023-01-01 - 15 Cleatus Kacprowicz Jelani Sheldon 44 m 2023-01-02 - 16 Taylor Moore Harleigh To 49 f 2023-01-02 - 17 Tyler Carlson Grayson Lovelace 60 f 2022-12-30 - 18 Tyler Carlson Angel Vazquez-Luevano 56 f 2023-01-06 - 19 Tyler Carlson Abdul Maalik al-Ishak 49 m 2023-01-01 - 20 Tyler Carlson Joewid Le 50 m 2023-01-01 - 21 Grayson Lovelace Kendra Newton 7 f 2023-01-01 + from to age sex date_first_contact + 1 Micheal Smallwood Kyle Foster 43 m 2022-12-30 + 2 Micheal Smallwood Ghaamid el-Kaiser 1 m 2022-12-30 + 3 Kyle Foster Durine Cobb 29 f 2022-12-27 + 4 Kyle Foster Faatih el-Riaz 78 m 2022-12-29 + 5 Ghaamid el-Kaiser Hope Arshad 22 f 2023-01-01 + 6 Ghaamid el-Kaiser Jonathan Takahashi 70 m 2022-12-30 + 7 Ghaamid el-Kaiser Shanta Holiday 28 f 2023-01-03 + 8 Faatih el-Riaz Darian Guyon 37 f 2023-01-06 + 9 Hope Arshad Mackenzie Ahn 61 f 2023-01-01 + 10 Shanta Holiday Aiman al-Demian 46 m 2023-01-04 + 11 Shanta Holiday Chandra Kilian 67 f 2023-01-01 + 12 Shanta Holiday Wajdi el-Diab 86 m 2022-12-31 + 13 Aiman al-Demian Travis Summers 71 m 2022-12-28 + 14 Aiman al-Demian Mikhaila Carlson 51 f 2023-01-01 + 15 Aiman al-Demian Cory Galligan 44 m 2023-01-02 + 16 Chandra Kilian Alexandra Johnson 49 f 2023-01-02 + 17 Wajdi el-Diab Kanani Nguyen 60 f 2022-12-30 + 18 Wajdi el-Diab Nirvana Elizalde Villa 56 f 2023-01-06 + 19 Wajdi el-Diab Raaid el-Vaziri 49 m 2023-01-01 + 20 Wajdi el-Diab Mubarak al-Shams 50 m 2023-01-01 + 21 Kanani Nguyen Annie Carter 7 f 2023-01-01 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case - 3 2023-01-03 N lost_to_followup + 3 2023-01-03 N under_followup 4 2023-01-02 Y case 5 2023-01-03 Y case 6 2023-01-02 N under_followup 7 2023-01-04 Y case - 8 2023-01-06 N lost_to_followup - 9 2023-01-05 N unknown + 8 2023-01-06 N under_followup + 9 2023-01-05 N lost_to_followup 10 2023-01-05 Y case 11 2023-01-04 Y case 12 2023-01-03 Y case - 13 2023-01-05 N under_followup + 13 2023-01-05 N lost_to_followup 14 2023-01-04 N under_followup 15 2023-01-05 N under_followup 16 2023-01-03 N under_followup 17 2023-01-03 Y case - 18 2023-01-09 N lost_to_followup + 18 2023-01-09 N unknown 19 2023-01-04 Y case - 20 2023-01-03 N under_followup + 20 2023-01-03 N lost_to_followup 21 2023-01-03 Y case @@ -252,56 +252,56 @@ population_age = age_struct) Output $linelist - id case_name case_type sex age date_onset date_admission outcome - 1 1 Mark Beard confirmed m 44 2023-01-01 recovered - 2 2 Brian Mccracken confirmed m 13 2023-01-01 recovered - 3 3 Jesus Garduno confirmed m 22 2023-01-01 2023-01-09 died - 4 5 Taalib al-Naqvi confirmed m 85 2023-01-01 recovered - 5 6 Kelly Geist confirmed f 41 2023-01-01 recovered - 6 8 Madison Krause suspected f 89 2023-01-01 2023-01-02 recovered - 7 11 Jonathon Lujano probable m 69 2023-01-01 recovered - 8 12 Ashlan Allen confirmed f 23 2023-01-01 recovered - 9 13 Dhaahir el-Hariri confirmed m 9 2023-01-01 recovered - 10 18 Korren Hart probable f 62 2023-01-02 recovered - 11 20 Isaac Huff confirmed m 52 2023-01-02 2023-01-15 recovered - 12 22 Ryanna Watts suspected f 76 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Gene Than probable m 44 2023-01-01 recovered + 2 2 Caleb Fredericks probable m 13 2023-01-01 recovered + 3 3 Jaisean Venable suspected m 22 2023-01-01 2023-01-09 died + 4 5 Taylor Swift probable m 85 2023-01-01 recovered + 5 6 Korren Bailey confirmed f 41 2023-01-01 recovered + 6 8 Madison Zahn confirmed f 89 2023-01-01 2023-01-02 recovered + 7 11 Dustin Bellow confirmed m 69 2023-01-01 recovered + 8 12 Ryanna Hart confirmed f 23 2023-01-01 recovered + 9 13 Rafael Garcia confirmed m 9 2023-01-01 recovered + 10 18 Ashlan Hendon confirmed f 62 2023-01-02 recovered + 11 20 Tieran Moorer suspected m 52 2023-01-02 2023-01-15 recovered + 12 22 Paige Reich probable f 76 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value - 1 25.6 - 2 2022-12-30 2023-01-05 25.6 - 3 2023-01-09 2022-12-30 2023-01-02 25.6 - 4 2022-12-29 2023-01-02 25.6 - 5 2023-01-01 2023-01-03 25.6 - 6 2023-01-03 2023-01-04 NA - 7 2023-01-04 2023-01-05 NA - 8 2023-01-01 2023-01-04 25.6 - 9 2022-12-31 2023-01-03 25.6 - 10 2022-12-30 2023-01-03 NA - 11 2023-01-01 2023-01-04 25.6 + 1 NA + 2 2022-12-30 2023-01-05 NA + 3 2023-01-12 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 24 + 6 2023-01-03 2023-01-04 24 + 7 2023-01-04 2023-01-05 24 + 8 2023-01-01 2023-01-04 24 + 9 2022-12-31 2023-01-03 24 + 10 2022-12-30 2023-01-03 24 + 11 2023-01-01 2023-01-04 NA 12 2023-01-01 2023-01-03 NA $contacts - from to age sex date_first_contact - 1 Mark Beard Brian Mccracken 13 m 2022-12-30 - 2 Mark Beard Jesus Garduno 22 m 2022-12-30 - 3 Brian Mccracken Alivia Estrada 5 f 2022-12-27 - 4 Brian Mccracken Taalib al-Naqvi 85 m 2022-12-29 - 5 Jesus Garduno Kelly Geist 41 f 2023-01-01 - 6 Jesus Garduno Umar al-Basa 2 m 2022-12-30 - 7 Jesus Garduno Madison Krause 89 f 2023-01-03 - 8 Taalib al-Naqvi Mawhiba al-Bilal 86 f 2023-01-06 - 9 Kelly Geist Destiny Bailey 82 f 2023-01-01 - 10 Madison Krause Jonathon Lujano 69 m 2023-01-04 - 11 Madison Krause Ashlan Allen 23 f 2023-01-01 - 12 Madison Krause Dhaahir el-Hariri 9 m 2022-12-31 - 13 Jonathon Lujano Andres Garza 79 m 2022-12-28 - 14 Jonathon Lujano Nicole Wright 29 f 2023-01-01 - 15 Jonathon Lujano Raj Ament 4 m 2023-01-02 - 16 Ashlan Allen Turfa el-Farah 13 f 2023-01-02 - 17 Dhaahir el-Hariri Korren Hart 62 f 2022-12-30 - 18 Dhaahir el-Hariri Shan Klutke 24 f 2023-01-06 - 19 Dhaahir el-Hariri Isaac Huff 52 m 2023-01-01 - 20 Dhaahir el-Hariri Darienne Knost 74 m 2023-01-01 - 21 Korren Hart Ryanna Watts 76 f 2023-01-01 + from to age sex date_first_contact + 1 Gene Than Caleb Fredericks 13 m 2022-12-30 + 2 Gene Than Jaisean Venable 22 m 2022-12-30 + 3 Caleb Fredericks Mawhiba al-Mussa 5 f 2022-12-27 + 4 Caleb Fredericks Taylor Swift 85 m 2022-12-29 + 5 Jaisean Venable Korren Bailey 41 f 2023-01-01 + 6 Jaisean Venable Mustaba al-Sarwar 2 m 2022-12-30 + 7 Jaisean Venable Madison Zahn 89 f 2023-01-03 + 8 Taylor Swift Nicole Perez 86 f 2023-01-06 + 9 Korren Bailey Turfa el-Saab 82 f 2023-01-01 + 10 Madison Zahn Dustin Bellow 69 m 2023-01-04 + 11 Madison Zahn Ryanna Hart 23 f 2023-01-01 + 12 Madison Zahn Rafael Garcia 9 m 2022-12-31 + 13 Dustin Bellow Adrien Leduke 79 m 2022-12-28 + 14 Dustin Bellow Shan Klutke 29 f 2023-01-01 + 15 Dustin Bellow Dennison Kills In Sight 4 m 2023-01-02 + 16 Ryanna Hart Violet Watts 13 f 2023-01-02 + 17 Rafael Garcia Ashlan Hendon 62 f 2022-12-30 + 18 Rafael Garcia Lien Saldanha 24 f 2023-01-06 + 19 Rafael Garcia Tieran Moorer 52 m 2023-01-01 + 20 Rafael Garcia Michael Chavez 74 m 2023-01-01 + 21 Ashlan Hendon Paige Reich 76 f 2023-01-01 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case @@ -310,19 +310,19 @@ 5 2023-01-03 Y case 6 2023-01-02 N under_followup 7 2023-01-04 Y case - 8 2023-01-06 N lost_to_followup - 9 2023-01-05 N under_followup + 8 2023-01-06 N unknown + 9 2023-01-05 N lost_to_followup 10 2023-01-05 Y case 11 2023-01-04 Y case 12 2023-01-03 Y case 13 2023-01-05 N under_followup 14 2023-01-04 N under_followup - 15 2023-01-05 N lost_to_followup - 16 2023-01-03 N under_followup + 15 2023-01-05 N under_followup + 16 2023-01-03 N lost_to_followup 17 2023-01-03 Y case - 18 2023-01-09 N lost_to_followup + 18 2023-01-09 N under_followup 19 2023-01-04 Y case - 20 2023-01-03 N unknown + 20 2023-01-03 N under_followup 21 2023-01-03 Y case From 146a279c8e23384a67f563fbb82a71cac0632533 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 24 Apr 2024 17:16:48 +0100 Subject: [PATCH 32/37] update .check_func_req_args to check arg names and give more informative error messages --- R/checkers.R | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/R/checkers.R b/R/checkers.R index 50efdc83..898a1e0d 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -133,8 +133,8 @@ sim_type <- match.arg(sim_type) checkmate::assert_number(prob_infect, lower = 0, upper = 1) - .check_func_req_args(contact_distribution) - .check_func_req_args(infect_period) + .check_func_req_args(contact_distribution, func_name = "contact_distribution") + .check_func_req_args(infect_period, func_name = "infect_period") checkmate::assert_date(outbreak_start_date) checkmate::assert_integerish(outbreak_size, lower = 1, len = 2) @@ -145,9 +145,9 @@ ) if (sim_type %in% c("linelist", "outbreak")) { - .check_func_req_args(onset_to_hosp) - .check_func_req_args(onset_to_death) - .check_func_req_args(onset_to_recovery) + .check_func_req_args(onset_to_hosp, func_name = "onset_to_hosp") + .check_func_req_args(onset_to_death, func_name = "onset_to_death") + .check_func_req_args(onset_to_recovery, func_name = "onset_to_recovery") checkmate::assert_logical(add_names, len = 1) checkmate::assert_logical(add_ct, len = 1) checkmate::assert_numeric(case_type_probs, len = 3, lower = 0, upper = 1) @@ -206,7 +206,10 @@ #' @return A `logical`. #' @keywords internal #' @noRd -.check_func_req_args <- function(func, n_req_args = 1) { +.check_func_req_args <- function(func, + func_name, + n_req_args = 1, + req_arg_names = NULL) { checkmate::assert_function(func) checkmate::assert_count(n_req_args, positive = TRUE) # using formals(args(fn)) to allow checking args of builtin primitives @@ -216,11 +219,23 @@ sum(mapply(function(x, y) { # nolint undesirable function is.name(x) && y != "..." }, formals(args(func)), names(formals(args(func))))) == n_req_args + + + msg <- character(0) if (!valid_func) { - stop( - "Anonymous functions supplied must have ", n_req_args, " argument(s).", - call. = FALSE - ) + msg <- c(msg, paste( + func_name, "supplied must have", n_req_args, "arguments." + )) + } + if (!is.null(req_arg_names) && + !identical(names(formals(func)), req_arg_names)) { + msg <- c(msg, paste( + func_name, "supplied must have", paste(req_arg_names, collapse = " & "), + "arguments." + )) + } + if (length(msg) > 0) { + stop("\n", sprintf(" - %s\n", msg), call. = FALSE) } } From a7f46485a5e22eac8ed596e2ba894d70b290f675 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 24 Apr 2024 17:17:05 +0100 Subject: [PATCH 33/37] updated .check_func_req_args tests --- tests/testthat/test-checkers.R | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-checkers.R b/tests/testthat/test-checkers.R index 8710d9e0..b5297835 100644 --- a/tests/testthat/test-checkers.R +++ b/tests/testthat/test-checkers.R @@ -456,13 +456,33 @@ test_that(".check_func_req_args works with more than 1 req args", { expect_null(.check_func_req_args(func = fn, n_req_args = 2)) }) +test_that(".check_func_req_args works with arg names", { + fn <- function(x) x + expect_silent(.check_func_req_args(func = fn, req_arg_names = "x")) + expect_null(.check_func_req_args(func = fn, req_arg_names = "x")) +}) + test_that(".check_func_req_args fails as expected", { expect_error( - .check_func_req_args(func = function(x) x + 1, n_req_args = 2), - regexp = "(Anonymous functions supplied must have)*(2)*(argument)" + .check_func_req_args( + func = function(x) x + 1, func_name = "anonymous func", n_req_args = 2 + ), + regexp = "(anonymous func supplied must have)*(2)*(argument)" ) expect_error( - .check_func_req_args(func = function(x, y) x + y, n_req_args = 1), - regexp = "(Anonymous functions supplied must have)*(1)*(argument)" + .check_func_req_args( + func = function(x, y) x + y, func_name = "anonymous func", n_req_args = 1 + ), + regexp = "(anonymous func supplied must have)*(1)*(argument)" + ) +}) + +test_that(".check_func_req_args fails with arg names", { + fn <- function(x) x + expect_error( + .check_func_req_args( + func = fn, func_name = "anonymous func", req_arg_names = c("x", "y") + ), + regexp = "(anonymous func supplied must have)*(y)*(arguments)" ) }) From 369f09ac1ce3264d2d63d21a80d3d1134727ace5 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 24 Apr 2024 17:17:26 +0100 Subject: [PATCH 34/37] updated .check_func_req_args call in .add_outcome --- R/add_cols.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/add_cols.R b/R/add_cols.R index 520f711b..85a940d9 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -154,7 +154,12 @@ NULL age_group_idx <- which(.data$age %in% age_bracket & idx) if (is.function(config$time_varying_death_risk)) { - .check_func_req_args(config$time_varying_death_risk, n_req_args = 2) + .check_func_req_args( + config$time_varying_death_risk, + func_name = "time_varying_death_risk", + n_req_args = 2, + req_arg_names = c("risk", "time") + ) risk_ <- config$time_varying_death_risk( risk = risk$risk[i], time = .data$time[age_group_idx] From 00450f6a3a5b315b723f7bd9d21f20f73cf60b8b Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 25 Apr 2024 14:43:12 +0100 Subject: [PATCH 35/37] vectorise time-varying cfr in apply_death_risk --- R/add_cols.R | 76 +++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/R/add_cols.R b/R/add_cols.R index 85a940d9..73e3108e 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -148,46 +148,48 @@ NULL risk = risk ) } - # loop through each age group and sample which cases die - for (i in seq_len(nrow(risk))) { - age_bracket <- risk$min_age[i]:risk$max_age[i] - age_group_idx <- which(.data$age %in% age_bracket & idx) - - if (is.function(config$time_varying_death_risk)) { - .check_func_req_args( - config$time_varying_death_risk, - func_name = "time_varying_death_risk", - n_req_args = 2, - req_arg_names = c("risk", "time") - ) - risk_ <- config$time_varying_death_risk( - risk = risk$risk[i], - time = .data$time[age_group_idx] - ) - valid_risk <- checkmate::test_numeric( - risk_, - lower = 0, - upper = 1, - any.missing = FALSE + # find risk group for each individual based on age + # findInterval indexes from 0 so plus 1 for R vec indexing + # oldest age group is inclusive at upper bound so rightmost.closed = TRUE + risk_group_idx <- findInterval( + x = .data$age, + vec = risk$max_age, + rightmost.closed = TRUE + ) + 1 + # assign risk to each individual given age group + risk_ <- risk$risk[risk_group_idx] + if (is.function(config$time_varying_death_risk)) { + .check_func_req_args( + config$time_varying_death_risk, + func_name = "time_varying_death_risk", + n_req_args = 2, + req_arg_names = c("risk", "time") + ) + risk_ <- config$time_varying_death_risk( + risk = risk$risk[risk_group_idx], + time = .data$time + ) + valid_risk <- checkmate::test_numeric( + risk_, + lower = 0, + upper = 1, + any.missing = FALSE + ) + if (!valid_risk) { + stop( + "Time-varying death risk outside [0,1]. \n", + "Check time-varying function.", + call. = FALSE ) - if (!valid_risk) { - stop( - "Time-varying death risk outside [0,1]. \n", - "Check time-varying function.", - call. = FALSE - ) - } - } else { - risk_ <- rep(risk$risk[i], times = length(age_group_idx)) } - - # sample individuals in the risk category (e.g. hosp) to die given risk - died_idx <- stats::rbinom(n = length(risk_), size = 1, prob = risk_) - died_idx <- age_group_idx[as.logical(died_idx)] - .data$outcome[died_idx] <- "died" - .data$outcome_time[died_idx] <- .data$time[died_idx] + - onset_to_death(length(died_idx)) } + # sample individuals to die given risk group + died_idx <- stats::rbinom(n = length(risk_), size = 1, prob = risk_) + # died index requires individuals to be in idx group (e.g. hosp) + died_idx <- as.logical(died_idx) & idx + .data$outcome[died_idx] <- "died" + .data$outcome_time[died_idx] <- .data$time[died_idx] + + onset_to_death(sum(died_idx)) } .data } From f16edabbb2705c821f24c9425a663952a254d2cf Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Thu, 25 Apr 2024 14:43:34 +0100 Subject: [PATCH 36/37] update sim_linelist and sim_outbreak tests and snapshots --- tests/testthat/_snaps/sim_linelist.md | 468 ++++++++++++------------- tests/testthat/_snaps/sim_outbreak.md | 486 +++++++++++++------------- tests/testthat/test-sim_linelist.R | 2 + 3 files changed, 479 insertions(+), 477 deletions(-) diff --git a/tests/testthat/_snaps/sim_linelist.md b/tests/testthat/_snaps/sim_linelist.md index ce75f02d..8411350e 100644 --- a/tests/testthat/_snaps/sim_linelist.md +++ b/tests/testthat/_snaps/sim_linelist.md @@ -4,32 +4,32 @@ sim_linelist(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gabriel Black probable m 35 2023-01-01 recovered - 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered - 3 3 Cody Morales suspected m 1 2023-01-01 recovered - 4 5 Joewid Le probable m 78 2023-01-01 recovered - 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered - 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 Kendra To suspected f 67 2023-01-01 recovered - 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died - 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered - 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered - date_outcome date_first_contact date_last_contact ct_value - 1 NA - 2 2022-12-30 2023-01-05 24 - 3 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 NA - 5 2023-01-01 2023-01-03 24 - 6 2023-01-03 2023-01-04 24 - 7 2023-01-04 2023-01-05 24 - 8 2023-01-01 2023-01-04 NA - 9 2023-01-09 2022-12-31 2023-01-03 24 - 10 2022-12-30 2023-01-03 24 - 11 2023-01-01 2023-01-04 NA - 12 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission + 1 1 Dominic Sundara probable m 35 2023-01-01 + 2 2 Preston Montgomery suspected m 43 2023-01-01 + 3 3 Reece Chittum probable m 1 2023-01-01 + 4 5 Michael Cheek confirmed m 78 2023-01-01 + 5 6 Jennifer Smith confirmed f 22 2023-01-01 + 6 8 Erika Quintero confirmed f 28 2023-01-01 + 7 11 Isaiah Patterson suspected m 46 2023-01-01 2023-01-13 + 8 12 Cicely Anderson suspected f 67 2023-01-01 + 9 13 Michael John probable m 86 2023-01-01 2023-01-01 + 10 18 Giovana Magana Aguirre suspected f 60 2023-01-02 + 11 20 Mudrik al-Hallal suspected m 49 2023-01-02 + 12 22 Tea Slaughter probable f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered NA + 2 recovered 2022-12-30 2023-01-05 NA + 3 recovered 2022-12-30 2023-01-02 NA + 4 recovered 2022-12-29 2023-01-02 23.1 + 5 recovered 2023-01-01 2023-01-03 23.1 + 6 recovered 2023-01-03 2023-01-04 23.1 + 7 recovered 2023-01-04 2023-01-05 NA + 8 recovered 2023-01-01 2023-01-04 NA + 9 died 2023-01-12 2022-12-31 2023-01-03 NA + 10 recovered 2022-12-30 2023-01-03 NA + 11 recovered 2023-01-01 2023-01-04 NA + 12 recovered 2023-01-01 2023-01-03 NA # sim_linelist works as expected with age-strat risks @@ -39,30 +39,30 @@ hosp_risk = age_dep_hosp_risk, hosp_death_risk = age_dep_hosp_death_risk, non_hosp_death_risk = age_dep_non_hosp_death_risk) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Micheal Smallwood probable m 35 2023-01-01 recovered - 2 2 Kyle Foster confirmed m 43 2023-01-01 recovered - 3 3 Ghaamid el-Kaiser suspected m 1 2023-01-01 2023-01-11 died - 4 5 Faatih el-Riaz confirmed m 78 2023-01-01 recovered - 5 6 Hope Arshad suspected f 22 2023-01-01 recovered - 6 8 Shanta Holiday probable f 28 2023-01-01 recovered - 7 11 Aiman al-Demian probable m 46 2023-01-01 recovered - 8 12 Chandra Kilian suspected f 67 2023-01-01 recovered - 9 13 Wajdi el-Diab confirmed m 86 2023-01-01 2023-01-01 recovered - 10 18 Kanani Nguyen confirmed f 60 2023-01-02 recovered - 11 20 Raaid el-Vaziri probable m 49 2023-01-02 2023-01-09 recovered - 12 22 Annie Carter probable f 7 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Cass Duran probable m 35 2023-01-01 recovered + 2 2 Mudrik al-Hallal suspected m 43 2023-01-01 recovered + 3 3 Jareer al-Safar probable m 1 2023-01-01 2023-01-11 recovered + 4 5 Raashid el-Huda confirmed m 78 2023-01-01 recovered + 5 6 Erika Sierra confirmed f 22 2023-01-01 recovered + 6 8 Jennifer Hong confirmed f 28 2023-01-01 recovered + 7 11 Donald Childs suspected m 46 2023-01-01 recovered + 8 12 Kayla Johnson suspected f 67 2023-01-01 died + 9 13 Avery Johnston probable m 86 2023-01-01 2023-01-01 recovered + 10 18 Giovana Segarra suspected f 60 2023-01-02 recovered + 11 20 Donald Root suspected m 49 2023-01-02 2023-01-09 recovered + 12 22 Kiona Dalke probable f 7 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA - 2 2022-12-30 2023-01-05 24.1 - 3 2023-01-14 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 24.1 - 5 2023-01-01 2023-01-03 NA - 6 2023-01-03 2023-01-04 NA + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 23.1 + 5 2023-01-01 2023-01-03 23.1 + 6 2023-01-03 2023-01-04 23.1 7 2023-01-04 2023-01-05 NA - 8 2023-01-01 2023-01-04 NA - 9 2022-12-31 2023-01-03 24.1 - 10 2022-12-30 2023-01-03 24.1 + 8 2023-01-14 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 NA + 10 2022-12-30 2023-01-03 NA 11 2023-01-01 2023-01-04 NA 12 2023-01-01 2023-01-03 NA @@ -73,32 +73,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, add_ct = FALSE) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gabriel Black probable m 35 2023-01-01 recovered - 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered - 3 3 Cody Morales suspected m 1 2023-01-01 recovered - 4 5 Joewid Le probable m 78 2023-01-01 recovered - 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered - 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 Kendra To suspected f 67 2023-01-01 recovered - 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died - 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered - 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered - date_outcome date_first_contact date_last_contact - 1 - 2 2022-12-30 2023-01-05 - 3 2022-12-30 2023-01-02 - 4 2022-12-29 2023-01-02 - 5 2023-01-01 2023-01-03 - 6 2023-01-03 2023-01-04 - 7 2023-01-04 2023-01-05 - 8 2023-01-01 2023-01-04 - 9 2023-01-09 2022-12-31 2023-01-03 - 10 2022-12-30 2023-01-03 - 11 2023-01-01 2023-01-04 - 12 2023-01-01 2023-01-03 + id case_name case_type sex age date_onset date_admission + 1 1 Dominic Sundara probable m 35 2023-01-01 + 2 2 Preston Montgomery suspected m 43 2023-01-01 + 3 3 Reece Chittum probable m 1 2023-01-01 + 4 5 Michael Cheek confirmed m 78 2023-01-01 + 5 6 Jennifer Smith confirmed f 22 2023-01-01 + 6 8 Erika Quintero confirmed f 28 2023-01-01 + 7 11 Isaiah Patterson suspected m 46 2023-01-01 2023-01-13 + 8 12 Cicely Anderson suspected f 67 2023-01-01 + 9 13 Michael John probable m 86 2023-01-01 2023-01-01 + 10 18 Giovana Magana Aguirre suspected f 60 2023-01-02 + 11 20 Mudrik al-Hallal suspected m 49 2023-01-02 + 12 22 Tea Slaughter probable f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact + 1 recovered + 2 recovered 2022-12-30 2023-01-05 + 3 recovered 2022-12-30 2023-01-02 + 4 recovered 2022-12-29 2023-01-02 + 5 recovered 2023-01-01 2023-01-03 + 6 recovered 2023-01-03 2023-01-04 + 7 recovered 2023-01-04 2023-01-05 + 8 recovered 2023-01-01 2023-01-04 + 9 died 2023-01-12 2022-12-31 2023-01-03 + 10 recovered 2022-12-30 2023-01-03 + 11 recovered 2023-01-01 2023-01-04 + 12 recovered 2023-01-01 2023-01-03 # sim_linelist works as expected with anonymous @@ -109,30 +109,30 @@ Output id case_type sex age date_onset date_admission outcome date_outcome 1 1 confirmed m 35 2023-01-01 recovered - 2 2 probable m 43 2023-01-01 recovered + 2 2 suspected m 43 2023-01-01 recovered 3 3 probable m 1 2023-01-01 recovered 4 5 confirmed m 78 2023-01-01 recovered 5 6 confirmed f 22 2023-01-01 recovered 6 8 confirmed f 28 2023-01-01 recovered 7 11 confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 confirmed f 67 2023-01-01 recovered - 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-09 - 10 18 confirmed f 60 2023-01-02 recovered + 8 12 suspected f 67 2023-01-01 recovered + 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-12 + 10 18 suspected f 60 2023-01-02 recovered 11 20 confirmed m 49 2023-01-02 recovered 12 22 confirmed f 7 2023-01-02 2023-01-02 recovered date_first_contact date_last_contact ct_value - 1 24.9 + 1 23.9 2 2022-12-30 2023-01-05 NA 3 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 24.9 - 5 2023-01-01 2023-01-03 24.9 - 6 2023-01-03 2023-01-04 24.9 - 7 2023-01-04 2023-01-05 24.9 - 8 2023-01-01 2023-01-04 24.9 - 9 2022-12-31 2023-01-03 24.9 - 10 2022-12-30 2023-01-03 24.9 - 11 2023-01-01 2023-01-04 24.9 - 12 2023-01-01 2023-01-03 24.9 + 4 2022-12-29 2023-01-02 23.9 + 5 2023-01-01 2023-01-03 23.9 + 6 2023-01-03 2023-01-04 23.9 + 7 2023-01-04 2023-01-05 23.9 + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 23.9 + 10 2022-12-30 2023-01-03 NA + 11 2023-01-01 2023-01-04 23.9 + 12 2023-01-01 2023-01-03 23.9 # sim_linelist works as expected with age structure @@ -141,32 +141,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, population_age = age_struct) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gene Than probable m 44 2023-01-01 recovered - 2 2 Caleb Fredericks probable m 13 2023-01-01 recovered - 3 3 Jaisean Venable suspected m 22 2023-01-01 2023-01-09 died - 4 5 Taylor Swift probable m 85 2023-01-01 recovered - 5 6 Korren Bailey confirmed f 41 2023-01-01 recovered - 6 8 Madison Zahn confirmed f 89 2023-01-01 2023-01-02 recovered - 7 11 Dustin Bellow confirmed m 69 2023-01-01 recovered - 8 12 Ryanna Hart confirmed f 23 2023-01-01 recovered - 9 13 Rafael Garcia confirmed m 9 2023-01-01 recovered - 10 18 Ashlan Hendon confirmed f 62 2023-01-02 recovered - 11 20 Tieran Moorer suspected m 52 2023-01-02 2023-01-15 recovered - 12 22 Paige Reich probable f 76 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Kyle Crane suspected m 44 2023-01-01 recovered + 2 2 Ghaamid el-Ishmael confirmed m 13 2023-01-01 recovered + 3 3 Faatih el-Kaiser confirmed m 22 2023-01-01 2023-01-09 recovered + 4 5 Va'Aahi Galligan suspected m 85 2023-01-01 recovered + 5 6 Katelyn Catlin confirmed f 41 2023-01-01 recovered + 6 8 Lynsey Duron confirmed f 89 2023-01-01 2023-01-02 died + 7 11 Wajdi al-Demian confirmed m 69 2023-01-01 recovered + 8 12 Jacy Cousins confirmed f 23 2023-01-01 recovered + 9 13 Travis Foster confirmed m 9 2023-01-01 recovered + 10 18 Maria Eberhart probable f 62 2023-01-02 recovered + 11 20 Mubarak el-Vaziri suspected m 52 2023-01-02 2023-01-15 recovered + 12 22 Erin Payson confirmed f 76 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA - 2 2022-12-30 2023-01-05 NA - 3 2023-01-12 2022-12-30 2023-01-02 NA + 2 2022-12-30 2023-01-05 25.1 + 3 2022-12-30 2023-01-02 25.1 4 2022-12-29 2023-01-02 NA - 5 2023-01-01 2023-01-03 24 - 6 2023-01-03 2023-01-04 24 - 7 2023-01-04 2023-01-05 24 - 8 2023-01-01 2023-01-04 24 - 9 2022-12-31 2023-01-03 24 - 10 2022-12-30 2023-01-03 24 + 5 2023-01-01 2023-01-03 25.1 + 6 2023-01-26 2023-01-03 2023-01-04 25.1 + 7 2023-01-04 2023-01-05 25.1 + 8 2023-01-01 2023-01-04 25.1 + 9 2022-12-31 2023-01-03 25.1 + 10 2022-12-30 2023-01-03 NA 11 2023-01-01 2023-01-04 NA - 12 2023-01-01 2023-01-03 NA + 12 2023-01-01 2023-01-03 25.1 # sim_linelist works as expected with age-strat risks & age struct @@ -175,32 +175,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, hosp_risk = age_dep_hosp_risk, population_age = age_struct) Output - id case_name case_type sex age date_onset date_admission - 1 1 Damion Hamm confirmed m 44 2023-01-01 - 2 2 Ignacio Hernandez confirmed m 13 2023-01-01 - 3 3 Bryce Donnelly confirmed m 22 2023-01-01 - 4 5 David Arrieta confirmed m 85 2023-01-01 2023-01-01 - 5 6 Kristina Vazquez Pallares confirmed f 41 2023-01-01 - 6 8 Nusaiba el-Farah suspected f 89 2023-01-01 - 7 11 Dominic Kills In Sight probable m 69 2023-01-01 - 8 12 Violet Watts confirmed f 23 2023-01-01 - 9 13 Khristopher Cunniff confirmed m 9 2023-01-01 - 10 18 Paige Reich probable f 62 2023-01-02 - 11 20 Jackson Carlson confirmed m 52 2023-01-02 - 12 22 Cassandra Smith suspected f 76 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered 25.6 - 2 recovered 2022-12-30 2023-01-05 25.6 - 3 recovered 2022-12-30 2023-01-02 25.6 - 4 died 2023-01-25 2022-12-29 2023-01-02 25.6 - 5 recovered 2023-01-01 2023-01-03 25.6 - 6 recovered 2023-01-03 2023-01-04 NA - 7 recovered 2023-01-04 2023-01-05 NA - 8 recovered 2023-01-01 2023-01-04 25.6 - 9 recovered 2022-12-31 2023-01-03 25.6 - 10 recovered 2022-12-30 2023-01-03 NA - 11 recovered 2023-01-01 2023-01-04 25.6 - 12 recovered 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Maazin el-Othman probable m 44 2023-01-01 recovered + 2 2 Faisal el-Vaziri confirmed m 13 2023-01-01 recovered + 3 3 Jorge Marten suspected m 22 2023-01-01 recovered + 4 5 Kaleb Natarelli confirmed m 85 2023-01-01 2023-01-01 recovered + 5 6 Hope Arshad suspected f 41 2023-01-01 recovered + 6 8 Shanta Holiday probable f 89 2023-01-01 recovered + 7 11 Nicholas Orgill probable m 69 2023-01-01 recovered + 8 12 Chandra Kilian suspected f 23 2023-01-01 recovered + 9 13 Corey Alcala confirmed m 9 2023-01-01 recovered + 10 18 Kanani Nguyen confirmed f 62 2023-01-02 recovered + 11 20 Sean Shrestha probable m 52 2023-01-02 recovered + 12 22 Annie Carter probable f 76 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 24.1 + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 24.1 + 5 2023-01-01 2023-01-03 NA + 6 2023-01-03 2023-01-04 NA + 7 2023-01-04 2023-01-05 NA + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 24.1 + 10 2022-12-30 2023-01-03 24.1 + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 NA # sim_linelist works as expected with modified config @@ -210,32 +210,32 @@ config = create_config(last_contact_distribution = "geom", last_contact_distribution_params = c(prob = 0.5))) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Maazina el-Kader probable f 20 2023-01-01 recovered - 2 2 Muneeb al-Youssef confirmed m 24 2023-01-01 recovered - 3 3 Francisco Huerta suspected m 51 2023-01-01 2023-01-07 recovered - 4 5 Sean Sundara confirmed m 16 2023-01-01 recovered - 5 6 Jack Walentine suspected m 83 2023-01-01 recovered - 6 8 Avery Temple probable m 48 2023-01-01 recovered - 7 11 Robert Gonzales probable m 77 2023-01-01 2023-01-01 recovered - 8 12 Timothy Cheek suspected m 90 2023-01-01 recovered - 9 13 Courtney Smith confirmed f 66 2023-01-01 recovered - 10 18 Jasra al-Hadi confirmed f 31 2023-01-02 2023-01-02 recovered - 11 20 Codie Patterson probable m 46 2023-01-02 recovered - 12 22 Eric Childs probable m 75 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Lily Camacho confirmed f 20 2023-01-01 recovered + 2 2 Sad el-Irani suspected m 24 2023-01-01 recovered + 3 3 Tristan Benjamin suspected m 51 2023-01-01 2023-01-07 recovered + 4 5 Treven Cornejo probable m 16 2023-01-01 recovered + 5 6 Kevin Contreras suspected m 83 2023-01-01 recovered + 6 8 Tyler Garcia suspected m 48 2023-01-01 recovered + 7 11 Royse Beltran probable m 77 2023-01-01 2023-01-01 recovered + 8 12 Clayton Falcon confirmed m 90 2023-01-01 recovered + 9 13 Halle Batchelder confirmed f 66 2023-01-01 recovered + 10 18 Morgan Grant-Perry confirmed f 31 2023-01-02 2023-01-02 recovered + 11 20 Bowen Apodaca confirmed m 46 2023-01-02 recovered + 12 22 Haaroon el-Firman confirmed m 75 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value - 1 NA - 2 2022-12-30 2023-01-01 24.1 + 1 24.7 + 2 2022-12-30 2023-01-01 NA 3 2022-12-31 2023-01-02 NA - 4 2022-12-30 2023-01-02 24.1 + 4 2022-12-30 2023-01-02 NA 5 2022-12-31 2023-01-01 NA 6 2022-12-31 2023-01-01 NA 7 2022-12-30 2023-01-02 NA - 8 2022-12-30 2023-01-01 NA - 9 2022-12-29 2023-01-01 24.1 - 10 2022-12-30 2023-01-01 24.1 - 11 2022-12-30 2023-01-01 NA - 12 2022-12-30 2023-01-02 NA + 8 2022-12-30 2023-01-01 24.7 + 9 2022-12-29 2023-01-01 24.7 + 10 2022-12-30 2023-01-01 24.7 + 11 2022-12-30 2023-01-01 24.7 + 12 2022-12-30 2023-01-02 24.7 # sim_linelist works as expected with modified config parameters @@ -244,32 +244,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, config = create_config(last_contact_distribution_params = c(lambda = 5))) Output - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gabriel Black probable m 35 2023-01-01 recovered - 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered - 3 3 Cody Morales suspected m 1 2023-01-01 recovered - 4 5 Joewid Le probable m 78 2023-01-01 recovered - 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered - 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 Kendra To suspected f 67 2023-01-01 recovered - 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died - 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered - 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered - date_outcome date_first_contact date_last_contact ct_value - 1 NA - 2 2023-01-01 2023-01-07 24 - 3 2022-12-31 2023-01-03 NA - 4 2022-12-31 2023-01-04 NA - 5 2023-01-02 2023-01-04 24 - 6 2023-01-06 2023-01-07 24 - 7 2023-01-07 2023-01-08 24 - 8 2023-01-03 2023-01-06 NA - 9 2023-01-09 2023-01-02 2023-01-05 24 - 10 2023-01-01 2023-01-05 24 - 11 2023-01-04 2023-01-07 NA - 12 2023-01-03 2023-01-05 NA + id case_name case_type sex age date_onset date_admission + 1 1 Dominic Sundara probable m 35 2023-01-01 + 2 2 Preston Montgomery suspected m 43 2023-01-01 + 3 3 Reece Chittum probable m 1 2023-01-01 + 4 5 Michael Cheek confirmed m 78 2023-01-01 + 5 6 Jennifer Smith confirmed f 22 2023-01-01 + 6 8 Erika Quintero confirmed f 28 2023-01-01 + 7 11 Isaiah Patterson suspected m 46 2023-01-01 2023-01-13 + 8 12 Cicely Anderson suspected f 67 2023-01-01 + 9 13 Michael John probable m 86 2023-01-01 2023-01-01 + 10 18 Giovana Magana Aguirre suspected f 60 2023-01-02 + 11 20 Mudrik al-Hallal suspected m 49 2023-01-02 + 12 22 Tea Slaughter probable f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered NA + 2 recovered 2023-01-01 2023-01-07 NA + 3 recovered 2022-12-31 2023-01-03 NA + 4 recovered 2022-12-31 2023-01-04 23.1 + 5 recovered 2023-01-02 2023-01-04 23.1 + 6 recovered 2023-01-06 2023-01-07 23.1 + 7 recovered 2023-01-07 2023-01-08 NA + 8 recovered 2023-01-03 2023-01-06 NA + 9 died 2023-01-12 2023-01-02 2023-01-05 NA + 10 recovered 2023-01-01 2023-01-05 NA + 11 recovered 2023-01-04 2023-01-07 NA + 12 recovered 2023-01-03 2023-01-05 NA # sim_linelist works as expected with time-varying cfr @@ -279,32 +279,32 @@ config = create_config(time_varying_death_risk = function(risk, time) risk * exp(-time))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Bryce Kelley probable m 35 2023-01-01 - 2 2 Cleatus Kacprowicz confirmed m 43 2023-01-01 - 3 3 Khristopher Carlson suspected m 1 2023-01-01 - 4 5 Raynaldo Grano probable m 78 2023-01-01 - 5 6 Carolyn Moore confirmed f 22 2023-01-01 - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 - 7 11 Abdul Maalik al-Chahine confirmed m 46 2023-01-01 2023-01-13 - 8 12 Kendra To suspected f 67 2023-01-01 - 9 13 Joewid Le confirmed m 86 2023-01-01 2023-01-01 - 10 18 Dominique Raymond confirmed f 60 2023-01-02 - 11 20 Jackson Sheek probable m 49 2023-01-02 - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered NA - 2 recovered 2022-12-30 2023-01-05 24 - 3 recovered 2022-12-30 2023-01-02 NA - 4 recovered 2022-12-29 2023-01-02 NA - 5 recovered 2023-01-01 2023-01-03 24 - 6 recovered 2023-01-03 2023-01-04 24 - 7 recovered 2023-01-04 2023-01-05 24 - 8 recovered 2023-01-01 2023-01-04 NA - 9 recovered 2022-12-31 2023-01-03 24 - 10 recovered 2022-12-30 2023-01-03 24 - 11 recovered 2023-01-01 2023-01-04 NA - 12 recovered 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Anthony Raigoza suspected m 35 2023-01-01 recovered + 2 2 Joseph Begay probable m 43 2023-01-01 recovered + 3 3 Andi Lee probable m 1 2023-01-01 recovered + 4 5 Robert Duran suspected m 78 2023-01-01 recovered + 5 6 Mikhaila Guyon confirmed f 22 2023-01-01 recovered + 6 8 Kanani Ahn confirmed f 28 2023-01-01 recovered + 7 11 Michael Chittum probable m 46 2023-01-01 2023-01-13 recovered + 8 12 Hope Cobb probable f 67 2023-01-01 recovered + 9 13 Eric Lopez confirmed m 86 2023-01-01 2023-01-01 recovered + 10 18 Kelly Carter probable f 60 2023-01-02 recovered + 11 20 Turki el-Vaziri probable m 49 2023-01-02 recovered + 12 22 Cicely Shangreaux confirmed f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 25.4 + 6 2023-01-03 2023-01-04 25.4 + 7 2023-01-04 2023-01-05 NA + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 25.4 + 10 2022-12-30 2023-01-03 NA + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 25.4 # sim_linelist works as expected with time-varying cfr & age-strat @@ -314,30 +314,30 @@ hosp_death_risk = age_dep_hosp_death_risk, config = create_config( time_varying_death_risk = function(risk, time) risk * exp(-time))) Output - id case_name case_type sex age date_onset date_admission - 1 1 Bryce Kelley probable m 35 2023-01-01 - 2 2 Cleatus Kacprowicz confirmed m 43 2023-01-01 - 3 3 Khristopher Carlson suspected m 1 2023-01-01 - 4 5 Raynaldo Grano probable m 78 2023-01-01 - 5 6 Carolyn Moore confirmed f 22 2023-01-01 - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 - 7 11 Abdul Maalik al-Chahine confirmed m 46 2023-01-01 2023-01-13 - 8 12 Kendra To suspected f 67 2023-01-01 - 9 13 Joewid Le confirmed m 86 2023-01-01 2023-01-01 - 10 18 Dominique Raymond confirmed f 60 2023-01-02 - 11 20 Jackson Sheek probable m 49 2023-01-02 - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 - outcome date_outcome date_first_contact date_last_contact ct_value - 1 recovered NA - 2 recovered 2022-12-30 2023-01-05 24 - 3 recovered 2022-12-30 2023-01-02 NA - 4 recovered 2022-12-29 2023-01-02 NA - 5 recovered 2023-01-01 2023-01-03 24 - 6 recovered 2023-01-03 2023-01-04 24 - 7 recovered 2023-01-04 2023-01-05 24 - 8 recovered 2023-01-01 2023-01-04 NA - 9 recovered 2022-12-31 2023-01-03 24 - 10 recovered 2022-12-30 2023-01-03 24 - 11 recovered 2023-01-01 2023-01-04 NA - 12 recovered 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission outcome + 1 1 Anthony Raigoza suspected m 35 2023-01-01 recovered + 2 2 Joseph Begay probable m 43 2023-01-01 recovered + 3 3 Andi Lee probable m 1 2023-01-01 recovered + 4 5 Robert Duran suspected m 78 2023-01-01 recovered + 5 6 Mikhaila Guyon confirmed f 22 2023-01-01 recovered + 6 8 Kanani Ahn confirmed f 28 2023-01-01 recovered + 7 11 Michael Chittum probable m 46 2023-01-01 2023-01-13 recovered + 8 12 Hope Cobb probable f 67 2023-01-01 recovered + 9 13 Eric Lopez confirmed m 86 2023-01-01 2023-01-01 recovered + 10 18 Kelly Carter probable f 60 2023-01-02 recovered + 11 20 Turki el-Vaziri probable m 49 2023-01-02 recovered + 12 22 Cicely Shangreaux confirmed f 7 2023-01-02 2023-01-02 recovered + date_outcome date_first_contact date_last_contact ct_value + 1 NA + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 NA + 5 2023-01-01 2023-01-03 25.4 + 6 2023-01-03 2023-01-04 25.4 + 7 2023-01-04 2023-01-05 NA + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 25.4 + 10 2022-12-30 2023-01-03 NA + 11 2023-01-01 2023-01-04 NA + 12 2023-01-01 2023-01-03 25.4 diff --git a/tests/testthat/_snaps/sim_outbreak.md b/tests/testthat/_snaps/sim_outbreak.md index 8e97962f..a02f8b01 100644 --- a/tests/testthat/_snaps/sim_outbreak.md +++ b/tests/testthat/_snaps/sim_outbreak.md @@ -5,78 +5,78 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death) Output $linelist - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gabriel Black probable m 35 2023-01-01 recovered - 2 2 Tyler Kelley confirmed m 43 2023-01-01 recovered - 3 3 Cody Morales suspected m 1 2023-01-01 recovered - 4 5 Joewid Le probable m 78 2023-01-01 recovered - 5 6 Carolyn Moore confirmed f 22 2023-01-01 recovered - 6 8 Cheyenne Sayavong confirmed f 28 2023-01-01 recovered - 7 11 Pierce Khanthavong confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 Kendra To suspected f 67 2023-01-01 recovered - 9 13 Preston Barringer confirmed m 86 2023-01-01 2023-01-01 died - 10 18 Dominique Raymond confirmed f 60 2023-01-02 recovered - 11 20 Bassaam el-Majid probable m 49 2023-01-02 recovered - 12 22 Susana Varela probable f 7 2023-01-02 2023-01-02 recovered - date_outcome date_first_contact date_last_contact ct_value - 1 NA - 2 2022-12-30 2023-01-05 24 - 3 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 NA - 5 2023-01-01 2023-01-03 24 - 6 2023-01-03 2023-01-04 24 - 7 2023-01-04 2023-01-05 24 - 8 2023-01-01 2023-01-04 NA - 9 2023-01-09 2022-12-31 2023-01-03 24 - 10 2022-12-30 2023-01-03 24 - 11 2023-01-01 2023-01-04 NA - 12 2023-01-01 2023-01-03 NA + id case_name case_type sex age date_onset date_admission + 1 1 Dominic Sundara probable m 35 2023-01-01 + 2 2 Preston Montgomery suspected m 43 2023-01-01 + 3 3 Reece Chittum probable m 1 2023-01-01 + 4 5 Michael Cheek confirmed m 78 2023-01-01 + 5 6 Jennifer Smith confirmed f 22 2023-01-01 + 6 8 Erika Quintero confirmed f 28 2023-01-01 + 7 11 Isaiah Patterson suspected m 46 2023-01-01 2023-01-13 + 8 12 Cicely Anderson suspected f 67 2023-01-01 + 9 13 Michael John probable m 86 2023-01-01 2023-01-01 + 10 18 Giovana Magana Aguirre suspected f 60 2023-01-02 + 11 20 Mudrik al-Hallal suspected m 49 2023-01-02 + 12 22 Tea Slaughter probable f 7 2023-01-02 2023-01-02 + outcome date_outcome date_first_contact date_last_contact ct_value + 1 recovered NA + 2 recovered 2022-12-30 2023-01-05 NA + 3 recovered 2022-12-30 2023-01-02 NA + 4 recovered 2022-12-29 2023-01-02 23.1 + 5 recovered 2023-01-01 2023-01-03 23.1 + 6 recovered 2023-01-03 2023-01-04 23.1 + 7 recovered 2023-01-04 2023-01-05 NA + 8 recovered 2023-01-01 2023-01-04 NA + 9 died 2023-01-12 2022-12-31 2023-01-03 NA + 10 recovered 2022-12-30 2023-01-03 NA + 11 recovered 2023-01-01 2023-01-04 NA + 12 recovered 2023-01-01 2023-01-03 NA $contacts - from to age sex date_first_contact - 1 Gabriel Black Tyler Kelley 43 m 2022-12-30 - 2 Gabriel Black Cody Morales 1 m 2022-12-30 - 3 Tyler Kelley Taylor Graves 29 f 2022-12-27 - 4 Tyler Kelley Joewid Le 78 m 2022-12-29 - 5 Cody Morales Carolyn Moore 22 f 2023-01-01 - 6 Cody Morales Rushdi al-Ishak 70 m 2022-12-30 - 7 Cody Morales Cheyenne Sayavong 28 f 2023-01-03 - 8 Joewid Le Mercedes Lovelace 37 f 2023-01-06 - 9 Carolyn Moore Chantelle Vazquez-Luevano 61 f 2023-01-01 - 10 Cheyenne Sayavong Pierce Khanthavong 46 m 2023-01-04 - 11 Cheyenne Sayavong Kendra To 67 f 2023-01-01 - 12 Cheyenne Sayavong Preston Barringer 86 m 2022-12-31 - 13 Pierce Khanthavong Jackson Carlson 71 m 2022-12-28 - 14 Pierce Khanthavong Megan Hayes 51 f 2023-01-01 - 15 Pierce Khanthavong Sam Spencer 44 m 2023-01-02 - 16 Kendra To Amanda Larochelle 49 f 2023-01-02 - 17 Preston Barringer Dominique Raymond 60 f 2022-12-30 - 18 Preston Barringer Natalie Newton 56 f 2023-01-06 - 19 Preston Barringer Bassaam el-Majid 49 m 2023-01-01 - 20 Preston Barringer Qaaid al-Madani 50 m 2023-01-01 - 21 Dominique Raymond Susana Varela 7 f 2023-01-01 - date_last_contact was_case status - 1 2023-01-05 Y case - 2 2023-01-02 Y case - 3 2023-01-03 N unknown - 4 2023-01-02 Y case - 5 2023-01-03 Y case - 6 2023-01-02 N under_followup - 7 2023-01-04 Y case - 8 2023-01-06 N under_followup - 9 2023-01-05 N under_followup - 10 2023-01-05 Y case - 11 2023-01-04 Y case - 12 2023-01-03 Y case - 13 2023-01-05 N under_followup - 14 2023-01-04 N lost_to_followup - 15 2023-01-05 N under_followup - 16 2023-01-03 N under_followup - 17 2023-01-03 Y case - 18 2023-01-09 N unknown - 19 2023-01-04 Y case - 20 2023-01-03 N under_followup - 21 2023-01-03 Y case + from to age sex date_first_contact + 1 Dominic Sundara Preston Montgomery 43 m 2022-12-30 + 2 Dominic Sundara Reece Chittum 1 m 2022-12-30 + 3 Preston Montgomery Kayla Hill 29 f 2022-12-27 + 4 Preston Montgomery Michael Cheek 78 m 2022-12-29 + 5 Reece Chittum Jennifer Smith 22 f 2023-01-01 + 6 Reece Chittum Jaylyn Childs 70 m 2022-12-30 + 7 Reece Chittum Erika Quintero 28 f 2023-01-03 + 8 Michael Cheek Kelly Fitzsimmons 37 f 2023-01-06 + 9 Jennifer Smith Audreon Starkey 61 f 2023-01-01 + 10 Erika Quintero Isaiah Patterson 46 m 2023-01-04 + 11 Erika Quintero Cicely Anderson 67 f 2023-01-01 + 12 Erika Quintero Michael John 86 m 2022-12-31 + 13 Isaiah Patterson Muneeb al-Jamil 71 m 2022-12-28 + 14 Isaiah Patterson Juwairiya el-Abdelrahman 51 f 2023-01-01 + 15 Isaiah Patterson Bishr al-Youssef 44 m 2023-01-02 + 16 Cicely Anderson Samantha Gonzalez 49 f 2023-01-02 + 17 Michael John Giovana Magana Aguirre 60 f 2022-12-30 + 18 Michael John Michiyo Batara 56 f 2023-01-06 + 19 Michael John Mudrik al-Hallal 49 m 2023-01-01 + 20 Michael John Dominic Gonzales 50 m 2023-01-01 + 21 Giovana Magana Aguirre Tea Slaughter 7 f 2023-01-01 + date_last_contact was_case status + 1 2023-01-05 Y case + 2 2023-01-02 Y case + 3 2023-01-03 N under_followup + 4 2023-01-02 Y case + 5 2023-01-03 Y case + 6 2023-01-02 N under_followup + 7 2023-01-04 Y case + 8 2023-01-06 N under_followup + 9 2023-01-05 N under_followup + 10 2023-01-05 Y case + 11 2023-01-04 Y case + 12 2023-01-03 Y case + 13 2023-01-05 N under_followup + 14 2023-01-04 N under_followup + 15 2023-01-05 N under_followup + 16 2023-01-03 N under_followup + 17 2023-01-03 Y case + 18 2023-01-09 N unknown + 19 2023-01-04 Y case + 20 2023-01-03 N under_followup + 21 2023-01-03 Y case # sim_outbreak works as expected with add_names = FALSE @@ -89,76 +89,76 @@ $linelist id case_type sex age date_onset date_admission outcome date_outcome 1 1 confirmed m 35 2023-01-01 recovered - 2 2 probable m 43 2023-01-01 recovered + 2 2 suspected m 43 2023-01-01 recovered 3 3 probable m 1 2023-01-01 recovered 4 5 confirmed m 78 2023-01-01 recovered 5 6 confirmed f 22 2023-01-01 recovered 6 8 confirmed f 28 2023-01-01 recovered 7 11 confirmed m 46 2023-01-01 2023-01-13 recovered - 8 12 confirmed f 67 2023-01-01 recovered - 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-09 - 10 18 confirmed f 60 2023-01-02 recovered + 8 12 suspected f 67 2023-01-01 recovered + 9 13 confirmed m 86 2023-01-01 2023-01-01 died 2023-01-12 + 10 18 suspected f 60 2023-01-02 recovered 11 20 confirmed m 49 2023-01-02 recovered 12 22 confirmed f 7 2023-01-02 2023-01-02 recovered date_first_contact date_last_contact ct_value - 1 24.9 + 1 23.9 2 2022-12-30 2023-01-05 NA 3 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 24.9 - 5 2023-01-01 2023-01-03 24.9 - 6 2023-01-03 2023-01-04 24.9 - 7 2023-01-04 2023-01-05 24.9 - 8 2023-01-01 2023-01-04 24.9 - 9 2022-12-31 2023-01-03 24.9 - 10 2022-12-30 2023-01-03 24.9 - 11 2023-01-01 2023-01-04 24.9 - 12 2023-01-01 2023-01-03 24.9 + 4 2022-12-29 2023-01-02 23.9 + 5 2023-01-01 2023-01-03 23.9 + 6 2023-01-03 2023-01-04 23.9 + 7 2023-01-04 2023-01-05 23.9 + 8 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 23.9 + 10 2022-12-30 2023-01-03 NA + 11 2023-01-01 2023-01-04 23.9 + 12 2023-01-01 2023-01-03 23.9 $contacts - from to age sex date_first_contact - 1 Wajdi al-Demian Raaid el-Diab 43 m 2022-12-30 - 2 Wajdi al-Demian Nickolas Nault 1 m 2022-12-30 - 3 Raaid el-Diab Durine Cobb 29 f 2022-12-27 - 4 Raaid el-Diab Hee Kennedy 78 m 2022-12-29 - 5 Nickolas Nault Hope Arshad 22 f 2023-01-01 - 6 Nickolas Nault Mubarak el-Vaziri 70 m 2022-12-30 - 7 Nickolas Nault Shanta Holiday 28 f 2023-01-03 - 8 Hee Kennedy Darian Guyon 37 f 2023-01-06 - 9 Hope Arshad Mackenzie Ahn 61 f 2023-01-01 - 10 Shanta Holiday Raakaan al-Shams 46 m 2023-01-04 - 11 Shanta Holiday Chandra Kilian 67 f 2023-01-01 - 12 Shanta Holiday Ricardo Sanchez 86 m 2022-12-31 - 13 Raakaan al-Shams Tae Woo Nguyen 71 m 2022-12-28 - 14 Raakaan al-Shams Mikhaila Carlson 51 f 2023-01-01 - 15 Raakaan al-Shams Alexander Orio 44 m 2023-01-02 - 16 Chandra Kilian Alexandra Johnson 49 f 2023-01-02 - 17 Ricardo Sanchez Kanani Nguyen 60 f 2022-12-30 - 18 Ricardo Sanchez Nirvana Elizalde Villa 56 f 2023-01-06 - 19 Ricardo Sanchez Jared Chambers 49 m 2023-01-01 - 20 Ricardo Sanchez Thomas Morales 50 m 2023-01-01 - 21 Kanani Nguyen Annie Carter 7 f 2023-01-01 - date_last_contact was_case status - 1 2023-01-05 Y case - 2 2023-01-02 Y case - 3 2023-01-03 N under_followup - 4 2023-01-02 Y case - 5 2023-01-03 Y case - 6 2023-01-02 N under_followup - 7 2023-01-04 Y case - 8 2023-01-06 N unknown - 9 2023-01-05 N under_followup - 10 2023-01-05 Y case - 11 2023-01-04 Y case - 12 2023-01-03 Y case - 13 2023-01-05 N lost_to_followup - 14 2023-01-04 N lost_to_followup - 15 2023-01-05 N under_followup - 16 2023-01-03 N lost_to_followup - 17 2023-01-03 Y case - 18 2023-01-09 N under_followup - 19 2023-01-04 Y case - 20 2023-01-03 N under_followup - 21 2023-01-03 Y case + from to age sex date_first_contact + 1 Jonah Hord Benjamin Flowers 43 m 2022-12-30 + 2 Jonah Hord Rito Cooper 1 m 2022-12-30 + 3 Benjamin Flowers Claire Hicks 29 f 2022-12-27 + 4 Benjamin Flowers Jeremy Loughridge 78 m 2022-12-29 + 5 Rito Cooper Ashwini Ali 22 f 2023-01-01 + 6 Rito Cooper Rory Jumbo 70 m 2022-12-30 + 7 Rito Cooper Danielle Kuhn 28 f 2023-01-03 + 8 Jeremy Loughridge Gicell Cisneros 37 f 2023-01-06 + 9 Ashwini Ali Lauren Nguyen 61 f 2023-01-01 + 10 Danielle Kuhn Thaamir al-Amini 46 m 2023-01-04 + 11 Danielle Kuhn Selena Chun 67 f 2023-01-01 + 12 Danielle Kuhn Charles Stuart Rasi 86 m 2022-12-31 + 13 Thaamir al-Amini Jose Hurtado 71 m 2022-12-28 + 14 Thaamir al-Amini Brianne Shahid 51 f 2023-01-01 + 15 Thaamir al-Amini Efren Armijo 44 m 2023-01-02 + 16 Selena Chun Juanita Martinez 49 f 2023-01-02 + 17 Charles Stuart Rasi Hannah Bodnar 60 f 2022-12-30 + 18 Charles Stuart Rasi Kifaaya el-Ameen 56 f 2023-01-06 + 19 Charles Stuart Rasi Enrique Ponce 49 m 2023-01-01 + 20 Charles Stuart Rasi Jaarallah al-Masood 50 m 2023-01-01 + 21 Hannah Bodnar Ashley Isaac 7 f 2023-01-01 + date_last_contact was_case status + 1 2023-01-05 Y case + 2 2023-01-02 Y case + 3 2023-01-03 N under_followup + 4 2023-01-02 Y case + 5 2023-01-03 Y case + 6 2023-01-02 N under_followup + 7 2023-01-04 Y case + 8 2023-01-06 N under_followup + 9 2023-01-05 N under_followup + 10 2023-01-05 Y case + 11 2023-01-04 Y case + 12 2023-01-03 Y case + 13 2023-01-05 N unknown + 14 2023-01-04 N under_followup + 15 2023-01-05 N under_followup + 16 2023-01-03 N under_followup + 17 2023-01-03 Y case + 18 2023-01-09 N under_followup + 19 2023-01-04 Y case + 20 2023-01-03 N unknown + 21 2023-01-03 Y case # sim_outbreak works as expected with age-strat risks @@ -170,78 +170,78 @@ non_hosp_death_risk = age_dep_non_hosp_death_risk) Output $linelist - id case_name case_type sex age date_onset date_admission outcome - 1 1 Micheal Smallwood probable m 35 2023-01-01 recovered - 2 2 Kyle Foster confirmed m 43 2023-01-01 recovered - 3 3 Ghaamid el-Kaiser suspected m 1 2023-01-01 2023-01-11 died - 4 5 Faatih el-Riaz confirmed m 78 2023-01-01 recovered - 5 6 Hope Arshad suspected f 22 2023-01-01 recovered - 6 8 Shanta Holiday probable f 28 2023-01-01 recovered - 7 11 Aiman al-Demian probable m 46 2023-01-01 recovered - 8 12 Chandra Kilian suspected f 67 2023-01-01 recovered - 9 13 Wajdi el-Diab confirmed m 86 2023-01-01 2023-01-01 recovered - 10 18 Kanani Nguyen confirmed f 60 2023-01-02 recovered - 11 20 Raaid el-Vaziri probable m 49 2023-01-02 2023-01-09 recovered - 12 22 Annie Carter probable f 7 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Cass Duran probable m 35 2023-01-01 recovered + 2 2 Mudrik al-Hallal suspected m 43 2023-01-01 recovered + 3 3 Jareer al-Safar probable m 1 2023-01-01 2023-01-11 recovered + 4 5 Raashid el-Huda confirmed m 78 2023-01-01 recovered + 5 6 Erika Sierra confirmed f 22 2023-01-01 recovered + 6 8 Jennifer Hong confirmed f 28 2023-01-01 recovered + 7 11 Donald Childs suspected m 46 2023-01-01 recovered + 8 12 Kayla Johnson suspected f 67 2023-01-01 died + 9 13 Avery Johnston probable m 86 2023-01-01 2023-01-01 recovered + 10 18 Giovana Segarra suspected f 60 2023-01-02 recovered + 11 20 Donald Root suspected m 49 2023-01-02 2023-01-09 recovered + 12 22 Kiona Dalke probable f 7 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA - 2 2022-12-30 2023-01-05 24.1 - 3 2023-01-14 2022-12-30 2023-01-02 NA - 4 2022-12-29 2023-01-02 24.1 - 5 2023-01-01 2023-01-03 NA - 6 2023-01-03 2023-01-04 NA + 2 2022-12-30 2023-01-05 NA + 3 2022-12-30 2023-01-02 NA + 4 2022-12-29 2023-01-02 23.1 + 5 2023-01-01 2023-01-03 23.1 + 6 2023-01-03 2023-01-04 23.1 7 2023-01-04 2023-01-05 NA - 8 2023-01-01 2023-01-04 NA - 9 2022-12-31 2023-01-03 24.1 - 10 2022-12-30 2023-01-03 24.1 + 8 2023-01-14 2023-01-01 2023-01-04 NA + 9 2022-12-31 2023-01-03 NA + 10 2022-12-30 2023-01-03 NA 11 2023-01-01 2023-01-04 NA 12 2023-01-01 2023-01-03 NA $contacts - from to age sex date_first_contact - 1 Micheal Smallwood Kyle Foster 43 m 2022-12-30 - 2 Micheal Smallwood Ghaamid el-Kaiser 1 m 2022-12-30 - 3 Kyle Foster Durine Cobb 29 f 2022-12-27 - 4 Kyle Foster Faatih el-Riaz 78 m 2022-12-29 - 5 Ghaamid el-Kaiser Hope Arshad 22 f 2023-01-01 - 6 Ghaamid el-Kaiser Jonathan Takahashi 70 m 2022-12-30 - 7 Ghaamid el-Kaiser Shanta Holiday 28 f 2023-01-03 - 8 Faatih el-Riaz Darian Guyon 37 f 2023-01-06 - 9 Hope Arshad Mackenzie Ahn 61 f 2023-01-01 - 10 Shanta Holiday Aiman al-Demian 46 m 2023-01-04 - 11 Shanta Holiday Chandra Kilian 67 f 2023-01-01 - 12 Shanta Holiday Wajdi el-Diab 86 m 2022-12-31 - 13 Aiman al-Demian Travis Summers 71 m 2022-12-28 - 14 Aiman al-Demian Mikhaila Carlson 51 f 2023-01-01 - 15 Aiman al-Demian Cory Galligan 44 m 2023-01-02 - 16 Chandra Kilian Alexandra Johnson 49 f 2023-01-02 - 17 Wajdi el-Diab Kanani Nguyen 60 f 2022-12-30 - 18 Wajdi el-Diab Nirvana Elizalde Villa 56 f 2023-01-06 - 19 Wajdi el-Diab Raaid el-Vaziri 49 m 2023-01-01 - 20 Wajdi el-Diab Mubarak al-Shams 50 m 2023-01-01 - 21 Kanani Nguyen Annie Carter 7 f 2023-01-01 - date_last_contact was_case status - 1 2023-01-05 Y case - 2 2023-01-02 Y case - 3 2023-01-03 N under_followup - 4 2023-01-02 Y case - 5 2023-01-03 Y case - 6 2023-01-02 N under_followup - 7 2023-01-04 Y case - 8 2023-01-06 N under_followup - 9 2023-01-05 N lost_to_followup - 10 2023-01-05 Y case - 11 2023-01-04 Y case - 12 2023-01-03 Y case - 13 2023-01-05 N lost_to_followup - 14 2023-01-04 N under_followup - 15 2023-01-05 N under_followup - 16 2023-01-03 N under_followup - 17 2023-01-03 Y case - 18 2023-01-09 N unknown - 19 2023-01-04 Y case - 20 2023-01-03 N lost_to_followup - 21 2023-01-03 Y case + from to age sex date_first_contact + 1 Cass Duran Mudrik al-Hallal 43 m 2022-12-30 + 2 Cass Duran Jareer al-Safar 1 m 2022-12-30 + 3 Mudrik al-Hallal Kaitlynne Rieger 29 f 2022-12-27 + 4 Mudrik al-Hallal Raashid el-Huda 78 m 2022-12-29 + 5 Jareer al-Safar Erika Sierra 22 f 2023-01-01 + 6 Jareer al-Safar Preston Huerta 70 m 2022-12-30 + 7 Jareer al-Safar Jennifer Hong 28 f 2023-01-03 + 8 Raashid el-Huda Kaitlin Gonzalez 37 f 2023-01-06 + 9 Erika Sierra Marissa Slaughter 61 f 2023-01-01 + 10 Jennifer Hong Donald Childs 46 m 2023-01-04 + 11 Jennifer Hong Kayla Johnson 67 f 2023-01-01 + 12 Jennifer Hong Avery Johnston 86 m 2022-12-31 + 13 Donald Childs Lorenzo Gaynor 71 m 2022-12-28 + 14 Donald Childs Michiyo Tran 51 f 2023-01-01 + 15 Donald Childs Ethan Black 44 m 2023-01-02 + 16 Kayla Johnson Marzooqa el-Abdelrahman 49 f 2023-01-02 + 17 Avery Johnston Giovana Segarra 60 f 2022-12-30 + 18 Avery Johnston Kaylie Shangreaux 56 f 2023-01-06 + 19 Avery Johnston Donald Root 49 m 2023-01-01 + 20 Avery Johnston Hunter Simmons 50 m 2023-01-01 + 21 Giovana Segarra Kiona Dalke 7 f 2023-01-01 + date_last_contact was_case status + 1 2023-01-05 Y case + 2 2023-01-02 Y case + 3 2023-01-03 N under_followup + 4 2023-01-02 Y case + 5 2023-01-03 Y case + 6 2023-01-02 N under_followup + 7 2023-01-04 Y case + 8 2023-01-06 N under_followup + 9 2023-01-05 N under_followup + 10 2023-01-05 Y case + 11 2023-01-04 Y case + 12 2023-01-03 Y case + 13 2023-01-05 N under_followup + 14 2023-01-04 N under_followup + 15 2023-01-05 N under_followup + 16 2023-01-03 N under_followup + 17 2023-01-03 Y case + 18 2023-01-09 N unknown + 19 2023-01-04 Y case + 20 2023-01-03 N under_followup + 21 2023-01-03 Y case # sim_outbreak works as expected with age structure @@ -252,56 +252,56 @@ population_age = age_struct) Output $linelist - id case_name case_type sex age date_onset date_admission outcome - 1 1 Gene Than probable m 44 2023-01-01 recovered - 2 2 Caleb Fredericks probable m 13 2023-01-01 recovered - 3 3 Jaisean Venable suspected m 22 2023-01-01 2023-01-09 died - 4 5 Taylor Swift probable m 85 2023-01-01 recovered - 5 6 Korren Bailey confirmed f 41 2023-01-01 recovered - 6 8 Madison Zahn confirmed f 89 2023-01-01 2023-01-02 recovered - 7 11 Dustin Bellow confirmed m 69 2023-01-01 recovered - 8 12 Ryanna Hart confirmed f 23 2023-01-01 recovered - 9 13 Rafael Garcia confirmed m 9 2023-01-01 recovered - 10 18 Ashlan Hendon confirmed f 62 2023-01-02 recovered - 11 20 Tieran Moorer suspected m 52 2023-01-02 2023-01-15 recovered - 12 22 Paige Reich probable f 76 2023-01-02 recovered + id case_name case_type sex age date_onset date_admission outcome + 1 1 Kyle Crane suspected m 44 2023-01-01 recovered + 2 2 Ghaamid el-Ishmael confirmed m 13 2023-01-01 recovered + 3 3 Faatih el-Kaiser confirmed m 22 2023-01-01 2023-01-09 recovered + 4 5 Va'Aahi Galligan suspected m 85 2023-01-01 recovered + 5 6 Katelyn Catlin confirmed f 41 2023-01-01 recovered + 6 8 Lynsey Duron confirmed f 89 2023-01-01 2023-01-02 died + 7 11 Wajdi al-Demian confirmed m 69 2023-01-01 recovered + 8 12 Jacy Cousins confirmed f 23 2023-01-01 recovered + 9 13 Travis Foster confirmed m 9 2023-01-01 recovered + 10 18 Maria Eberhart probable f 62 2023-01-02 recovered + 11 20 Mubarak el-Vaziri suspected m 52 2023-01-02 2023-01-15 recovered + 12 22 Erin Payson confirmed f 76 2023-01-02 recovered date_outcome date_first_contact date_last_contact ct_value 1 NA - 2 2022-12-30 2023-01-05 NA - 3 2023-01-12 2022-12-30 2023-01-02 NA + 2 2022-12-30 2023-01-05 25.1 + 3 2022-12-30 2023-01-02 25.1 4 2022-12-29 2023-01-02 NA - 5 2023-01-01 2023-01-03 24 - 6 2023-01-03 2023-01-04 24 - 7 2023-01-04 2023-01-05 24 - 8 2023-01-01 2023-01-04 24 - 9 2022-12-31 2023-01-03 24 - 10 2022-12-30 2023-01-03 24 + 5 2023-01-01 2023-01-03 25.1 + 6 2023-01-26 2023-01-03 2023-01-04 25.1 + 7 2023-01-04 2023-01-05 25.1 + 8 2023-01-01 2023-01-04 25.1 + 9 2022-12-31 2023-01-03 25.1 + 10 2022-12-30 2023-01-03 NA 11 2023-01-01 2023-01-04 NA - 12 2023-01-01 2023-01-03 NA + 12 2023-01-01 2023-01-03 25.1 $contacts - from to age sex date_first_contact - 1 Gene Than Caleb Fredericks 13 m 2022-12-30 - 2 Gene Than Jaisean Venable 22 m 2022-12-30 - 3 Caleb Fredericks Mawhiba al-Mussa 5 f 2022-12-27 - 4 Caleb Fredericks Taylor Swift 85 m 2022-12-29 - 5 Jaisean Venable Korren Bailey 41 f 2023-01-01 - 6 Jaisean Venable Mustaba al-Sarwar 2 m 2022-12-30 - 7 Jaisean Venable Madison Zahn 89 f 2023-01-03 - 8 Taylor Swift Nicole Perez 86 f 2023-01-06 - 9 Korren Bailey Turfa el-Saab 82 f 2023-01-01 - 10 Madison Zahn Dustin Bellow 69 m 2023-01-04 - 11 Madison Zahn Ryanna Hart 23 f 2023-01-01 - 12 Madison Zahn Rafael Garcia 9 m 2022-12-31 - 13 Dustin Bellow Adrien Leduke 79 m 2022-12-28 - 14 Dustin Bellow Shan Klutke 29 f 2023-01-01 - 15 Dustin Bellow Dennison Kills In Sight 4 m 2023-01-02 - 16 Ryanna Hart Violet Watts 13 f 2023-01-02 - 17 Rafael Garcia Ashlan Hendon 62 f 2022-12-30 - 18 Rafael Garcia Lien Saldanha 24 f 2023-01-06 - 19 Rafael Garcia Tieran Moorer 52 m 2023-01-01 - 20 Rafael Garcia Michael Chavez 74 m 2023-01-01 - 21 Ashlan Hendon Paige Reich 76 f 2023-01-01 + from to age sex date_first_contact + 1 Kyle Crane Ghaamid el-Ishmael 13 m 2022-12-30 + 2 Kyle Crane Faatih el-Kaiser 22 m 2022-12-30 + 3 Ghaamid el-Ishmael Carisa Flores-Gonzalez 5 f 2022-12-27 + 4 Ghaamid el-Ishmael Va'Aahi Galligan 85 m 2022-12-29 + 5 Faatih el-Kaiser Katelyn Catlin 41 f 2023-01-01 + 6 Faatih el-Kaiser Aiman el-Riaz 2 m 2022-12-30 + 7 Faatih el-Kaiser Lynsey Duron 89 f 2023-01-03 + 8 Va'Aahi Galligan Amaani al-Gaber 86 f 2023-01-06 + 9 Katelyn Catlin Lilibeth Black 82 f 2023-01-01 + 10 Lynsey Duron Wajdi al-Demian 69 m 2023-01-04 + 11 Lynsey Duron Jacy Cousins 23 f 2023-01-01 + 12 Lynsey Duron Travis Foster 9 m 2022-12-31 + 13 Wajdi al-Demian Raymond Murray 79 m 2022-12-28 + 14 Wajdi al-Demian Marquaja Johnson 29 f 2023-01-01 + 15 Wajdi al-Demian Raaid el-Diab 4 m 2023-01-02 + 16 Jacy Cousins Kayla Tudor 13 f 2023-01-02 + 17 Travis Foster Maria Eberhart 62 f 2022-12-30 + 18 Travis Foster Katja Muetz 24 f 2023-01-06 + 19 Travis Foster Mubarak el-Vaziri 52 m 2023-01-01 + 20 Travis Foster Alexandre Guerrero 74 m 2023-01-01 + 21 Maria Eberhart Erin Payson 76 f 2023-01-01 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case @@ -310,17 +310,17 @@ 5 2023-01-03 Y case 6 2023-01-02 N under_followup 7 2023-01-04 Y case - 8 2023-01-06 N unknown - 9 2023-01-05 N lost_to_followup + 8 2023-01-06 N under_followup + 9 2023-01-05 N unknown 10 2023-01-05 Y case 11 2023-01-04 Y case 12 2023-01-03 Y case 13 2023-01-05 N under_followup - 14 2023-01-04 N under_followup - 15 2023-01-05 N under_followup - 16 2023-01-03 N lost_to_followup + 14 2023-01-04 N lost_to_followup + 15 2023-01-05 N lost_to_followup + 16 2023-01-03 N under_followup 17 2023-01-03 Y case - 18 2023-01-09 N under_followup + 18 2023-01-09 N lost_to_followup 19 2023-01-04 Y case 20 2023-01-03 N under_followup 21 2023-01-03 Y case diff --git a/tests/testthat/test-sim_linelist.R b/tests/testthat/test-sim_linelist.R index df58ec38..717d94ed 100644 --- a/tests/testthat/test-sim_linelist.R +++ b/tests/testthat/test-sim_linelist.R @@ -363,6 +363,7 @@ test_that("sim_linelist fails when onset-to-event are given by risk is NA", { }) test_that("sim_linest date_admission column is NA when onset_to_hosp is NA", { + set.seed(1) ll <- suppressWarnings( sim_linelist( contact_distribution = contact_distribution, @@ -388,6 +389,7 @@ test_that("sim_linest date_admission column is NA when onset_to_hosp is NA", { }) test_that("sim_linest date_death column is NA when onset_to_death is NA", { + set.seed(1) ll <- suppressWarnings( sim_linelist( contact_distribution = contact_distribution, From 87aabbeba93954f8db9b3a519941d94e917f95f1 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 25 Apr 2024 14:33:49 +0000 Subject: [PATCH 37/37] Update CITATION.cff --- CITATION.cff | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 8c91cec8..6d4c926a 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,7 +1,7 @@ -# ----------------------------------------------------------- -# CITATION file created with {cffr} R package, v1.0.0 +# -------------------------------------------- +# CITATION file created with {cffr} R package # See also: https://docs.ropensci.org/cffr/ -# ----------------------------------------------------------- +# -------------------------------------------- cff-version: 1.2.0 message: 'To cite package "simulist" in publications use:' @@ -347,3 +347,4 @@ references: identifiers: - type: url value: https://epiverse-trace.github.io/simulist/ +