diff --git a/CITATION.cff b/CITATION.cff index bda8d13b..8c91cec8 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -163,6 +163,22 @@ references: email: davis@posit.co orcid: https://orcid.org/0000-0003-4777-038X year: '2024' +- type: software + title: tidyr + abstract: 'tidyr: Tidy Messy Data' + notes: Suggests + url: https://tidyr.tidyverse.org + repository: https://CRAN.R-project.org/package=tidyr + authors: + - family-names: Wickham + given-names: Hadley + email: hadley@posit.co + - family-names: Vaughan + given-names: Davis + email: davis@posit.co + - family-names: Girlich + given-names: Maximilian + year: '2024' - type: software title: epicontacts abstract: 'epicontacts: Handling, Visualisation and Analysis of Epidemiological diff --git a/DESCRIPTION b/DESCRIPTION index 7ea2ab98..563e8987 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,6 +32,7 @@ Imports: Suggests: bookdown, dplyr, + tidyr, epicontacts (>= 1.1.3), ggplot2, incidence2 (>= 2.1.0), diff --git a/R/add_cols.R b/R/add_cols.R index a5299b29..9d77b98b 100644 --- a/R/add_cols.R +++ b/R/add_cols.R @@ -118,60 +118,61 @@ NULL } #' @name .add_date -.add_deaths <- function(.data, - onset_to_death, - hosp_death_risk, - non_hosp_death_risk) { +.add_outcome <- function(.data, + onset_to_death, + onset_to_recovery, + hosp_death_risk, + non_hosp_death_risk) { infected_idx <- .data$infected == "infected" num_infected <- sum(infected_idx) - .data$deaths <- NA_real_ - .data$deaths[infected_idx] <- .data$time[infected_idx] + - onset_to_death(num_infected) + .data$outcome <- "contact" + .data$outcome_time <- NA_real_ + .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) - apply_death_risk <- function(.data, risk, hosp = TRUE) { + apply_death_risk <- function(.data, risk, idx) { if (!is_na(risk)) { if (is.numeric(risk)) { # size is converted to an integer internally in sample() pop_sample <- sample( - which(infected_idx), + which(idx), replace = FALSE, - size = (1 - risk) * num_infected + size = risk * sum(idx) ) - .data$deaths[pop_sample] <- NA_real_ + .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] - if (hosp) { - age_group <- which( - .data$age %in% age_bracket & !is.na(.data$hospitalisation) - ) - } else { - age_group <- which( - .data$age %in% age_bracket & is.na(.data$hospitalisation) - ) - } - not_hosp_death_prob <- 1 - risk$risk[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 = not_hosp_death_prob * length(age_group) + size = risk$risk[i] * length(age_group) ) - .data$deaths[age_group_sample] <- NA_real_ + .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 } - .data <- apply_death_risk(.data, risk = hosp_death_risk, hosp = TRUE) - .data <- apply_death_risk(.data, risk = non_hosp_death_risk, hosp = FALSE) + .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 + ) # return data .data } - #' Add line list information as column to infectious history `` #' #' @param .data A `` containing the infectious history from a diff --git a/R/checkers.R b/R/checkers.R index 2dfea006..0fdefa6f 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -121,6 +121,7 @@ outbreak_size, onset_to_hosp = NULL, onset_to_death = NULL, + onset_to_recovery = NULL, add_names = NULL, add_ct = NULL, case_type_probs = NULL, @@ -146,6 +147,7 @@ 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) 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) @@ -250,59 +252,77 @@ onset_to_hosp_eval <- onset_to_hosp(1) onset_to_death_eval <- onset_to_death(1) + msg <- character(0) # risks can only be NA when the onset to event is also NA if (!is_na(onset_to_hosp_eval) && is_na(hosp_risk)) { - stop( + msg <- c(msg, paste( "hosp_risk is set to NA but onset_to_hosp is specified \n", - "set hosp_risk to numeric value", - call. = FALSE - ) + "set hosp_risk to numeric value" + )) } if (!is_na(onset_to_death_eval)) { if (is_na(hosp_death_risk)) { - stop( + msg <- c(msg, paste( "hosp_death_risk is set to NA but onset_to_death is specified \n", - "set hosp_death_risk to numeric value", - call. = FALSE - ) + "set hosp_death_risk to numeric value" + )) } if (is_na(non_hosp_death_risk)) { - stop( + msg <- c(msg, paste( "non_hosp_death_risk is set to NA but onset_to_death is specified \n", - "set non_hosp_death_risk to numeric value", - call. = FALSE - ) + "set non_hosp_death_risk to numeric value" + )) } } + if (length(msg) > 0) { + stop( + "Some onset-to-event and their corresponding risk are incompatible:\n", + sprintf(" - %s\n", msg), + call. = FALSE + ) + } if (is_na(onset_to_hosp_eval) && checkmate::test_number(hosp_risk) || is_na(onset_to_hosp_eval) && is.data.frame(hosp_risk)) { - warning( + msg <- c(msg, paste( "onset_to_hosp is set to NA but hosp_risk is specified \n", - "hosp_risk is being ignored, set hosp_risk to NA when ", - "onset_to_hosp is NA", - call. = FALSE - ) + "hosp_risk is being ignored, set hosp_risk to NA when", + "onset_to_hosp is NA" + )) + } + if (is_na(onset_to_hosp_eval) && checkmate::test_number(hosp_death_risk) || + is_na(onset_to_hosp_eval) && is.data.frame(hosp_death_risk)) { + msg <- c(msg, paste( + "onset_to_hosp is set to NA but hosp_death_risk is specified \n", + "hosp_death_risk is being ignored, set hosp_death_risk to NA when", + "onset_to_hosp is NA" + )) } if (is_na(onset_to_death_eval) && checkmate::test_number(hosp_death_risk) || is_na(onset_to_death_eval) && is.data.frame(hosp_death_risk)) { - warning( + msg <- c(msg, paste( "onset_to_death is set to NA but hosp_death_risk is specified \n", - "hosp_death_risk is being ignored, set hosp_death_risk to NA when ", - "onset_to_death is NA", - call. = FALSE - ) + "hosp_death_risk is being ignored, set hosp_death_risk to NA when", + "onset_to_death is NA" + )) } if (is_na(onset_to_death_eval) && checkmate::test_number(non_hosp_death_risk) || is_na(onset_to_death_eval) && is.data.frame(non_hosp_death_risk)) { - warning( + msg <- c(msg, paste( "onset_to_death is set to NA but non_hosp_death_risk is specified \n", - "non_hosp_death_risk is being ignored, set non_hosp_death_risk to NA ", - "when onset_to_death is NA", + "non_hosp_death_risk is being ignored, set non_hosp_death_risk to NA", + "when onset_to_death is NA" + )) + } + if (length(msg) > 0) { + warning( + "Some onset-to-event and their corresponding risk are incompatible:\n", + sprintf(" - %s\n", msg), call. = FALSE ) } + invisible(onset_to_hosp) } diff --git a/R/sim_internal.R b/R/sim_internal.R index af8cc44b..9f97bf53 100644 --- a/R/sim_internal.R +++ b/R/sim_internal.R @@ -17,6 +17,7 @@ prob_infect, onset_to_hosp = NULL, onset_to_death = NULL, + onset_to_recovery = NULL, hosp_risk = NULL, hosp_death_risk = NULL, non_hosp_death_risk = NULL, @@ -109,20 +110,21 @@ onset_to_hosp = onset_to_hosp, hosp_risk = hosp_risk ) - .data <- .add_deaths( + .data <- .add_outcome( .data = .data, 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 ) # add hospitalisation and death dates .data$date_admission <- .data$hospitalisation + outbreak_start_date - .data$date_death <- .data$deaths + outbreak_start_date + .data$date_outcome <- .data$outcome_time + outbreak_start_date linelist_cols <- c( "id", "case_type", "sex", "age", "date_onset", "date_admission", - "date_death", "date_first_contact", "date_last_contact" + "outcome", "date_outcome", "date_first_contact", "date_last_contact" ) if (add_names) { diff --git a/R/sim_linelist.R b/R/sim_linelist.R index f0a67d63..7495c546 100644 --- a/R/sim_linelist.R +++ b/R/sim_linelist.R @@ -33,10 +33,16 @@ #' infectious period. #' @param prob_infect A single `numeric` for the probability of a secondary #' contact being infected by an infected primary contact. -#' @param onset_to_hosp An `` object or anonymous function for -#' the onset to hospitalisation delay distribution. -#' @param onset_to_death An `` object or anonymous function for -#' the onset to death delay distribution. +#' @param onset_to_hosp An `` object, an anonymous function for +#' the onset to hospitalisation delay distribution, or `NA` to not simulate +#' hospitalisation (admission) dates. +#' @param onset_to_death An `` object, an anonymous function for +#' the onset to death delay distribution, or `NA` to not simulate dates for +#' individuals that died. +#' @param onset_to_recovery An `` object, an anonymous function for +#' the onset to death delay distribution, or `NA` to not simulate dates for +#' individuals that recovered. Default is `NA` so by default cases that +#' recover get an `NA` in the `$date_outcome` line list column. #' @param hosp_risk Either a single `numeric` for the hospitalisation risk of #' everyone in the population, or a `` with age specific #' hospitalisation risks Default is 20% hospitalisation (`0.2`) for the entire @@ -151,6 +157,7 @@ sim_linelist <- function(contact_distribution, prob_infect, onset_to_hosp, onset_to_death, + onset_to_recovery = NA, hosp_risk = 0.2, hosp_death_risk = 0.5, non_hosp_death_risk = 0.05, @@ -171,13 +178,15 @@ sim_linelist <- function(contact_distribution, contact_distribution = contact_distribution, infect_period = infect_period, onset_to_hosp = onset_to_hosp, - onset_to_death = onset_to_death + onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery ) ) contact_distribution <- funcs$contact_distribution infect_period <- funcs$infect_period onset_to_hosp <- funcs$onset_to_hosp onset_to_death <- funcs$onset_to_death + onset_to_recovery <- funcs$onset_to_recovery .check_sim_input( sim_type = "linelist", @@ -188,6 +197,7 @@ sim_linelist <- function(contact_distribution, outbreak_size = outbreak_size, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, add_names = add_names, add_ct = add_ct, case_type_probs = case_type_probs, @@ -241,6 +251,7 @@ sim_linelist <- function(contact_distribution, prob_infect = prob_infect, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, hosp_risk = hosp_risk, hosp_death_risk = hosp_death_risk, non_hosp_death_risk = non_hosp_death_risk, diff --git a/R/sim_outbreak.R b/R/sim_outbreak.R index 6da600d6..3f4d169e 100644 --- a/R/sim_outbreak.R +++ b/R/sim_outbreak.R @@ -58,6 +58,7 @@ sim_outbreak <- function(contact_distribution, prob_infect, onset_to_hosp, onset_to_death, + onset_to_recovery = NA, hosp_risk = 0.2, hosp_death_risk = 0.5, non_hosp_death_risk = 0.05, @@ -83,13 +84,15 @@ sim_outbreak <- function(contact_distribution, contact_distribution = contact_distribution, infect_period = infect_period, onset_to_hosp = onset_to_hosp, - onset_to_death = onset_to_death + onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery ) ) contact_distribution <- funcs$contact_distribution infect_period <- funcs$infect_period onset_to_hosp <- funcs$onset_to_hosp onset_to_death <- funcs$onset_to_death + onset_to_recovery <- funcs$onset_to_recovery .check_sim_input( sim_type = "outbreak", @@ -100,6 +103,7 @@ sim_outbreak <- function(contact_distribution, outbreak_size = outbreak_size, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, add_names = add_names, add_ct = add_ct, case_type_probs = case_type_probs, @@ -154,6 +158,7 @@ sim_outbreak <- function(contact_distribution, prob_infect = prob_infect, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, hosp_risk = hosp_risk, hosp_death_risk = hosp_death_risk, non_hosp_death_risk = non_hosp_death_risk, diff --git a/R/utils.R b/R/utils.R index bccd936d..2e64d9ff 100644 --- a/R/utils.R +++ b/R/utils.R @@ -103,7 +103,7 @@ is_na <- function(x) { #' #' @param x A named list containing either ``, `function` or `NA`. #' Named list elements are: `"contact_distribution"`, `"infect_period"`, -#' `"onset_to_hosp"`, `"onset_to_death"`. +#' `"onset_to_hosp"`, `"onset_to_death"`, `"onset_to_recovery".` #' #' @return A list of `function`s. #' @keywords internal @@ -112,7 +112,8 @@ as_function <- function(x) { "Input delay distributions need to be either functions or " = inherits(x$contact_distribution, c("function", "epidist")) && inherits(x$infect_period, c("function", "epidist")), - "onset_to_hosp and onset_to_death need to be a function, or NA" = + "onset_to_hosp, onset_to_death and onset_to_recovery need to be a function, + or NA" = inherits(x$onset_to_hosp, c("function", "epidist")) || is_na(x$onset_to_hosp) && inherits(x$onset_to_death, c("function", "epidist")) || @@ -134,12 +135,21 @@ as_function <- function(x) { } else { onset_to_death <- as.function(x$onset_to_death, func_type = "generate") } + if (is_na(x$onset_to_recovery)) { + # function to generate NA instead of recovery times + onset_to_recovery <- function(x) rep(NA, times = x) + } else { + onset_to_recovery <- as.function( + x$onset_to_recovery, func_type = "generate" + ) + } # return list of functions list( contact_distribution = contact_distribution, infect_period = infect_period, onset_to_hosp = onset_to_hosp, - onset_to_death = onset_to_death + onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery ) } diff --git a/man/as_function.Rd b/man/as_function.Rd index 2986d0c6..e6178d0d 100644 --- a/man/as_function.Rd +++ b/man/as_function.Rd @@ -9,7 +9,7 @@ as_function(x) \arguments{ \item{x}{A named list containing either \verb{}, \code{function} or \code{NA}. Named list elements are: \code{"contact_distribution"}, \code{"infect_period"}, -\code{"onset_to_hosp"}, \code{"onset_to_death"}.} +\code{"onset_to_hosp"}, \code{"onset_to_death"}, \verb{"onset_to_recovery".}} } \value{ A list of \code{function}s. diff --git a/man/dot-add_date.Rd b/man/dot-add_date.Rd index 6a5a1506..64e77276 100644 --- a/man/dot-add_date.Rd +++ b/man/dot-add_date.Rd @@ -4,7 +4,7 @@ \alias{.add_date} \alias{.add_date_contact} \alias{.add_hospitalisation} -\alias{.add_deaths} +\alias{.add_outcome} \title{Add event date as column to infectious history \verb{}} \usage{ .add_date_contact( @@ -17,7 +17,13 @@ .add_hospitalisation(.data, onset_to_hosp, hosp_risk) -.add_deaths(.data, onset_to_death, hosp_death_risk, non_hosp_death_risk) +.add_outcome( + .data, + onset_to_death, + onset_to_recovery, + hosp_death_risk, + non_hosp_death_risk +) } \arguments{ \item{.data}{A \verb{} containing the infectious history from a @@ -35,8 +41,9 @@ given in the \code{distribution} argument.} \item{outbreak_start_date}{A \code{date} for the start of the outbreak.} -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} \item{hosp_risk}{Either a single \code{numeric} for the hospitalisation risk of everyone in the population, or a \verb{} with age specific @@ -44,8 +51,14 @@ hospitalisation risks Default is 20\% hospitalisation (\code{0.2}) for the entir population. If the \code{onset_to_hosp} argument is set to \code{NA} this argument should also be set to \code{NA}. See details and examples for more information.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} + +\item{onset_to_recovery}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that recovered. Default is \code{NA} so by default cases that +recover get an \code{NA} in the \verb{$date_outcome} line list column.} \item{hosp_death_risk}{Either a single \code{numeric} for the death risk for hospitalised individuals across the population, or a \verb{} with age diff --git a/man/dot-check_sim_input.Rd b/man/dot-check_sim_input.Rd index 9171f037..3f4904de 100644 --- a/man/dot-check_sim_input.Rd +++ b/man/dot-check_sim_input.Rd @@ -13,6 +13,7 @@ outbreak_size, onset_to_hosp = NULL, onset_to_death = NULL, + onset_to_recovery = NULL, add_names = NULL, add_ct = NULL, case_type_probs = NULL, @@ -56,11 +57,18 @@ many iterations (internally) then the function errors, whereas if the maximum outbreak size is exceeded the function returns the data early and a warning stating how many cases and contacts are returned.} -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} + +\item{onset_to_recovery}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that recovered. Default is \code{NA} so by default cases that +recover get an \code{NA} in the \verb{$date_outcome} line list column.} \item{add_names}{A \code{logical} boolean for whether to add names to each row of the line list. Default is \code{TRUE}.} diff --git a/man/dot-cross_check_sim_input.Rd b/man/dot-cross_check_sim_input.Rd index ecdf66f0..1f354975 100644 --- a/man/dot-cross_check_sim_input.Rd +++ b/man/dot-cross_check_sim_input.Rd @@ -14,11 +14,13 @@ compatible with hospitalisation and death risks} ) } \arguments{ -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} \item{hosp_risk}{Either a single \code{numeric} for the hospitalisation risk of everyone in the population, or a \verb{} with age specific diff --git a/man/dot-sim_internal.Rd b/man/dot-sim_internal.Rd index a8bba1d2..04668f25 100644 --- a/man/dot-sim_internal.Rd +++ b/man/dot-sim_internal.Rd @@ -12,6 +12,7 @@ within \pkg{simulist}} prob_infect, onset_to_hosp = NULL, onset_to_death = NULL, + onset_to_recovery = NULL, hosp_risk = NULL, hosp_death_risk = NULL, non_hosp_death_risk = NULL, @@ -45,11 +46,18 @@ infectious period.} \item{prob_infect}{A single \code{numeric} for the probability of a secondary contact being infected by an infected primary contact.} -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} + +\item{onset_to_recovery}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that recovered. Default is \code{NA} so by default cases that +recover get an \code{NA} in the \verb{$date_outcome} line list column.} \item{hosp_risk}{Either a single \code{numeric} for the hospitalisation risk of everyone in the population, or a \verb{} with age specific diff --git a/man/sim_linelist.Rd b/man/sim_linelist.Rd index 318aa2a6..03a371d4 100644 --- a/man/sim_linelist.Rd +++ b/man/sim_linelist.Rd @@ -10,6 +10,7 @@ sim_linelist( prob_infect, onset_to_hosp, onset_to_death, + onset_to_recovery = NA, hosp_risk = 0.2, hosp_death_risk = 0.5, non_hosp_death_risk = 0.05, @@ -39,11 +40,18 @@ infectious period.} \item{prob_infect}{A single \code{numeric} for the probability of a secondary contact being infected by an infected primary contact.} -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} + +\item{onset_to_recovery}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that recovered. Default is \code{NA} so by default cases that +recover get an \code{NA} in the \verb{$date_outcome} line list column.} \item{hosp_risk}{Either a single \code{numeric} for the hospitalisation risk of everyone in the population, or a \verb{} with age specific diff --git a/man/sim_outbreak.Rd b/man/sim_outbreak.Rd index 34bf1ead..ed2e5bca 100644 --- a/man/sim_outbreak.Rd +++ b/man/sim_outbreak.Rd @@ -10,6 +10,7 @@ sim_outbreak( prob_infect, onset_to_hosp, onset_to_death, + onset_to_recovery = NA, hosp_risk = 0.2, hosp_death_risk = 0.5, non_hosp_death_risk = 0.05, @@ -41,11 +42,18 @@ infectious period.} \item{prob_infect}{A single \code{numeric} for the probability of a secondary contact being infected by an infected primary contact.} -\item{onset_to_hosp}{An \verb{} object or anonymous function for -the onset to hospitalisation delay distribution.} +\item{onset_to_hosp}{An \verb{} object, an anonymous function for +the onset to hospitalisation delay distribution, or \code{NA} to not simulate +hospitalisation (admission) dates.} -\item{onset_to_death}{An \verb{} object or anonymous function for -the onset to death delay distribution.} +\item{onset_to_death}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that died.} + +\item{onset_to_recovery}{An \verb{} object, an anonymous function for +the onset to death delay distribution, or \code{NA} to not simulate dates for +individuals that recovered. Default is \code{NA} so by default cases that +recover get an \code{NA} in the \verb{$date_outcome} line list column.} \item{hosp_risk}{Either a single \code{numeric} for the hospitalisation risk of everyone in the population, or a \verb{} with age specific diff --git a/tests/testthat/_snaps/sim_linelist.md b/tests/testthat/_snaps/sim_linelist.md index 93c5f1d2..7b4b5ae4 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 date_death - 1 1 Isaiah Patterson probable m 35 2023-01-01 - 2 2 Michael John suspected m 43 2023-01-01 - 3 3 Lorenzo Gaynor confirmed m 1 2023-01-01 - 4 5 Cass Milburn confirmed m 78 2023-01-01 - 5 6 Hope Cobb probable f 22 2023-01-01 - 6 8 Wyona Lenahan probable f 28 2023-01-01 - 7 11 Bishr al-Jamil confirmed m 46 2023-01-01 2023-01-13 - 8 12 Viviana Martinez probable f 67 2023-01-01 - 9 13 Mudrik al-Youssef probable m 86 2023-01-01 2023-01-01 - 10 18 Kylie Rieger confirmed f 60 2023-01-02 - 11 20 Vincent Edwards probable m 49 2023-01-02 - 12 22 Michiyo Hong suspected f 7 2023-01-02 2023-01-02 - 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 25.6 - 4 2022-12-29 2023-01-02 25.6 - 5 2023-01-01 2023-01-03 NA - 6 2023-01-03 2023-01-04 NA - 7 2023-01-04 2023-01-05 25.6 - 8 2023-01-01 2023-01-04 NA - 9 2022-12-31 2023-01-03 NA - 10 2022-12-30 2023-01-03 25.6 - 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 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 # 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 date_death - 1 1 Donald Childs probable m 35 2023-01-01 - 2 2 Michael Duran suspected m 43 2023-01-01 - 3 3 Cass Root probable m 1 2023-01-01 2023-01-11 2023-01-19 - 4 5 Mudrik al-Hallal confirmed m 78 2023-01-01 - 5 6 Erika Sierra confirmed f 22 2023-01-01 - 6 8 Jennifer Hong confirmed f 28 2023-01-01 - 7 11 Raashid el-Huda suspected m 46 2023-01-01 - 8 12 Kayla Johnson suspected f 67 2023-01-01 - 9 13 Dominic Montgomery probable m 86 2023-01-01 2023-01-01 2023-01-10 - 10 18 Giovana Segarra suspected f 60 2023-01-02 - 11 20 Vincent Edwards suspected m 49 2023-01-02 2023-01-09 2023-01-21 - 12 22 Kiona Dalke probable f 7 2023-01-02 - 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 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 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 + 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 # 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 date_death - 1 1 Isaiah Patterson probable m 35 2023-01-01 - 2 2 Michael John suspected m 43 2023-01-01 - 3 3 Lorenzo Gaynor confirmed m 1 2023-01-01 - 4 5 Cass Milburn confirmed m 78 2023-01-01 - 5 6 Hope Cobb probable f 22 2023-01-01 - 6 8 Wyona Lenahan probable f 28 2023-01-01 - 7 11 Bishr al-Jamil confirmed m 46 2023-01-01 2023-01-13 - 8 12 Viviana Martinez probable f 67 2023-01-01 - 9 13 Mudrik al-Youssef probable m 86 2023-01-01 2023-01-01 - 10 18 Kylie Rieger confirmed f 60 2023-01-02 - 11 20 Vincent Edwards probable m 49 2023-01-02 - 12 22 Michiyo Hong suspected f 7 2023-01-02 2023-01-02 - 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 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 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 # sim_linelist works as expected with anonymous @@ -107,32 +107,32 @@ prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, add_names = FALSE) Output - id case_type sex age date_onset date_admission date_death date_first_contact - 1 1 probable m 35 2023-01-01 - 2 2 confirmed m 43 2023-01-01 2022-12-30 - 3 3 confirmed m 1 2023-01-01 2022-12-30 - 4 5 confirmed m 78 2023-01-01 2022-12-29 - 5 6 confirmed f 22 2023-01-01 2023-01-01 - 6 8 suspected f 28 2023-01-01 2023-01-03 - 7 11 confirmed m 46 2023-01-01 2023-01-13 2023-01-04 - 8 12 suspected f 67 2023-01-01 2023-01-01 - 9 13 confirmed m 86 2023-01-01 2023-01-01 2022-12-31 - 10 18 confirmed f 60 2023-01-02 2022-12-30 - 11 20 confirmed m 49 2023-01-02 2023-01-01 - 12 22 confirmed f 7 2023-01-02 2023-01-02 2023-01-01 - date_last_contact ct_value - 1 NA - 2 2023-01-05 26 - 3 2023-01-02 26 - 4 2023-01-02 26 - 5 2023-01-03 26 - 6 2023-01-04 NA - 7 2023-01-05 26 - 8 2023-01-04 NA - 9 2023-01-03 26 - 10 2023-01-03 26 - 11 2023-01-04 26 - 12 2023-01-03 26 + 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 + 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 + 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 + 11 20 confirmed m 49 2023-01-02 recovered + 12 22 confirmed f 7 2023-01-02 2023-01-02 died 2023-01-16 + 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 # 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 date_death - 1 1 Ghaamid el-Ishmael suspected m 44 2023-01-01 - 2 2 Faatih el-Kaiser confirmed m 13 2023-01-01 - 3 3 Brandon Galligan confirmed m 22 2023-01-01 2023-01-09 - 4 5 Aiman el-Riaz suspected m 85 2023-01-01 - 5 6 Katelyn Catlin confirmed f 41 2023-01-01 - 6 8 Lynsey Duron confirmed f 89 2023-01-01 2023-01-02 - 7 11 Travis Foster confirmed m 69 2023-01-01 - 8 12 Jacy Cousins confirmed f 23 2023-01-01 - 9 13 Khoa Murray confirmed m 9 2023-01-01 - 10 18 Maria Eberhart probable f 62 2023-01-02 - 11 20 John Flores suspected m 52 2023-01-02 2023-01-15 - 12 22 Erin Payson confirmed f 76 2023-01-02 - date_first_contact date_last_contact ct_value - 1 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 25.1 - 6 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 25.1 + 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 @@ -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 Corey Marten probable m 44 2023-01-01 - 2 2 Sean Natarelli confirmed m 13 2023-01-01 - 3 3 Collin Stimack suspected m 22 2023-01-01 - 4 5 Nicholas Orgill confirmed m 85 2023-01-01 2023-01-01 - 5 6 Hope Arshad suspected f 41 2023-01-01 - 6 8 Shanta Holiday probable f 89 2023-01-01 - 7 11 Anthony Zapata Morales probable m 69 2023-01-01 - 8 12 Chandra Kilian suspected f 23 2023-01-01 - 9 13 Bradford Coffman confirmed m 9 2023-01-01 - 10 18 Kanani Nguyen confirmed f 62 2023-01-02 - 11 20 Codie North probable m 52 2023-01-02 - 12 22 Annie Carter probable f 76 2023-01-02 - date_death 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 + 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 + 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 + 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 date_death - 1 1 Lily Camacho confirmed f 20 2023-01-01 - 2 2 Justin Apodaca suspected m 24 2023-01-01 2023-01-10 - 3 3 Sad el-Irani suspected m 51 2023-01-01 2023-01-07 - 4 5 Tristan Benjamin probable m 16 2023-01-01 - 5 6 Treven Cornejo suspected m 83 2023-01-01 - 6 8 Kevin Contreras suspected m 48 2023-01-01 - 7 11 Luqmaan el-Ozer probable m 77 2023-01-01 2023-01-01 - 8 12 Royse Beltran confirmed m 90 2023-01-01 - 9 13 Halle Batchelder confirmed f 66 2023-01-01 - 10 18 Morgan Grant-Perry confirmed f 31 2023-01-02 2023-01-02 - 11 20 Matthew Chavez confirmed m 46 2023-01-02 - 12 22 Martin Gaspar confirmed m 75 2023-01-02 - date_first_contact date_last_contact ct_value - 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 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 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 + 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 # sim_linelist works as expected with modified config parameters @@ -244,30 +244,30 @@ 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 date_death - 1 1 Isaiah Patterson probable m 35 2023-01-01 - 2 2 Michael John suspected m 43 2023-01-01 - 3 3 Lorenzo Gaynor confirmed m 1 2023-01-01 - 4 5 Cass Milburn confirmed m 78 2023-01-01 - 5 6 Hope Cobb probable f 22 2023-01-01 - 6 8 Wyona Lenahan probable f 28 2023-01-01 - 7 11 Bishr al-Jamil confirmed m 46 2023-01-01 2023-01-13 - 8 12 Viviana Martinez probable f 67 2023-01-01 - 9 13 Mudrik al-Youssef probable m 86 2023-01-01 2023-01-01 - 10 18 Kylie Rieger confirmed f 60 2023-01-02 - 11 20 Vincent Edwards probable m 49 2023-01-02 - 12 22 Michiyo Hong suspected f 7 2023-01-02 2023-01-02 - date_first_contact date_last_contact ct_value - 1 NA - 2 2023-01-01 2023-01-07 NA - 3 2022-12-31 2023-01-03 25.6 - 4 2022-12-31 2023-01-04 25.6 - 5 2023-01-02 2023-01-04 NA - 6 2023-01-06 2023-01-07 NA - 7 2023-01-07 2023-01-08 25.6 - 8 2023-01-03 2023-01-06 NA - 9 2023-01-02 2023-01-05 NA - 10 2023-01-01 2023-01-05 25.6 - 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 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 diff --git a/tests/testthat/_snaps/sim_outbreak.md b/tests/testthat/_snaps/sim_outbreak.md index 3e9f72bc..73a8984f 100644 --- a/tests/testthat/_snaps/sim_outbreak.md +++ b/tests/testthat/_snaps/sim_outbreak.md @@ -5,56 +5,138 @@ 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 date_death - 1 1 Isaiah Patterson probable m 35 2023-01-01 - 2 2 Michael John suspected m 43 2023-01-01 - 3 3 Lorenzo Gaynor confirmed m 1 2023-01-01 - 4 5 Cass Milburn confirmed m 78 2023-01-01 - 5 6 Hope Cobb probable f 22 2023-01-01 - 6 8 Wyona Lenahan probable f 28 2023-01-01 - 7 11 Bishr al-Jamil confirmed m 46 2023-01-01 2023-01-13 - 8 12 Viviana Martinez probable f 67 2023-01-01 - 9 13 Mudrik al-Youssef probable m 86 2023-01-01 2023-01-01 - 10 18 Kylie Rieger confirmed f 60 2023-01-02 - 11 20 Vincent Edwards probable m 49 2023-01-02 - 12 22 Michiyo Hong suspected f 7 2023-01-02 2023-01-02 + 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 + + $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 + + +# sim_outbreak works as expected with add_names = FALSE + + Code + sim_outbreak(contact_distribution = contact_distribution, infect_period = infect_period, + prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + add_names = FALSE) + Output + $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 + 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 + 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 + 11 20 confirmed m 49 2023-01-02 recovered + 12 22 confirmed f 7 2023-01-02 2023-01-02 died 2023-01-16 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 25.6 - 4 2022-12-29 2023-01-02 25.6 + 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.6 - 8 2023-01-01 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 25.6 - 11 2023-01-01 2023-01-04 NA - 12 2023-01-01 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 $contacts - from to age sex date_first_contact - 1 Isaiah Patterson Michael John 43 m 2022-12-30 - 2 Isaiah Patterson Lorenzo Gaynor 1 m 2022-12-30 - 3 Michael John Alyssa Davis 29 f 2022-12-27 - 4 Michael John Cass Milburn 78 m 2022-12-29 - 5 Lorenzo Gaynor Hope Cobb 22 f 2023-01-01 - 6 Lorenzo Gaynor Donald Simmons 70 m 2022-12-30 - 7 Lorenzo Gaynor Wyona Lenahan 28 f 2023-01-03 - 8 Cass Milburn Jasra al-Dib 37 f 2023-01-06 - 9 Hope Cobb Courtney Senff 61 f 2023-01-01 - 10 Wyona Lenahan Bishr al-Jamil 46 m 2023-01-04 - 11 Wyona Lenahan Viviana Martinez 67 f 2023-01-01 - 12 Wyona Lenahan Mudrik al-Youssef 86 m 2022-12-31 - 13 Bishr al-Jamil Jareer al-Hallal 71 m 2022-12-28 - 14 Bishr al-Jamil Jennifer Nguyen 51 f 2023-01-01 - 15 Bishr al-Jamil Hector Abeyta 44 m 2023-01-02 - 16 Viviana Martinez Chandra Musil 49 f 2023-01-02 - 17 Mudrik al-Youssef Kylie Rieger 60 f 2022-12-30 - 18 Mudrik al-Youssef Alexandra Arshad 56 f 2023-01-06 - 19 Mudrik al-Youssef Vincent Edwards 49 m 2023-01-01 - 20 Mudrik al-Youssef Avery Johnston 50 m 2023-01-01 - 21 Kylie Rieger Michiyo Hong 7 f 2023-01-01 + 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 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case @@ -68,10 +150,10 @@ 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 unknown - 15 2023-01-05 N unknown - 16 2023-01-03 N under_followup + 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 17 2023-01-03 Y case 18 2023-01-09 N under_followup 19 2023-01-04 Y case @@ -79,64 +161,65 @@ 21 2023-01-03 Y case -# sim_outbreak works as expected with add_names = FALSE +# sim_outbreak works as expected with age-strat risks Code sim_outbreak(contact_distribution = contact_distribution, infect_period = infect_period, prob_infect = 0.5, onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, - add_names = FALSE) + 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 $linelist - id case_type sex age date_onset date_admission date_death date_first_contact - 1 1 probable m 35 2023-01-01 - 2 2 confirmed m 43 2023-01-01 2022-12-30 - 3 3 confirmed m 1 2023-01-01 2022-12-30 - 4 5 confirmed m 78 2023-01-01 2022-12-29 - 5 6 confirmed f 22 2023-01-01 2023-01-01 - 6 8 suspected f 28 2023-01-01 2023-01-03 - 7 11 confirmed m 46 2023-01-01 2023-01-13 2023-01-04 - 8 12 suspected f 67 2023-01-01 2023-01-01 - 9 13 confirmed m 86 2023-01-01 2023-01-01 2022-12-31 - 10 18 confirmed f 60 2023-01-02 2022-12-30 - 11 20 confirmed m 49 2023-01-02 2023-01-01 - 12 22 confirmed f 7 2023-01-02 2023-01-02 2023-01-01 - date_last_contact ct_value - 1 NA - 2 2023-01-05 26 - 3 2023-01-02 26 - 4 2023-01-02 26 - 5 2023-01-03 26 - 6 2023-01-04 NA - 7 2023-01-05 26 - 8 2023-01-04 NA - 9 2023-01-03 26 - 10 2023-01-03 26 - 11 2023-01-04 26 - 12 2023-01-03 26 + 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 $contacts - from to age sex date_first_contact - 1 Christopher Chaffin Kevin Cooper 43 m 2022-12-30 - 2 Christopher Chaffin Austin Loughridge 1 m 2022-12-30 - 3 Kevin Cooper Michiyo Smith 29 f 2022-12-27 - 4 Kevin Cooper Khaleel el-Huda 78 m 2022-12-29 - 5 Austin Loughridge Samantha Gonzalez 22 f 2023-01-01 - 6 Austin Loughridge Benjamin Mcdonald 70 m 2022-12-30 - 7 Austin Loughridge Tea Slaughter 28 f 2023-01-03 - 8 Khaleel el-Huda Audreon Hill 37 f 2023-01-06 - 9 Samantha Gonzalez Dieu Linh Batara 61 f 2023-01-01 - 10 Tea Slaughter Travis Montgomery 46 m 2023-01-04 - 11 Tea Slaughter Hishma el-Hamid 67 f 2023-01-01 - 12 Tea Slaughter Jose Gonzales 86 m 2022-12-31 - 13 Travis Montgomery Efren Abeyta 71 m 2022-12-28 - 14 Travis Montgomery Giovana Quintero 51 f 2023-01-01 - 15 Travis Montgomery Zayyaan el-Radwan 44 m 2023-01-02 - 16 Hishma el-Hamid Kiona Fitzsimmons 49 f 2023-01-02 - 17 Jose Gonzales Danita Anderson 60 f 2022-12-30 - 18 Jose Gonzales Arwa el-Moussa 56 f 2023-01-06 - 19 Jose Gonzales Enrique Salas Dominguez 49 m 2023-01-01 - 20 Jose Gonzales Charles Graf 50 m 2023-01-01 - 21 Danita Anderson Cheyenne Miller 7 f 2023-01-01 + 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 date_last_contact was_case status 1 2023-01-05 Y case 2 2023-01-02 Y case @@ -145,105 +228,22 @@ 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 + 8 2023-01-06 N lost_to_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 unknown - 14 2023-01-04 N lost_to_followup - 15 2023-01-05 N lost_to_followup - 16 2023-01-03 N unknown + 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 + 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 -# sim_outbreak works as expected with age-strat risks - - Code - sim_outbreak(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, hosp_death_risk = age_dep_hosp_death_risk, - non_hosp_death_risk = age_dep_non_hosp_death_risk) - Output - $linelist - id case_name case_type sex age date_onset date_admission date_death - 1 1 Donald Childs probable m 35 2023-01-01 - 2 2 Michael Duran suspected m 43 2023-01-01 - 3 3 Cass Root probable m 1 2023-01-01 2023-01-11 2023-01-19 - 4 5 Mudrik al-Hallal confirmed m 78 2023-01-01 - 5 6 Erika Sierra confirmed f 22 2023-01-01 - 6 8 Jennifer Hong confirmed f 28 2023-01-01 - 7 11 Raashid el-Huda suspected m 46 2023-01-01 - 8 12 Kayla Johnson suspected f 67 2023-01-01 - 9 13 Dominic Montgomery probable m 86 2023-01-01 2023-01-01 2023-01-10 - 10 18 Giovana Segarra suspected f 60 2023-01-02 - 11 20 Vincent Edwards suspected m 49 2023-01-02 2023-01-09 2023-01-21 - 12 22 Kiona Dalke probable f 7 2023-01-02 - 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 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 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 Donald Childs Michael Duran 43 m 2022-12-30 - 2 Donald Childs Cass Root 1 m 2022-12-30 - 3 Michael Duran Kaitlynne Rieger 29 f 2022-12-27 - 4 Michael Duran Mudrik al-Hallal 78 m 2022-12-29 - 5 Cass Root Erika Sierra 22 f 2023-01-01 - 6 Cass Root Jareer al-Safar 70 m 2022-12-30 - 7 Cass Root Jennifer Hong 28 f 2023-01-03 - 8 Mudrik al-Hallal Kaitlin Gonzalez 37 f 2023-01-06 - 9 Erika Sierra Marissa Slaughter 61 f 2023-01-01 - 10 Jennifer Hong Raashid el-Huda 46 m 2023-01-04 - 11 Jennifer Hong Kayla Johnson 67 f 2023-01-01 - 12 Jennifer Hong Dominic Montgomery 86 m 2022-12-31 - 13 Raashid el-Huda Lorenzo Gaynor 71 m 2022-12-28 - 14 Raashid el-Huda Michiyo Tran 51 f 2023-01-01 - 15 Raashid el-Huda Avery Johnston 44 m 2023-01-02 - 16 Kayla Johnson Marzooqa el-Abdelrahman 49 f 2023-01-02 - 17 Dominic Montgomery Giovana Segarra 60 f 2022-12-30 - 18 Dominic Montgomery Kaylie Shangreaux 56 f 2023-01-06 - 19 Dominic Montgomery Vincent Edwards 49 m 2023-01-01 - 20 Dominic Montgomery Ethan Black 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 Code @@ -252,56 +252,56 @@ population_age = age_struct) Output $linelist - id case_name case_type sex age date_onset date_admission date_death - 1 1 Ghaamid el-Ishmael suspected m 44 2023-01-01 - 2 2 Faatih el-Kaiser confirmed m 13 2023-01-01 - 3 3 Brandon Galligan confirmed m 22 2023-01-01 2023-01-09 - 4 5 Aiman el-Riaz suspected m 85 2023-01-01 - 5 6 Katelyn Catlin confirmed f 41 2023-01-01 - 6 8 Lynsey Duron confirmed f 89 2023-01-01 2023-01-02 - 7 11 Travis Foster confirmed m 69 2023-01-01 - 8 12 Jacy Cousins confirmed f 23 2023-01-01 - 9 13 Khoa Murray confirmed m 9 2023-01-01 - 10 18 Maria Eberhart probable f 62 2023-01-02 - 11 20 John Flores suspected m 52 2023-01-02 2023-01-15 - 12 22 Erin Payson confirmed f 76 2023-01-02 - date_first_contact date_last_contact ct_value - 1 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 25.1 - 6 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 25.1 + 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 $contacts - from to age sex date_first_contact - 1 Ghaamid el-Ishmael Faatih el-Kaiser 13 m 2022-12-30 - 2 Ghaamid el-Ishmael Brandon Galligan 22 m 2022-12-30 - 3 Faatih el-Kaiser Carisa Flores-Gonzalez 5 f 2022-12-27 - 4 Faatih el-Kaiser Aiman el-Riaz 85 m 2022-12-29 - 5 Brandon Galligan Katelyn Catlin 41 f 2023-01-01 - 6 Brandon Galligan Wajdi al-Demian 2 m 2022-12-30 - 7 Brandon Galligan Lynsey Duron 89 f 2023-01-03 - 8 Aiman el-Riaz Amaani al-Gaber 86 f 2023-01-06 - 9 Katelyn Catlin Lilibeth Black 82 f 2023-01-01 - 10 Lynsey Duron Travis Foster 69 m 2023-01-04 - 11 Lynsey Duron Jacy Cousins 23 f 2023-01-01 - 12 Lynsey Duron Khoa Murray 9 m 2022-12-31 - 13 Travis Foster Raaid el-Diab 79 m 2022-12-28 - 14 Travis Foster Marquaja Johnson 29 f 2023-01-01 - 15 Travis Foster Mubarak el-Vaziri 4 m 2023-01-02 - 16 Jacy Cousins Kayla Tudor 13 f 2023-01-02 - 17 Khoa Murray Maria Eberhart 62 f 2022-12-30 - 18 Khoa Murray Katja Muetz 24 f 2023-01-06 - 19 Khoa Murray John Flores 52 m 2023-01-01 - 20 Khoa Murray Bryce Sena 74 m 2023-01-01 - 21 Maria Eberhart Erin Payson 76 f 2023-01-01 + 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 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 under_followup - 9 2023-01-05 N unknown + 8 2023-01-06 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 lost_to_followup + 14 2023-01-04 N under_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 lost_to_followup 19 2023-01-04 Y case - 20 2023-01-03 N under_followup + 20 2023-01-03 N unknown 21 2023-01-03 Y case diff --git a/tests/testthat/test-add_cols.R b/tests/testthat/test-add_cols.R index ac82c659..c5d76efb 100644 --- a/tests/testthat/test-add_cols.R +++ b/tests/testthat/test-add_cols.R @@ -13,6 +13,8 @@ suppressMessages({ epi_dist = "onset to death", single_epidist = TRUE )) + + onset_to_recovery <- function(x) rep(NA, times = x) }) test_that(".add_date_contact works as expected with contact_type = 'last'", { @@ -173,42 +175,46 @@ test_that(".add_hospitalisation works as expected with age-strat risks", { ) }) -test_that(".add_deaths works as expected", { - ll <- readRDS(file.path("testdata", "pre_death.rds")) - linelist <- .add_deaths( +test_that(".add_outcome works as expected", { + ll <- readRDS(file.path("testdata", "pre_outcome.rds")) + linelist <- .add_outcome( .data = ll, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, hosp_death_risk = 0.5, non_hosp_death_risk = 0.5 ) expect_s3_class(linelist, class = "data.frame") - expect_type(linelist$deaths, type = "double") - expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 1L)) + expect_type(linelist$outcome, type = "character") + expect_type(linelist$outcome_time, type = "double") + expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 2L)) expect_identical( colnames(linelist), - c(colnames(ll), "deaths") + c(colnames(ll), "outcome", "outcome_time") ) }) -test_that(".add_deaths works as expected with different parameter", { - ll <- readRDS(file.path("testdata", "pre_death.rds")) - linelist <- .add_deaths( +test_that(".add_outcome works as expected with different parameter", { + ll <- readRDS(file.path("testdata", "pre_outcome.rds")) + linelist <- .add_outcome( .data = ll, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, hosp_death_risk = 0.9, non_hosp_death_risk = 0.1 ) expect_s3_class(linelist, class = "data.frame") - expect_type(linelist$deaths, type = "double") - expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 1L)) + expect_type(linelist$outcome, type = "character") + expect_type(linelist$outcome_time, type = "double") + expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 2L)) expect_identical( colnames(linelist), - c(colnames(ll), "deaths") + c(colnames(ll), "outcome", "outcome_time") ) }) -test_that(".add_deaths works as expected with age-strat risks", { - ll <- readRDS(file.path("testdata", "pre_death.rds")) +test_that(".add_outcome works as expected with age-strat risks", { + ll <- readRDS(file.path("testdata", "pre_outcome.rds")) age_dep_hosp_death_risk <- data.frame( min_age = c(1, 5, 80), max_age = c(4, 79, 90), @@ -219,18 +225,20 @@ test_that(".add_deaths works as expected with age-strat risks", { max_age = c(4, 79, 90), risk = c(0.05, 0.025, 0.1) ) - linelist <- .add_deaths( + linelist <- .add_outcome( .data = ll, 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 ) expect_s3_class(linelist, class = "data.frame") - expect_type(linelist$deaths, type = "double") - expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 1L)) + expect_type(linelist$outcome, type = "character") + expect_type(linelist$outcome_time, type = "double") + expect_identical(dim(linelist), c(nrow(ll), ncol(ll) + 2L)) expect_identical( colnames(linelist), - c(colnames(ll), "deaths") + c(colnames(ll), "outcome", "outcome_time") ) }) diff --git a/tests/testthat/test-checkers.R b/tests/testthat/test-checkers.R index d09df031..cab951fb 100644 --- a/tests/testthat/test-checkers.R +++ b/tests/testthat/test-checkers.R @@ -165,6 +165,14 @@ suppressMessages({ epi_dist = "onset to death", single_epidist = TRUE )) + + onset_to_recovery <- as.function(epiparameter::epidist( + disease = "COVID-19", + epi_dist = "onset to recovery", + prob_distribution = "lnorm", + prob_distribution_params = c(meanlog = 3, sdlog = 1) + )) + }) test_that(".check_sim_input works as expected", { @@ -177,6 +185,7 @@ test_that(".check_sim_input works as expected", { outbreak_size = c(10, 1e4), onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, add_names = TRUE, add_ct = FALSE, case_type_probs = c( @@ -206,6 +215,7 @@ test_that(".check_sim_input works as expected", { outbreak_size = c(10, 1e4), onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, add_names = TRUE, add_ct = FALSE, case_type_probs = c( @@ -249,6 +259,7 @@ test_that(".check_sim_input works as expected with NA risks", { outbreak_size = c(10, 1e4), onset_to_hosp = onset_to_hosp, onset_to_death = onset_to_death, + onset_to_recovery = onset_to_recovery, add_names = TRUE, add_ct = FALSE, case_type_probs = c( @@ -361,22 +372,37 @@ test_that(".cross_check_sim_input warns as expected", { hosp_death_risk = 0.5, non_hosp_death_risk = 0.05 ), - regexp = "(onset_to_hosp is set to NA)*(hosp_risk is being ignored)" + regexp = paste0( + "(onset_to_hosp is set to NA)*(hosp_risk is being ignored)*", + "(hosp_death_risk is being ignored)" + ) ) - # since testthat v3 these handle a single condition so nesting expect warning - # to check both warnings + expect_warning( - expect_warning( - .cross_check_sim_input( - onset_to_hosp = onset_to_hosp, - onset_to_death = function(x) rep(NA, times = x), - hosp_risk = 0.2, - hosp_death_risk = 0.5, - non_hosp_death_risk = 0.05 - ), - regexp = "(onset_to_death is)*(NA)*(hosp_death_risk is being ignored)" + .cross_check_sim_input( + onset_to_hosp = function(x) rep(NA, times = x), + onset_to_death = onset_to_death, + hosp_risk = 0.2, + hosp_death_risk = 0.5, + non_hosp_death_risk = 0.05 + ), + regexp = paste0( + "(onset_to_hosp is set to NA)*(hosp_risk is being ignored)*", + "(hosp_death_risk is being ignored)" + ) + ) + expect_warning( + .cross_check_sim_input( + onset_to_hosp = onset_to_hosp, + onset_to_death = function(x) rep(NA, times = x), + hosp_risk = 0.2, + hosp_death_risk = 0.5, + non_hosp_death_risk = 0.05 ), - regexp = "(onset_to_death is)*(NA)*(non_hosp_death_risk is being ignored)" + regexp = paste0( + "(onset_to_death is set to NA)*(hosp_death_risk is being ignored)*", + "(non_hosp_death_risk is being ignored)" + ) ) expect_error( .cross_check_sim_input( @@ -386,7 +412,10 @@ test_that(".cross_check_sim_input warns as expected", { hosp_death_risk = 0.5, non_hosp_death_risk = 0.05 ), - regexp = "(hosp_risk is set to NA)*(but onset_to_hosp is specified)" + regexp = paste0( + "(hosp_risk is set to NA)*(but onset_to_hosp is specified)*", + "(set hosp_risk to numeric value)" + ) ) expect_error( .cross_check_sim_input( @@ -396,7 +425,10 @@ test_that(".cross_check_sim_input warns as expected", { hosp_death_risk = NA, non_hosp_death_risk = 0.05 ), - regexp = "(hosp_death_risk is set to NA but onset_to_death is specified)" + regexp = paste0( + "(hosp_death_risk is set to NA)*(but onset_to_death is specified)*", + "(set hosp_death_risk to numeric value)" + ) ) expect_error( .cross_check_sim_input( @@ -406,6 +438,9 @@ test_that(".cross_check_sim_input warns as expected", { hosp_death_risk = 0.5, non_hosp_death_risk = NA ), - regexp = "(non_hosp_death_risk is set to NA)*(onset_to_death is specified)" + regexp = paste0( + "(non_hosp_death_risk is set to NA)*(onset_to_death is specified)*", + "(set non_hosp_death_risk to numeric value)" + ) ) }) diff --git a/tests/testthat/test-sim_linelist.R b/tests/testthat/test-sim_linelist.R index e5199435..7da1396f 100644 --- a/tests/testthat/test-sim_linelist.R +++ b/tests/testthat/test-sim_linelist.R @@ -296,35 +296,33 @@ test_that("sim_linelist warns when risks are given by onset-to-event is NA", { ), regexp = "(onset_to_hosp is set to NA)*(hosp_risk is being ignored)" ) - # since testthat v3 these handle a single condition so nesting expect warning - # to check both warnings expect_warning( - expect_warning( - sim_linelist( - contact_distribution = contact_distribution, - infect_period = infect_period, - prob_infect = 0.5, - onset_to_hosp = onset_to_hosp, - onset_to_death = NA, - hosp_death_risk = 0.5 - ), - regexp = "(onset_to_death is)*(NA)*(hosp_death_risk is being ignored)" + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = NA, + hosp_death_risk = 0.5 ), - regexp = "(onset_to_death is)*(NA)*(non_hosp_death_risk is being ignored)" + regexp = paste0( + "(onset_to_death is set to NA)*(hosp_death_risk is being ignored)*", + "(non_hosp_death_risk is being ignored)" + ) ) expect_warning( - expect_warning( - sim_linelist( - contact_distribution = contact_distribution, - infect_period = infect_period, - prob_infect = 0.5, - onset_to_hosp = onset_to_hosp, - onset_to_death = NA, - non_hosp_death_risk = 0.02 - ), - regexp = "(onset_to_death is)*(NA)*(hosp_death_risk is being ignored)" + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = onset_to_hosp, + onset_to_death = NA, + non_hosp_death_risk = 0.02 ), - regexp = "(onset_to_death is)*(NA)*(non_hosp_death_risk is being ignored)" + regexp = paste0( + "(onset_to_death is set to NA)*(hosp_death_risk is being ignored)*", + "(non_hosp_death_risk is being ignored)" + ) ) }) @@ -376,13 +374,15 @@ test_that("sim_linest date_admission column is NA when onset_to_hosp is NA", { ) expect_true(all(is.na(ll$date_admission))) - ll <- sim_linelist( - contact_distribution = contact_distribution, - infect_period = infect_period, - prob_infect = 0.5, - onset_to_hosp = NA, - onset_to_death = onset_to_death, - hosp_risk = NA + ll <- suppressWarnings( + sim_linelist( + contact_distribution = contact_distribution, + infect_period = infect_period, + prob_infect = 0.5, + onset_to_hosp = NA, + onset_to_death = onset_to_death, + hosp_risk = NA + ) ) expect_true(all(is.na(ll$date_admission))) }) diff --git a/tests/testthat/testdata/README.md b/tests/testthat/testdata/README.md index a25b50ed..c245e72d 100644 --- a/tests/testthat/testdata/README.md +++ b/tests/testthat/testdata/README.md @@ -5,7 +5,7 @@ The {simulist} R package contains test data files in order to test internal func * "pre_date_last_contact" * "pre_date_first_contact" * "pre_hospitalisation" -* "pre_death" +* "pre_outcome" * "pre_names" * "pre_ct" diff --git a/tests/testthat/testdata/pre_ct.rds b/tests/testthat/testdata/pre_ct.rds index 21d67762..6c8a06b4 100644 Binary files a/tests/testthat/testdata/pre_ct.rds and b/tests/testthat/testdata/pre_ct.rds differ diff --git a/tests/testthat/testdata/pre_date_first_contact.rds b/tests/testthat/testdata/pre_date_first_contact.rds index c482f5aa..66fe7a58 100644 Binary files a/tests/testthat/testdata/pre_date_first_contact.rds and b/tests/testthat/testdata/pre_date_first_contact.rds differ diff --git a/tests/testthat/testdata/pre_date_last_contact.rds b/tests/testthat/testdata/pre_date_last_contact.rds index 42e50333..6bbadfee 100644 Binary files a/tests/testthat/testdata/pre_date_last_contact.rds and b/tests/testthat/testdata/pre_date_last_contact.rds differ diff --git a/tests/testthat/testdata/pre_death.rds b/tests/testthat/testdata/pre_death.rds deleted file mode 100644 index 07c92573..00000000 Binary files a/tests/testthat/testdata/pre_death.rds and /dev/null differ diff --git a/tests/testthat/testdata/pre_hospitalisation.rds b/tests/testthat/testdata/pre_hospitalisation.rds index 3521406f..1c5ef33c 100644 Binary files a/tests/testthat/testdata/pre_hospitalisation.rds and b/tests/testthat/testdata/pre_hospitalisation.rds differ diff --git a/tests/testthat/testdata/pre_names.rds b/tests/testthat/testdata/pre_names.rds index 23c11553..e21da405 100644 Binary files a/tests/testthat/testdata/pre_names.rds and b/tests/testthat/testdata/pre_names.rds differ diff --git a/tests/testthat/testdata/pre_outcome.rds b/tests/testthat/testdata/pre_outcome.rds new file mode 100644 index 00000000..c8abe8ab Binary files /dev/null and b/tests/testthat/testdata/pre_outcome.rds differ diff --git a/vignettes/vis-linelist.Rmd b/vignettes/vis-linelist.Rmd index 0ac8bb89..3d8252ae 100644 --- a/vignettes/vis-linelist.Rmd +++ b/vignettes/vis-linelist.Rmd @@ -127,6 +127,40 @@ plot(weekly) ``` To visualise the onset, hospitalisation and death incidence in the same plot they can be jointly specified to the `date_index` argument of `incidence2::incidence()`. + +First the outcome data needs to be pivoted from long data to wide data to be input into `incidence2::incidence()`. + +### Reshape line list data {.tabset} + +#### Base R + +```{r, reshape-linelist-base-r, eval=FALSE} +# this can also be achieved with the reshape() function but the user interface +# for that function is complicated so here we just create the columns manually +linelist$date_death <- linelist$date_outcome +linelist$date_death[linelist$outcome == "recovered"] <- NA +linelist$date_recovery <- linelist$date_outcome +linelist$date_recovery[linelist$outcome == "died"] <- NA +``` + +#### Tidyverse + +```{r, reshape-linelist-tidyverse, message=FALSE} +library(tidyr) +library(dplyr) +linelist <- linelist %>% + tidyr::pivot_wider( + names_from = outcome, + values_from = date_outcome + ) +linelist <- linelist %>% + dplyr::rename( + date_death = died, + date_recovery = recovered + ) +``` + +## {-} ```{r, plot-onset-hospitalisation, fig.cap="Figure 4: Daily incidence of cases from symptom onset and incidence of hospitalisations and deaths.", fig.width = 8, fig.height = 5} daily <- incidence( @@ -238,7 +272,7 @@ outbreak$contacts <- outbreak$contacts[outbreak$contacts$was_case == "Y", ] #### Tidyverse -```{r, subset-linelist-tidyverse, message=FALSE} +```{r, subset-linelist-tidyverse} library(dplyr) outbreak$contacts <- outbreak$contacts %>% dplyr::filter(was_case == "Y")