diff --git a/NAMESPACE b/NAMESPACE index 877fcbd2..de76e0bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -73,6 +73,17 @@ importFrom(lubridate,ymd) importFrom(posterior,as_draws_list) importFrom(posterior,subset_draws) importFrom(rlang,sym) +importFrom(stats,dnbinom) +importFrom(stats,dweibull) +importFrom(stats,ecdf) +importFrom(stats,plogis) +importFrom(stats,qlogis) +importFrom(stats,rlnorm) +importFrom(stats,rnbinom) +importFrom(stats,rnorm) +importFrom(stats,rt) +importFrom(stats,sd) +importFrom(stats,time) importFrom(tidybayes,spread_draws) importFrom(tidybayes,stat_halfeye) importFrom(tidybayes,stat_slab) diff --git a/R/data.R b/R/data.R index deac836b..fac93c1e 100644 --- a/R/data.R +++ b/R/data.R @@ -32,7 +32,7 @@ #' \item{site_pop}{The population size of the wastewater catchment area #' represented by the site variable} #' } -#' @source generate_simulated_data.R +#' @source vignette_data.R "ww_data" @@ -66,7 +66,7 @@ #' \item{state_pop}{The number of people contributing to the daily hospital #' admissions} #' } -#' @source generate_simulated_data.R +#' @source vignette_data.R "hosp_data" #' Example hospital admissions dataset for evaluation @@ -90,5 +90,29 @@ #' \item{state_pop}{The number of people contributing to the daily hospital #' admissions} #' } -#' @source generate_simulated_data.R +#' @source vignette_data.R "hosp_data_eval" + +#' COVID-19 post-Omicron generation interval probability mass function +#' +#' \describe{ +#' A vector that sums to 1, with each element representing the daily +#' probability of secondary onward transmission occurring on that day. The +#' first element of this vector represents the day after primary transmission +#' occurred, it is assumed to be impossible for primary and secondary +#' transmission to occur on the same day. +#' } +#' @source covid_pmfs.R +"generation_interval" + +#' COVID-19 time delay distribution from infection to hospital admission +#' +#' \describe{ +#' A vector that sums to 1, with each element representing the daily +#' probabilty of transitioning from infected to hospitalized, conditioned on +#' being infected and eventually ending up hospitalized. The first element +#' represents the probability of being infected and admitted to the hospital +#' on the same day +#' } +#' @source covid_pmfs.R +"inf_to_hosp" diff --git a/R/generate_simulated_data.R b/R/generate_simulated_data.R index 15e84175..43c3fd45 100644 --- a/R/generate_simulated_data.R +++ b/R/generate_simulated_data.R @@ -66,7 +66,10 @@ #' # different labs #' sim_data <- generate_simulated_data( #' n_sites = 6, -#' site = c(rep(1, 4), rep(2, 2)) +#' site = c(1, 2, 3, 4, 5, 6, 6), +#' lab = c(1, 1, 1, 1, 2, 2, 3), +#' ww_pop_sites = c(1e5, 4e5, 2e5, 1.5e5, 5e4, 3e5), +#' pop_size = 2e6 #' ) #' hosp_data <- sim_data$hosp_data #' ww_data <- sim_data$ww_data diff --git a/R/get_stan_data.R b/R/get_stan_data.R index 5317b60d..1d34f67a 100644 --- a/R/get_stan_data.R +++ b/R/get_stan_data.R @@ -572,7 +572,7 @@ get_subpop_data <- function(add_auxiliary_site, #' Get count data integer sizes for stan #' -#' @param input_cout_data a dataframe with the input count data +#' @param input_count_data a dataframe with the input count data #' @param forecast_date string indicating the forecast date #' @param forecast_horizon integer indicating the number of days to make a #' forecast for diff --git a/R/utils.R b/R/utils.R index c1a329d4..98b2524e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -132,7 +132,6 @@ convert_to_logsd <- function(mean, sd) { #' @export #' @examples #' to_simplex(c(1, 1, 1)) -#' @noRd to_simplex <- function(vector) { return(vector / sum(vector)) } diff --git a/R/wwinference-package.R b/R/wwinference-package.R index e6be48c4..d999b342 100644 --- a/R/wwinference-package.R +++ b/R/wwinference-package.R @@ -13,4 +13,6 @@ #' @importFrom posterior subset_draws as_draws_list #' @importFrom fs path_package #' @importFrom rlang sym +#' @importFrom stats dnbinom dweibull ecdf plogis qlogis rlnorm rnbinom rnorm +#' rt sd time NULL diff --git a/man/generate_simulated_data.Rd b/man/generate_simulated_data.Rd index b5638514..2cd6158b 100644 --- a/man/generate_simulated_data.Rd +++ b/man/generate_simulated_data.Rd @@ -119,7 +119,10 @@ and parameters to generate from. # different labs sim_data <- generate_simulated_data( n_sites = 6, - site = c(rep(1, 4), rep(2, 2)) + site = c(1, 2, 3, 4, 5, 6, 6), + lab = c(1, 1, 1, 1, 2, 2, 3), + ww_pop_sites = c(1e5, 4e5, 2e5, 1.5e5, 5e4, 3e5), + pop_size = 2e6 ) hosp_data <- sim_data$hosp_data ww_data <- sim_data$ww_data diff --git a/man/generation_interval.Rd b/man/generation_interval.Rd new file mode 100644 index 00000000..51654b66 --- /dev/null +++ b/man/generation_interval.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{generation_interval} +\alias{generation_interval} +\title{COVID-19 post-Omicron generation interval probability mass function} +\format{ +An object of class \code{numeric} of length 15. +} +\source{ +covid_pmfs.R +} +\usage{ +generation_interval +} +\description{ +\describe{ +A vector that sums to 1, with each element representing the daily +probability of secondary onward transmission occurring on that day. The +first element of this vector represents the day after primary transmission +occurred, it is assumed to be impossible for primary and secondary +transmission to occur on the same day. +} +} +\keyword{datasets} diff --git a/man/get_count_data_sizes.Rd b/man/get_count_data_sizes.Rd index 82935002..46d808e9 100644 --- a/man/get_count_data_sizes.Rd +++ b/man/get_count_data_sizes.Rd @@ -15,6 +15,8 @@ get_count_data_sizes( ) } \arguments{ +\item{input_count_data}{a dataframe with the input count data} + \item{forecast_date}{string indicating the forecast date} \item{forecast_horizon}{integer indicating the number of days to make a @@ -32,8 +34,6 @@ no observations} \item{count_col_name}{A string represeting the name of the column in the input_count_data that indicates the number of daily counts, default is \code{count}} - -\item{input_cout_data}{a dataframe with the input count data} } \value{ A list containing the integer sizes of the follow variables that diff --git a/man/hosp_data.Rd b/man/hosp_data.Rd index 9d8d335c..b75c70b3 100644 --- a/man/hosp_data.Rd +++ b/man/hosp_data.Rd @@ -3,46 +3,17 @@ \docType{data} \name{hosp_data} \alias{hosp_data} -\title{Example hospital admissions dataset - -A dataset containing the simulated daily hospital admissions -(labeled here as \code{daily_hosp_admits}) by date of admission (\code{date}). -Additional columns that are required are the population size of the -population contributing to the hospital admissions. It is assumed that -the wastewater sites are subsets of this larger population, which -is in the package data assumed to be from a hypothetical US state. -The data generated are daily hospital admissions but they could be any other -epidemiological count dataset e.g. cases. This data should only contain -hospital admissions that would have been available as of the date that -the forecast was made. We recommend that users try to format their data -to match this format. - -This data is generated via the default values in the -\code{generate_simulated_data()} function. They represent the bare minumum -required fields needed to pass to the model, and we recommend that users -try to format their own data to match this formate. - -The variables are as follows: -\describe{ -\item{date}{Date the hospital admissions occurred, formatte din ISO8601 -standatds as YYYY-MM-DD} -\item{daily_hosp_admits}{The number of individuals admitted to the -hospital on that date, available as of the forecast date} -\item{state_pop}{The number of people contributing to the daily hospital -admissions} -}} +\title{Example hospital admissions dataset} \format{ An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 90 rows and 3 columns. } \source{ -generate_simulated_data.R +vignette_data.R } \usage{ hosp_data } \description{ -Example hospital admissions dataset - A dataset containing the simulated daily hospital admissions (labeled here as \code{daily_hosp_admits}) by date of admission (\code{date}). Additional columns that are required are the population size of the @@ -54,7 +25,8 @@ epidemiological count dataset e.g. cases. This data should only contain hospital admissions that would have been available as of the date that the forecast was made. We recommend that users try to format their data to match this format. - +} +\details{ This data is generated via the default values in the \code{generate_simulated_data()} function. They represent the bare minumum required fields needed to pass to the model, and we recommend that users diff --git a/man/hosp_data_eval.Rd b/man/hosp_data_eval.Rd index 9a9c40cd..3713a275 100644 --- a/man/hosp_data_eval.Rd +++ b/man/hosp_data_eval.Rd @@ -3,45 +3,24 @@ \docType{data} \name{hosp_data_eval} \alias{hosp_data_eval} -\title{Example hospital admissions dataset for evaluation - -A dataset containing the simulated daily hospital admissions that the model -will be evaluated against (labeled here as \code{daily_hosp_admits_for_eval}) -by date of admission (\code{date}). This data is not needed to fit the model, -but is used in the Getting Started vignette to demonstrate the forecasted -hospital admissions compared to those later observed. - -This data is generated via the default values in the -\code{generate_simulated_data()} function. - -The variables are as follows: -\describe{ -\item{date}{Date the hospital admissions occurred, formatte din ISO8601 -standatds as YYYY-MM-DD} -\item{daily_hosp_admits_for_eval}{The number of individuals admitted to the -hospital on that date, available beyond the forecast date for evaluating -the forecasted hospital admissions} -\item{state_pop}{The number of people contributing to the daily hospital -admissions} -}} +\title{Example hospital admissions dataset for evaluation} \format{ An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 127 rows and 3 columns. } \source{ -generate_simulated_data.R +vignette_data.R } \usage{ hosp_data_eval } \description{ -Example hospital admissions dataset for evaluation - A dataset containing the simulated daily hospital admissions that the model will be evaluated against (labeled here as \code{daily_hosp_admits_for_eval}) by date of admission (\code{date}). This data is not needed to fit the model, but is used in the Getting Started vignette to demonstrate the forecasted hospital admissions compared to those later observed. - +} +\details{ This data is generated via the default values in the \code{generate_simulated_data()} function. diff --git a/man/inf_to_hosp.Rd b/man/inf_to_hosp.Rd new file mode 100644 index 00000000..ffa01998 --- /dev/null +++ b/man/inf_to_hosp.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{inf_to_hosp} +\alias{inf_to_hosp} +\title{COVID-19 time delay distribution from infection to hospital admission} +\format{ +An object of class \code{numeric} of length 55. +} +\source{ +covid_pmfs.R +} +\usage{ +inf_to_hosp +} +\description{ +\describe{ +A vector that sums to 1, with each element representing the daily +probabilty of transitioning from infected to hospitalized, conditioned on +being infected and eventually ending up hospitalized. The first element +represents the probability of being infected and admitted to the hospital +on the same day +} +} +\keyword{datasets} diff --git a/man/to_simplex.Rd b/man/to_simplex.Rd new file mode 100644 index 00000000..1a7b4d6d --- /dev/null +++ b/man/to_simplex.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{to_simplex} +\alias{to_simplex} +\title{Normalize vector to a simplex} +\usage{ +to_simplex(vector) +} +\arguments{ +\item{vector}{numeric vector} +} +\value{ +vector whos sum adds to 1 +} +\description{ +Normalize vector to a simplex +} +\examples{ +to_simplex(c(1, 1, 1)) +} diff --git a/man/ww_data.Rd b/man/ww_data.Rd index ec825e59..ee2bebde 100644 --- a/man/ww_data.Rd +++ b/man/ww_data.Rd @@ -26,7 +26,7 @@ represented by the site variable} } } \source{ -generate_simulated_data.R +vignette_data.R } \usage{ ww_data diff --git a/tests/testthat/test_diff_ar1.R b/tests/testthat/test_diff_ar1.R index 34792b5a..e69c3e3a 100644 --- a/tests/testthat/test_diff_ar1.R +++ b/tests/testthat/test_diff_ar1.R @@ -1,6 +1,5 @@ test_that( "Test differenced AR(1) Stan function agrees with R", - "implementation.", { model <- compiled_site_inf_model @@ -9,40 +8,40 @@ test_that( ar <- runif(1) sd <- exp(rnorm(1, 0, 0.5)) x0 <- rnorm(1, 0, 5) - }) - for (stat in c(TRUE, FALSE)) { - stan_ar_diff <- model$functions$diff_ar1( - x0 = x0, - ar = ar, - sd = sd, - z = z, - is_stat = stat - ) + for (stat in c(TRUE, FALSE)) { + stan_ar_diff <- model$functions$diff_ar1( + x0 = x0, + ar = ar, + sd = sd, + z = z, + is_stat = stat + ) - r_ar_diff <- diff_ar1_from_z_scores( - x0 = x0, - ar = ar, - sd = sd, - z = z, - stationary = stat - ) - r_ar_diff_alt <- diff_ar1_from_z_scores_alt( - x0 = x0, - ar = ar, - sd = sd, - z = z, - stationary = stat - ) + r_ar_diff <- diff_ar1_from_z_scores( + x0 = x0, + ar = ar, + sd = sd, + z = z, + stationary = stat + ) + r_ar_diff_alt <- diff_ar1_from_z_scores_alt( + x0 = x0, + ar = ar, + sd = sd, + z = z, + stationary = stat + ) - expect_equal( - stan_ar_diff, - r_ar_diff - ) - expect_equal( - stan_ar_diff, - r_ar_diff_alt - ) - } + expect_equal( + stan_ar_diff, + r_ar_diff + ) + expect_equal( + stan_ar_diff, + r_ar_diff_alt + ) + } + }) } )