From 4fd9b0dcf699f257b70d4559710dc6bbc7734fde Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 5 Apr 2024 17:29:37 +0100 Subject: [PATCH 01/11] added onset_to_recovery to sim_linelist and sim_outbreak, WIP #36 --- R/sim_linelist.R | 21 ++++++++++++++++----- R/sim_outbreak.R | 7 ++++++- man/sim_linelist.Rd | 16 ++++++++++++---- man/sim_outbreak.Rd | 16 ++++++++++++---- 4 files changed, 46 insertions(+), 14 deletions(-) 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/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 From db3c7370f2f2fcd708d4afaf9305aa1f3132f704 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 5 Apr 2024 17:30:09 +0100 Subject: [PATCH 02/11] added onset_to_recovery to as_function, WIP #36 --- R/utils.R | 16 +++++++++++++--- man/as_function.Rd | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) 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. From fab9a9040493d300a8a02e6587272fc6c580010c Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 5 Apr 2024 17:31:04 +0100 Subject: [PATCH 03/11] renamed and updated .add_deaths to .add_outcome, WIP #36 --- R/add_cols.R | 53 +++++++++++++++++++++++---------------------- man/dot-add_date.Rd | 25 ++++++++++++++++----- 2 files changed, 46 insertions(+), 32 deletions(-) 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/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 From d342165b9e955a84d4270deb9ed48a3cace6c7b2 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 5 Apr 2024 17:31:54 +0100 Subject: [PATCH 04/11] updated .sim_internal to call .add_outcome and use outcome columns, WIP #36 --- R/sim_internal.R | 8 +++++--- man/dot-sim_internal.Rd | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) 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/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 From fb136cbd8d149538f415b751cc9411e521eb23cd Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Fri, 5 Apr 2024 17:33:09 +0100 Subject: [PATCH 05/11] added onset_to_recovery to .check_sim_input and updated .cross_check_sim_input to return compound warnings or errors, WIP #36 --- R/checkers.R | 70 ++++++++++++++++++++------------ man/dot-check_sim_input.Rd | 16 ++++++-- man/dot-cross_check_sim_input.Rd | 10 +++-- 3 files changed, 63 insertions(+), 33 deletions(-) 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/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 From 7c4539a80c5dee36c5ac266432c3accac3c290ed Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 8 Apr 2024 17:46:59 +0100 Subject: [PATCH 06/11] add tidyr to Suggests in DESCRIPTION --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) 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), From 00e11e4c31f403bd881c8ea1851cd87a02b874f1 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Mon, 8 Apr 2024 17:47:34 +0100 Subject: [PATCH 07/11] added data reshaping (base R and tidyverse) to fix vis-linelist vignette --- vignettes/vis-linelist.Rmd | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/vignettes/vis-linelist.Rmd b/vignettes/vis-linelist.Rmd index 0ac8bb89..637b8b9d 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") From 5fe308342ff9cef06e22ee34dfe615c1e86ffcd3 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Mon, 8 Apr 2024 16:50:47 +0000 Subject: [PATCH 08/11] Update CITATION.cff --- CITATION.cff | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 From b8f9f33aa81e5ac295750bf501c531a6ab2d22e6 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 12:15:39 +0100 Subject: [PATCH 09/11] updated testdata and testdata README --- tests/testthat/testdata/README.md | 2 +- tests/testthat/testdata/pre_ct.rds | Bin 1687 -> 1583 bytes .../testdata/pre_date_first_contact.rds | Bin 854 -> 759 bytes .../testdata/pre_date_last_contact.rds | Bin 757 -> 671 bytes tests/testthat/testdata/pre_death.rds | Bin 1095 -> 0 bytes .../testthat/testdata/pre_hospitalisation.rds | Bin 1002 -> 893 bytes tests/testthat/testdata/pre_names.rds | Bin 1210 -> 1171 bytes tests/testthat/testdata/pre_outcome.rds | Bin 0 -> 966 bytes 8 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 tests/testthat/testdata/pre_death.rds create mode 100644 tests/testthat/testdata/pre_outcome.rds 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 21d677621e3877832d02912535b41ea1ec85fc9f..6c8a06b444dde6e8b319d80d7d679f2c98bd357e 100644 GIT binary patch literal 1583 zcmV+~2GIE*iwFP!000001FctkY!pQp-(Ih@*9U#tgoK8T2%(YI0>MDkY~he%dq6^= zJVLC~z3JV;-tM`(*K$pGC=i1fGzdNd3Q=kR!Kgw0ktm3kr=X2I5(tnY?NK$9cLTKb z+uNDz-L}{EN-z1{Z|0ks?=j!EGrNnD8HR~xtd@8tJ^`9c!h-oT3#Nc98#+4D0J(rT zfF(GYVXXQ@z%W1}APHat=*m(6sbt-7Ksq1;kO{~lI&%Qe5WPYDYnb3KF3b+KMM3Q) zg&`#j)Mhxcdhy?^m%`c$68ga~5?e0J*5gkSq-xA-*g3#{A}>oC;N96Pq_Zuevmo#FQ!(a@xRpgUy8QevpL_$n9XxLau7A8Z z83SLO`(#^_-XD4UrE9?7pX}Iv4ETpryGC^Z|Ju@C_!V$t-tHwwfZKPqOnMIZLB_L7 zCj~waqPGN}6eAA_yogkllsFYyXCMs&chcmnZqq|d{DLw4Ldh~G&CKTH(WIG~ zCe6&|Bt~PBJer)$8V07+WFK{%B# zNm{@`nD$2+NeqlJl6aFOGk^&bdBCbC&qz*OSM+?C<7#0@T!fqLMm)_&O~pv!qjA!> zXi?I5LPbgX&9oRPpC){n6eson1}V~d6R#UsToFfXoF{stIu=RKMjxx5QeoKS?h9!& z;CaTlnDPK~h044#(1111o223ICiHva>M?957#l_=xFH&4z z=W^|LD#rcU$#Az?A8nAD^7>oH-APl~U4Pg@df2Yf7tjlvLgNn)X8M+Vu-24in}T_{ z1}mW}qJM$u5_$RseP3}_r!aWuV(NxliqU6dDJ=I0pzt9RbzQVl z8ngS|A62O$n*QSPjt4893+9>+w4vhS#@4MV!yWhG0J?r+(U-G;e?E6V>q`IYT8>XX z{q~35{hK@fuKRav*!Y!;ubx{L>p?w)aUGJ9>#q)C-Q>)Lk`#UXAKT|=_ic>vpiY~v z_<79QeUc?5V;M7Kk01#=2o+6`a2=JGD9EqM5<5+D zVg(vRo>lI~q7&q0i1#XTt-#Y2Id-JTBB)?zVa0_d1#4KLtIFJpplY($jTN>Giz4=u zk!(A>?I6jiAa5HZqxDmz_7{Bj~pFNL-qZ@Cvse8}+(JNSlRM;-9Q!*psfbq1;t zob0qJ?AH*Hjj+3sr0K!26{zk_AFeBK_;3x9WO{Iv;b5TisUTxEb|HzKC%9n0st`{j zx0Qk|Nnjn+T;@EV>UIh&5(~hH8#bB7GR>nq2-y%+aGDkasOW-UUqumfr3|WyVw4ZA zy85W0!436VPXiamR(Ve;3@a*2}4S8gdR5gRnf1?XkJH^M}BBY$b;#JRyGk@1k;zfOp7cTiViDC6GCY=e^6UB!9%w! z*$L-!r7WqKz7?cVeU)L;GK16LgHNlBe22&i4nUkeM&ebxf;N$hDoS_Ds#nmED5&8s zCdxjImqX@KNjKbu;XzBt=@C@5dts{Kf5d7Vk5pW#?^=(L!i2^w&F?kuw+)`>Lb~Vr h>$qhN{6U^tqug=&9-_i(Mb`~C-T!;bZU8kC008h}27mwn literal 1687 zcmV;I259*oiwFP!000001I1WvRTH5s&~#1SA2H0jjZ7KpJ^21CR+Y0kVia)owN*2QUUO7BCL*Fd4@` z-X@*@iX(^*fguW#2vS3kPR0)f^(BjpuZ>SX!tsm|kT47q$@t^Jf;wMGoZ!GV1=~qG z(IyHCvMEuzhfyE88KbfL+kIaniOrRfY6q%yypCL!I~iBEu-+?{yYlJIA5!12+{)C|f-d}pwFN7lY$HlgH`d=#G>kFE)^uRYR+}XDR_~s|a zca#ACeXMOsyxQLK^y)Lfx8B~`)CzpB;r&N%tL@zKG!yW@TdVgp0pC7-{g1tB`{%Cq(UByd4RBX$Aj#bY0q!D6?;=U>Izd<=td-ODhCmTe?k36a`jl`JVTlyMwLtQ_ z-z7yr+mvZhw34E@LD;D#KakwG{^Sr%2+WGR)o><2T zK0m2vovG!=ogph;Ggu`JKz~D|1|B;_7BHwd(YzT zUDtPq*gH7!@?j;qe%I%}wmDK`9cSSA?pF@Cru5QwtSexM-+6hL+AfXOj|a^$u7DY( z2ytr|#OK%8?VLcQ=3*YNMS>kmOtn*Vdt{OJWEAs0*@>J?vEt$cnM%t=+37{hv$6+C zO^8TM#fay8pj(M#o2V!pk*8O2e4T_9rb4v2sEKUVu#A|Mq7&yYkwl@96Y5D{>IxqRmkSVl8>q6B;CL+&V%<%~EYN(Z77>S6} zD!eu%Gu6l;`lu|~>O%r!hz`P^Q? zE;3f+=A_^xnoC5lqzKr@lp>o8^Qs+MP%v-(a1B{lQKXTJDi&$P0{nla5vnwTC`uW| zCJrmm@Jbw=B$oP(CXZBu`az3MG8`EloaBZxM^V&Na2F3xb_Th zP&hY@FU1Z!MXe~vn4b94slD0|wJg6HoEeqc!T%4K{T<+cSWmo+*V0=kGg{(KQTA{O zY!z~-iwSm&6ld`L_8UcZHz&&jIssSxiovNvGOkspC(QQ{VL(gqd9Y?;lO?fnCY@aM hvsu3hejouIQMOgp12oeiskUKr{SS94?+OhR008nHKTH4s diff --git a/tests/testthat/testdata/pre_date_first_contact.rds b/tests/testthat/testdata/pre_date_first_contact.rds index c482f5aa294ab24966304f1d36aeeef6a1ed8223..66fe7a58fb0d22ffa8fa69b4e78c70efa3b76d9b 100644 GIT binary patch literal 759 zcmVBbDA%+fuIOc(I90Nh0=#36$v`(Lj@Vq zTJu^fx50KzzobP;gi#>&hDH(^DH#>kCyCk1G%bTs78oT9-BpM*#YQ@B&$;)Um={MG zUHJ3cdG2$c=Q;e(+5QBEVN{G-sbW+b_{nJY?cJG^2QdRIw4fxA5u^Yq#bkz2<3vy# zD4yi$K)9G5lt{i?0ZIm?fKoweAY3;cw35^n>z`u8M-kPB_M)Qwv{BMWiS~?E+7k22 z>r$zgkme7HBYQJKHr~J1;VNhC99#C6>v+4{#o6rK|4EmK*zIe)@~IOI&sEN>JN*Fp4b>IzM+%XD0) zGQ9|NG9Y$063;K3@4VpQ3%y{2Af)-5qulgcIC~{VNH7PF+O>eW9 zOMX_tffDB~2!zCg4Lq}}%C7^~Yla%%0WTdqR8$OXg2_!duIt`XfmxY7eHnN`ITic? zya|)%0DX#+<`XzR^z_<2U^7fU25g%vNnn8=cF#8j@j7#A>j>~+f26q=_-LRtTL3-} zg>!EM16g+t^Z>)Hp-roSvni`eHv?bm%sofp&@088BKe@PSJ=E>a>Qv+y~D<_zy)ef z?Ihk}{4GZI{5DH&nw)a;sA+Oi)8v$!7>mR_YEErfn!6ytQc6nKPXOn0>YgAgQm8dU|?WoU}0irU}gm}8CXL@+;lB~V!}WU2N3fDu@n$9 z0x=U=mHUjCtWh+#E zf%wW^JOV)a=Y){iRY3aJzBljYfcR@~_W3(pdSR58DbEU|)y=${4g+b0pc9i)fV4@* zy48Dtw4vAOAB%u=?eoP-mOxrjW(MCeAg$3nb#)w&R<39D3I*|X7x9$%)38VJ}Qk!1klLGMWZJQ7!8elSmf6KfcOg-I1JE8J^-O# zY=lJeOG60#0vhQrpppJ!3zRN_(&*waek~*s!04CI$bYd5N>@SYB4{Fb0EzsU3!sSr z#)r|cM6nT?C_X~z3{d1lBA4+$?)XHF{Jg~6R9NJ5Kn0mH(F&XVA}F6LJvA@2D6u3n zKMzNtz*3T#n+j8%0<<(fKd(3yR)p}v%!@}-CJ0srOoS!z@Dc^Zk(@>O<$5rOf+`&* gP=5UX|Nk=_z6DvFsFzj*)B^G|0569n3#tbI0ERGy0RR91 diff --git a/tests/testthat/testdata/pre_date_last_contact.rds b/tests/testthat/testdata/pre_date_last_contact.rds index 42e503335f2e6da86037f11102e757b42b80e862..6bbadfeed3d1bb322ba89d3920606b7d4cf41443 100644 GIT binary patch delta 597 zcmV-b0;>J>1)l|wDghXgD=&XgbHU~}Fn|Fgl07iHU>If}2NLE+!Z16Lu@DybqniuE zELbor0n7&Vn;1|v$p0Lfd1q#!W{ zD6n5uywAY>Q@8yw?zNh${+zczx97l=Y4_IJ-~L_tMWb<}{W0N+oa=uN-0hFOvVX4W zv&H@d>*J$uC6C+RFM76AXTcWx4-D}>vXf@opIqB&7$fOrf9HMYm8X+V*+2Tbrq#$f z+y0yIf3+XE!S;{(D&~F=Sz!M%weDQ<%5CX&evA`Hce7rbaurDT z$0c}q1L@g7murH=Iro_5fap^B&r^YP57Wm--+}aepv!fE^Z~|NgEEl#wL>%30qHqF zmp=p2OMgdlr2^?2{(oja0`X-&T0a2Nn@;_ma~w!-J-tN!KahVu^8AP1G9Z0Pc16@d zApK*>b7K`C{Y^kA#uP}OK(Q-w85tPrB zo|>0hlvt9PpNB~!F|(9p=BC0_rvL*hK0mKG6_&PnVdlkym7%(Yvnan@59S_Fxy1xZ jKL7v!e+5y<_#Z7YK;|dvr4=RSf};cgadEs^%>@7e`7V{x{#f7KhTC_J4}^J-^1?ZU0wyjcR|u6=wTCuRjGj z?DVt$tH>X|eod17KjkNKYphu9|HrQ4w3|Q0{vXGsW)@Zv`+q5-YWHd??f|{Yi=p+Xgu1F!Djx`Q!y`opki^Uw+G$ZRpY-Any z_k2ll7f^R#QJ&0rV`qP=1FJyM*6fX{4lMZ(R(eeraA0NK;&`t5mIH^CL0NI$9S0!? zkvWI`PdV_Ji7r*ps&Qa@`}Y2;8Yf^P2K&q5(sOX80@81+s|1;V^v83*=SKkPFWWXu zbq3O(*Prxc2Ju^L=mHUjCtWh+#Ef%wW^JOV)a=Y)Td*;PRL*SBc#=6yefV834=^u-LbnWxSN|r!cQDz3; zF(9qcJau&(kXEi|^$G>?brB%{-?NGFztB?5S2fJHtk zjYtI0$j3#aCkhx1jePV#$V<#kg#`jTRFEkXEz{)}LHS(isd=eIi6xo&c{nl$OG##K zDok|>Ffilu^NLepS&0{BUOZSCs#`dV^2_yL?g5ptOrRj-_y7O@XAp&q|Is1~WPYMv ST2W#yILZJwn*gPm1^@t$qe!y= diff --git a/tests/testthat/testdata/pre_death.rds b/tests/testthat/testdata/pre_death.rds deleted file mode 100644 index 07c92573a30d498f1b071d3110f72f6f3397a9f4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1095 zcmV-N1i1SjiwFP!000001Fe>SY!hV|$FJ>O*KJ+b)edk$`B4Eejxc11WqR+_xG;Xt zEe;czwY{=t>`JQ?*wMWUcx0bC%4F32#w!U5D)$9CS>3rnJ+_(9W;?8;Nzc=xB z|M?G!Q3V&#prV;bPjjhhI2T1<8 zTfPeW0>ZlX8Gb%15Y8U@w4rAnVT1jjRK9N~9CxPt>h@oV#l5&m5`QHQ;yiR|-Pgpn ztnkCxkF*f;(9my#El)!dtA3H*h`OnOH&%oTjKG^$?;NfL-ump+{%3&ybYEU+QtVw% zZn^**-n}Q>0~~4k_@Ud1?W(lef&cEQZVv-*pTF_vA;s>x{_Z-`8(ks>W^up;%T~Q{ z2{^mztGzzp()yDp&H+m*zZvcT?udLa_X*&fnFnoO0v~SMe_|8R)yh@YD0Xp&O$L^K z*LJ!cc+{}+N-1#Lsjh_v;Nw9tQ4O2WsP0-VjGT9iN0M-R(MtANk1PP=G`OvQDX$=_ zgVFs)gRCbFdZwgFFq#ZB_^BLA0t|jS>XU*JgHMCoI;{BxFNeV(U(^`w(SjT+(HO;` zM=|KpGe{Y!uc!77EeR-N82sqx$S^X5NzktaKXwF@fZCKaDS9v|ZX)ZI;A_D(B+|!I z?{|dyO_QAZxlQ8$wU=VDQ@?cfxO$rW$e0_Gp8D_B`Aw5v#~8I`&F=x~FK&uRhJL49 zABM(p1%LXQ@r6u=Pf(a(=1kVgWKlmec0pHw9s@lJDgl*&mScGdqg}4bhs6x+SBh`z zc}Ba`7lX=i{2I`UAUGb?4-(~LU@mBt{-mHJoOS3*xWPxb(!Og|$IA5Wlab7?Sbf2F z@#v`S*f8`~v)h`szjJNbftR}mr@GGQ_*sM7?I(XaFm~dl9+#r0QJ}}A6)TMa-Sr#{ zp`Ei?5QUIO4g|$C*C;Co8U@+Mzc11EFy( zCP{dW7CoEkMEUhWX=_0CYzau(Bc}SA9SSxtqW&t$WZVgVi9})`&303s-?PXcf+1kV N{{xD~Q#2zB003BeFv0); diff --git a/tests/testthat/testdata/pre_hospitalisation.rds b/tests/testthat/testdata/pre_hospitalisation.rds index 3521406ff9527d69c7851382c60079e808979961..1c5ef33c46523301822eb794fba776d703af0c48 100644 GIT binary patch literal 893 zcmV-@1A_b?iwFP!000001Fe;9NK;W5$M4>BbDFOW1VyNfB$cTYO2v^31s(RG7c!)^ z=G9higKef?(jq0IC=h!?BMFU^j0)?Mgl4I!8H}<(DKXrxLZm4+(z%{{?>RQFuC%)F zefTAb~B^663i42OA?7;ragj8q?hl&yi0#twq5ObX=O3HQw`~ZJI z4k&;CJSGs2TL%OKAwVb)2C(x+0PFF*-27)K?h$#dL)IdY_2gbCy&!9P6Sl(sh4T`m zDfyFOl8o zlf}^(U*C!*DXk{D`X+kSQk9e+nT>|OUU)lJ-HS%u_p6dKPNLax&t{i#9~!+}c55=C z9*xuG1Nx??XkyGB>}frQrqULaP5N>)bN+_l<#HIE3xU-SFQhq%s)elYY)~NG- zltMyr`%bqzxx@xNms{GU0KF(1ta%4|<;cQij{;PV>~KX!`}JYQMMj6wPOVIaj(0s8}vzELyQOX zh0~RI7t|ho?{EjGtHGJF33N7OL;g0<*9vvVaY%YGcT#vCWcp&A)rwP`G)njAY&7Ts zF{fgZ4blG&C3qIi5}GDdp?SnKp%T-CDm2lTV)KYO6)t|?>2`*g)Xpm-!De;x$|$jE zeY`R`SciD?7;GMcO=C1z1F>S$7!6iZkK#>aVtEtCv6&2w6}K}|);!)Ek;k_m!nm9i zjti?JgOA72DM&^fABmI1MUs-lvzU~)?jXrXv>)p*PENA_F`T500(wok>jqbeO}q4-593}G8Z67+NUU@jDe8)7K~M^dxipak#(qsPdw@M2&xDU$VmGQw TEVRH7Hluz5MvxQ7^aua|`Y@|@ literal 1002 zcmV6XcIvc$2ZAtnzlAgW9w18uhk7*e?d}_Gx28sL z;m>d0>>T^%y_wm(IEG;i468RV1`di0mzy&sZ8X%i2O}Po07?bvKzgMy!?1EgkP#FE zGJ#@2aoDFF_A`SLK^9OF$O@9jO$McaI)FNYI)OUlJj#3<80FES49&zwkO>vvObIxD zbJ1@}!uhrS>7$&F`-6;sQ4G$X3M0ttWpaxy!66Awv|}6|QL;Ov2(SOrylwLz2m8OT z|Enke_9@Y}RA-)=0nbuzAuW`@}a8BV~=&b&xe*3I(8lHLX0!+ z+Um=!gl)LFA}@C*VdLgor*Ez##;qxjR{J^-X|`#F{V8sg{0(we8Y9xhN3M z;yu5tx({JJ^(V6SS_sFT%e=Sl88KxHDfEfYiIpVpzc%X@F^^0+(qmvTF}{2E@^$e< zNMgk=Qs-AT74YrYq9i@=gl#wq%JU2ba&@~{YGYQyawzs=f+MaaQM>G6*a*0 ztlN#{!1ew^y~Y50cG+jX4(wmLr(zM%R>EcF%63}0SpsH0C_P&SJgl2`X9RHNnNtIF zz)>DCoCBLsuk2bijGSY+-RHyYMJw6Kc1Zw+XmCqD$V(7Y&S;)rLDrH6JzCNv_>~Ma z_$~Q62{8DPs7(q=3_cBRNu%l)EDnP~zN#`%tp+)mt}=i@4`9#(=a3RoTTkuvY7$Te zG5CQ?$ReZ{lb~J=e()eB0ktV1p?H%)Tt=Sr0g)E zPW{r@t?Fs=BZC>3^wj?hjo&osH4IW)QvGhA{^F+aN9lKq>qA%2s^E%T)4C8%_cjV` zj2z8e(M;-MeqYd2LBl|UKi26}+> Ykbm-r+6TM5&_&L|pXpATEi?)M08}#ekpKVy diff --git a/tests/testthat/testdata/pre_names.rds b/tests/testthat/testdata/pre_names.rds index 23c11553f127d18d68c021ebe71b9f1c875a8c26..e21da405222cb7544646dff8cdf4ad6da2d86738 100644 GIT binary patch literal 1171 zcmV;E1Z?{siwFP!000001FcqlOjB1BfBgbV`NlOdfoSG1G{X)xESPP%&DdnYM*rAg zXw15|_JMWu)$|o1OZ?c>ERMx3PWKUYnhh3ovTO_UpOFpchNw)pW~hk<35@p9Z4pqR zQK38Uy?e{+!&-_o`Sthi$2s?$_dD<2Tb)W#l!nr(HIzmNkCd+RmDS5ip)VI2S%7qa z5ugI7#mN+<6($0b0Lg$9fF2+?GXT=CT?QZ%`^g6600h4a0FPn6qW_(g_*2Q&A!`wk z^-^Ro$UxSVBj*9}EBz8^9{^n(B;nkQFk8q!#mUw%b}!?YWjopKX1%oCJ3rGE!wEW1 z%v)k>&2?C+AR~o;=mhsuarsyi>N2#MPTaqQE_QSt__(hPUAtF*yYTJrP*-ka-Ie}w z)D=VlleHan>jr=OZ{b;V!{cu$I@XRxD4R8Z|7Yl2+n(hc7gnI_H~0QEwEsLBm^`^> zMcJEZJU6^F}xzSvfvmRX0~6nA3ueHL%z&#`x|I<)s*45eLK4S?q=h+wth5a zTGi7%S%D^Zr+kuLnuKmWZ!KPbw*d-DjN9T1h=mQjYi&c99=J(&`9Lr52d}+eu?F}M zL~auL^&L;w30%ME)#67`VH`5h};j{a&LVq1AKMe z{X+vnJ8$%ve&FxVPaZxC{KJLjMPcAy10nNQz`p#}4X1%a&4HCq0FP%qzOe-OcYX2c zO;Ge|@k^0((An!~j>9ERI<+s*UIuuIh_hovNHO^fO7V+`r4&ucO7VzjN+zNySt(*H z#^Moic7&w3Ek2%z)G0Bq!D5|}m^Wb2E=bI;!F){;kH_NiSTx>>ISn%wjkjVZ?L0|D zzCaRj7>mg>m~lU^6~vRoQH5jcq0B2l;k+>W%cOk#XB5SV^CNkZyhu@!d?H1O+kR4v zgnKYw$HhtFAHqf2qTt=L%PVS&Rk>n6)Fjd~^Wh;@kLXY~dHO(F0(g>=4yJs-THL=H zkOwFLJO?lX$^cb>a==PJ5nwssSwJa%UO`ERanx5iUu-FCt@hM@ZA785s=_~~D0DM; zcP~4TAI}brrE`m$|IkPLEDkTZLO-=HGCpxCyMDumyA&$xJ&fJGmGMN5i1;0fL*&s7 z9)84W9nQH2mrzr_Qi3r{rlchB#xR3NX4$VS3De+~O7jF2(=Jvi6|}zhBga<7@^2}! zj&E~Ru2XJk^Tifl@Sq{XdIvV3!E@DLz6AVp@12~!_;!KrlAd=ynr;st{rjzdm&(Tb zuD;m2Inj-J9`ov8Q(JD#!LB6xRhErC{*V6iODCJ+=M{Z>U}+aaZVy?wQ|(k-H{BlG zPOW8F#zT9ZZZ^g(QR{WO7&6-di`v{Q$BSA9 literal 1210 zcmV;r1V#HFiwFP!000001I1Q-Y*SSffBkq}_tkcF16+`=y1|Si4B5moeRpb{3>Z4M zI80>L_H}E1I!030NjoJi2im{ z;!lC0ihw!_v>2%oNXPyoLDrIi{mbK1#_5l~2{bW~g#BlO1!2Fm4yT>9@~jQZNmiGW zw^;co!!gw7785jfdxvjpB#A90UTvvbvnl*zuIq;PpqDN)H@GvtA5-6CCiA; z-1y_~3UsQRnOv%Wwy*m|CS>}3QMZ|9!q0z{{K%1anUHp%RZV9yAzN1NaPuonsPFT2 zUGpz7q54Ma{$mS~X4AK(k#-|ekM?h`uG)vxDO-#iU++emx3UJCxOqsEx1}Ys_#UJ` zebrWKSdP@D{fePeETRqWPwKrnNbMT=ul)zUmUO!R|eD%{4ZI1!})7QUVCCGao z-g*{z;+?%7FYsjJ2lrkRWK&t10rRoyC=;m?b7svo!TEO3Y5VzawbWSmq`&!6$45BOr9ESZxCn?$m=uK<7sVCKbwcu` zdr6r1&uh%(&=D{AO9)r08WFATlq-Jxb!m zAB8W@xMy4+iiTMYd-R^!jd-Td(U`+>Jig*_YNw_z=u*G~fcpUjfMUQ}++Iydm#grw zSb+5k@oqgsNtgO6Knb3|3Gf^Mjz{r9B0L6`0XE1_3c`p^3tsTl+Yntie5vACv3xuh zqukPsXKm+>PRYingKspM)1vBUmKPs*p=T^nKU4D;kL@({{&XPX#JhQ1IR!<%<()&f z>gP_g{3M7t30KrQt=|LZ_5SN=laI$@G%)sL;NbY72z#B2hPwFZ`u;C|>$j&S>Sua> z;MFc~N|4Bjo`4bS&dnX{AH3Cd+-Z&-_snbGX=z}|wXesWN{8&3>2hN^rIvNFZVT^l zIioxW)x4vDCE7M{TH|tZEO|Vp6MHogY8j#$JU{rFnNLllIAC|UXN{;h_GQwv)DlDb zIv2Oy!CSUDxX2}HY^;T^Q-lrw9}%SIJRuGM0Oa&sGynhq diff --git a/tests/testthat/testdata/pre_outcome.rds b/tests/testthat/testdata/pre_outcome.rds new file mode 100644 index 0000000000000000000000000000000000000000..c8abe8ab4602cf77ea3bb45acef7e6d89f7e36a3 GIT binary patch literal 966 zcmV;%13CO3iwFP!000001Fe;NNK;W9$M0UcIn8`D5FAD?l+t`q7!^k{6m-}hJY{Xm_`Xr*=5xmhllo@MaaMVsAT|2oZAkcz@Tbk%Y{ zF>|yEwJDq9uKs+5Ufyf1J^is6efUv47JK9tYKtf>?CHxyZG*@Wr)fbQvd>SxM75(& zW_!bmOD$-a(rVN-=g`yUiliM;S*UlY@@;=jC$hP&S0tzJL*o&iWzM3_$W~o?VL0*< z8eqy^>YDDN!TzpLPs?sJvc|1!(v_jHV|!IMwSCAPx8`|=D+{^GC zB~Vb_bEkDVyoC*VG^eCZ0a_*Nu6+l3V&|@`Y|!&?@;Gi>ac^}Yr^PW}Pk|m6kJ!F} zUWAj!gSLteCLZ9%yC0st0a^zqw}UqP$O~dX-*5VP-p2K#N7nX%-tKhOwS(SyRv+U5 zee7^1TmkJ;H*S9b>a2I9ECC&#zi7uQ&=-ot2L({{V(**6`ykU5(iRIYaWW{~NLv|D zH!4(kHx038mz%sv1zOZE9pn`CbCO;69=%FEQ1w~vr^7H-W-v~zaPT9 z92CwAt3931$NorAj5t4%C&`NxCCO)^C~@CTijnAZti8B6$@%+nkv0gld}et~`oxNg z{5SNo8TqsEm#6+SpwHsp7t&&2ImKU0Y9I%XX8_T_QeZuh0Hg!kfJ`6-SOFvf>wr|; zPNw+Fc+y)rSDF^vm}}0zrb5oqZLx3M6dD@*UTL(cr+W^KhFBKXzgA4dS?F2ZL$9o! znE!S+ta$s$qry**kuGA$rzaQ>iVcFh%4Ej2lg=lBLJLfm{RS&tXt3}{oSdt| oY${10`Etb}J`8^zk7v-&tHGV0PSBg-5$L&p0b;NlM#BjJ08+WroB#j- literal 0 HcmV?d00001 From a2a6eed576e21e1169c26a83fe64dc167264141a Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 12:17:14 +0100 Subject: [PATCH 10/11] updated tests and snapshots with onset-to-recovery, relates #36 --- tests/testthat/_snaps/sim_linelist.md | 416 +++++++++++----------- tests/testthat/_snaps/sim_outbreak.md | 480 +++++++++++++------------- tests/testthat/test-add_cols.R | 44 ++- tests/testthat/test-checkers.R | 67 +++- tests/testthat/test-sim_linelist.R | 62 ++-- 5 files changed, 556 insertions(+), 513 deletions(-) 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))) }) From e9935fef4151fba36ebd4638b2dba4794b465323 Mon Sep 17 00:00:00 2001 From: Joshua Lambert Date: Wed, 10 Apr 2024 12:37:18 +0100 Subject: [PATCH 11/11] linting --- vignettes/vis-linelist.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vignettes/vis-linelist.Rmd b/vignettes/vis-linelist.Rmd index 637b8b9d..3d8252ae 100644 --- a/vignettes/vis-linelist.Rmd +++ b/vignettes/vis-linelist.Rmd @@ -148,14 +148,14 @@ linelist$date_recovery[linelist$outcome == "died"] <- NA ```{r, reshape-linelist-tidyverse, message=FALSE} library(tidyr) library(dplyr) -linelist <- linelist %>% +linelist <- linelist %>% tidyr::pivot_wider( - names_from = outcome, + names_from = outcome, values_from = date_outcome ) linelist <- linelist %>% dplyr::rename( - date_death = died, + date_death = died, date_recovery = recovered ) ```