From 35a9833ce2fa0104f6a6bfb8b1c3a0a89ac0fce5 Mon Sep 17 00:00:00 2001 From: athowes Date: Mon, 13 May 2024 14:57:24 +0100 Subject: [PATCH 1/3] Remove all models apart from latent_truncation_censoring_adjusted_delay() --- R/models.R | 405 ----------------------------------------------------- 1 file changed, 405 deletions(-) diff --git a/R/models.R b/R/models.R index af1c9d583..4e7a35411 100644 --- a/R/models.R +++ b/R/models.R @@ -1,168 +1,3 @@ -#' Estimate delays naively -#' -#' @family model -#' @export -naive_delay <- function(formula = brms::bf(delay_daily ~ 1, sigma ~ 1), data, - fn = brms::brm, family = "lognormal", ...) { - - data <- drop_zero(data) - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - -#' Estimate delays with filtering of the most recent data -#' -#' @family model -#' @export -filtered_naive_delay <- function( - formula = brms::bf(delay_daily ~ 1, sigma ~ 1), data, fn = brms::brm, - family = "lognormal", truncation = 10, ...) { - data <- data.table::as.data.table(data) - ## NEED TO FILTER BASED ON PTIME - data <- data[ptime_daily <= (obs_at - truncation)] - - data <- drop_zero(data) - - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - -#' Estimate delays adjusted for censoring -#' -#' @family model -#' @export -censoring_adjusted_delay <- function( - formula = brms::bf( - delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1 - ), data, fn = brms::brm, family = "lognormal", ...) { - data <- pad_zero(data) - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - -#' Estimate delays adjusted forcensoring using a -#' latent model -#' -#' @family model -#' @export -latent_censoring_adjusted_delay <- function( - formula = brms::bf( - delay_central | vreal(pwindow_upr, swindow_upr) ~ 1, - sigma ~ 1 - ), data, fn = brms::brm, - family = brms::custom_family( - "latent_lognormal", - dpars = c("mu", "sigma"), - links = c("identity", "log"), - lb = c(NA, 0), - ub = c(NA, NA), - type = "real", - vars = c("pwindow", "swindow"), - loop = FALSE - ), - scode_functions = " - real latent_lognormal_lpdf(vector y, vector mu, vector sigma, - vector pwindow, vector swindow) { - int n = num_elements(y); - vector[n] d = y - pwindow + swindow; - return lognormal_lpdf(d | mu, sigma); - } - ", - scode_parameters = " - vector[N] pwindow; - vector[N] swindow; - ", - scode_prior = " - pwindow ~ uniform(0, to_vector(vreal1)); - swindow ~ uniform(0, to_vector(vreal2)); - ", - ... -) { - - stanvars_functions <- brms::stanvar( - block = "functions", scode = scode_functions - ) - stanvars_parameters <- brms::stanvar( - block = "parameters", scode = scode_parameters - ) - stanvars_prior <- brms::stanvar(block = "model", scode = scode_prior) - - stanvars_all <- stanvars_functions + stanvars_parameters + stanvars_prior - - data <- data.table::as.data.table(data) - data[, id := 1:.N] - data[, pwindow_upr := ptime_upr - ptime_lwr] - data[, swindow_upr := stime_upr - stime_lwr] - data[, delay_central := stime_lwr - ptime_lwr] - - if (nrow(data) > 1) { - data <- data[, id := as.factor(id)] - } - - fit <- fn( - formula = formula, family = family, stanvars = stanvars_all, - backend = "cmdstanr", data = data, ... - ) - return(fit) -} - -#' Estimate delays with filtering of the most recent data and -#' censoring adjustment -#' -#' @family model -#' @export -filtered_censoring_adjusted_delay <- function( - formula = brms::bf( - delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1 - ), data, fn = brms::brm, family = "lognormal", truncation = 10, ...) { - - data <- data.table::as.data.table(data) - data <- data[ptime_daily <= (obs_at - truncation)] - - data <- pad_zero(data) - - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - -#' Estimate delays adjusted for right truncation -#' -#' @family model -#' @export -truncation_adjusted_delay <- function( - formula = brms::bf( - delay_daily | trunc(lb = 1, ub = censored_obs_time) ~ 1, sigma ~ 1 - ), data, fn = brms::brm, family = "lognormal", ...) { - - data <- drop_zero(data) - - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - -#' Estimate delays adjusted for censoring and right truncation -#' -#' @family model -#' @export -truncation_censoring_adjusted_delay <- function( - formula = brms::bf( - delay_lwr | cens(censored, delay_upr) + - trunc(lb = 1e-3, ub = censored_obs_time) ~ 1, - sigma ~ 1 - ), data, fn = brms::brm, family = "lognormal", ...) { - - data <- pad_zero(data) - - fn( - formula, data = data, family = family, backend = "cmdstanr", ... - ) -} - #' Estimate delays adjusted for right truncation and censoring using a #' latent model #' @@ -268,243 +103,3 @@ latent_truncation_censoring_adjusted_delay <- function( ) return(fit) } - -#' Estimate delays from the backward delay distribution + brms -#' @param data_cases data frame consisting of integer time column and incidence -#' column -#' -#' @family model -#' @export -dynamical_censoring_adjusted_delay <- function( - formula = brms::bf( - delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1 - ), - data, - data_cases, - fn = brms::brm, - family = "lognormal", - scode_tparameters = " - array[tlength] real cdenom; - - cdenom[1] = 0; - - for (i in 2:tlength) { - cdenom[i] = 0; - for (j in 1:(i-1)) { - if (j==1) { - cdenom[i] += - exp(lognormal_lcdf(j | Intercept, exp(Intercept_sigma)) + - log_cases[i-j]); - } else { - cdenom[i] += - exp( - log_diff_exp( - lognormal_lcdf(j | Intercept, exp(Intercept_sigma)), - lognormal_lcdf(j - 1 | Intercept, exp(Intercept_sigma)) - ) + - log_cases[i-j] - ); - } - } - } - ", - scode_model = " - if (!prior_only) { - for (i in 1:N) { - target += - log(cdenom[stime_daily[i] - tmin + 1]); - } - } - ", - ...) { - - if (as.character(formula)[1] != "delay_lwr | cens(censored, delay_upr) ~ 1") { - stop( - "Only `delay_lwr | cens(censored, delay_upr) ~ 1` has been tested. The current implementation is not robust to non-daily censoring, the use of multiple time series, or models that have more than simple intercepts" # nolint - ) - } - - if (missing(data_cases)) { - message("No `data_cases` provided. Using `data` to calculate incidence") - data_cases <- event_to_incidence(data) - } - - if (!all(c("time", "cases") %in% colnames(data_cases))) { - stop( - "`data_cases` must be a data.frame containing `time` and `cases` columns" - ) - } - cols <- colnames(data)[map_lgl(data, is.integer)] - data <- data.table::as.data.table(data) - data[, (cols) := lapply(.SD, as.double), .SDcols = cols] - - data <- drop_zero(data) - ## need to do this because lognormal doesn't like zero - data[delay_lwr == 0, delay_lwr := 1e-3] - - tmin <- pmin(min(data$ptime_daily), min(data_cases$time)) - tmax <- pmax(max(data$stime_daily), max(data_cases$time)) - - data_cases_tmp <- data.table( - time = tmin:tmax, - cases = 1e-3 - ) - - data_cases_tmp[match(data_cases$time, time), cases := data_cases$cases] - data_cases <- data_cases_tmp - - cases <- data_cases$cases - log_cases <- log(cases) - tmin <- min(data_cases$time) - tlength <- nrow(data_cases) - - stanvars_data <- c( - brms::stanvar( - x = tmin, block = "data", - scode = "int tmin;", - name = "tmin" - ), - brms::stanvar( - x = tlength, block = "data", - scode = "int tlength; // time series length", - name = "tlength" - ), - brms::stanvar( - x = data$stime_daily, block = "data", - scode = "array[N] int stime_daily;", - name = "stime_daily" - ), - brms::stanvar( - x = log_cases, block = "data", - scode = "array[tlength] real log_cases;", - name = "log_cases" - ) - ) - - stanvars_tparameters <- brms::stanvar( - block = "tparameters", scode = scode_tparameters - ) - - stanvars_model <- brms::stanvar( - block = "model", scode = scode_model - ) - - stanvars_gp <- brms::stanvar( - block = "genquant", scode = " - array[tlength] real backwardmean; - - for (i in 1:tlength) { - backwardmean[i] = 0; - - // this is quite approximate... - // but sort of the best we can do without sacrificing a ton of - // computational power - for (j in 1:(i-1)) { - backwardmean[i] += exp( - log_diff_exp( - lognormal_lcdf(j | Intercept, exp(Intercept_sigma)), - lognormal_lcdf(j - 1 | Intercept, exp(Intercept_sigma)) - ) + - log_cases[i-j] + log(j-0.5) - log(cdenom[i]) - ); - } - } - " - ) - - stanvars_all <- stanvars_data + stanvars_tparameters + stanvars_model + - stanvars_gp - - fit <- fn( - formula, data = data, - family = family, - stanvars = stanvars_all, - backend = "cmdstanr", - ... - ) - - return(fit) -} - -#' @family model -#' @export -dynamical_censoring_adjusted_delay_wrapper <- function(data, data_cases, ...) { - dynamical_censoring_adjusted_delay(data = data, ...) -} - -#' @family model -#' @export -epinowcast_delay <- function(formula = ~ 1, data, by = c(), - family = "lognormal", max_delay = 30, - model = epinowcast::enw_model(), - sampler = epinowcast::enw_sample, - with_epinowcast_output = TRUE, - ...) { - # check if the epinowcast package is installed and error if not - if (!requireNamespace("epinowcast", quietly = TRUE)) { - stop( - "epinowcast is not installed. Please install it to use this function" - ) - } - data_as_counts <- data.table::as.data.table(data) - data_as_counts <- data_as_counts[, .(new_confirm = .N), by = c("ptime_daily", "stime_daily", by)] - data_as_counts <- data_as_counts[order(ptime_daily, stime_daily)] - data_as_counts[, reference_date := as.Date("2000-01-01") + ptime_daily] - data_as_counts[, report_date := as.Date("2000-01-01") + stime_daily] - - # Actual largest observerable delay - preprocess_delay <- min( - max_delay, - max(data_as_counts$report_date) - min(data_as_counts$reference_date) + 1 - ) - # Update to make sure we have enough data to fit the model - complete_delay <- max(max_delay, preprocess_delay) - - cum_counts <- data_as_counts |> - epinowcast::enw_incidence_to_cumulative(by = by) - - complete_counts <- epinowcast::enw_complete_dates( - cum_counts, by = by, max_delay = complete_delay - ) - - epinowcast_data <- epinowcast::enw_preprocess_data( - complete_counts, by = by, max_delay = preprocess_delay - ) - - reference <- epinowcast::enw_reference( - parametric = formula, - distribution = family, - data = epinowcast_data - ) - - expectation <- epinowcast::enw_expectation( - r = ~ week, - data = epinowcast_data - ) - - observation <- epinowcast::enw_obs( - family = "negbin", - data = epinowcast_data - ) - - fit <- epinowcast::epinowcast( - data = epinowcast_data, - reference = reference, - expectation = expectation, - obs = observation, - model = model, - fit = epinowcast::enw_fit_opts( - sampler = sampler, - ... - ) - ) - - if (!with_epinowcast_output) { - fit <- fit[, -c( - "obs", "new_confirm", "latest", "missing_reference", - "reporting_triangle", "metareference", "metareport", - "metadelay", "time", "snapshots", "by", "groups", - "max_delay", "max_date", "data", "fit_args" - )] - } - return(fit[]) -} From bce2dfe9e479c3c243e6efbcddab82d8283dbead Mon Sep 17 00:00:00 2001 From: athowes Date: Mon, 13 May 2024 15:10:14 +0100 Subject: [PATCH 2/3] Document package functions --- NAMESPACE | 10 ------- man/add_natural_scale_mean_sd.Rd | 13 +++++++++ man/calculate_censor_delay.Rd | 10 +++++++ man/calculate_cohort_mean.Rd | 12 +++++++++ man/calculate_truncated_means.Rd | 12 +++++++++ man/censoring_adjusted_delay.Rd | 17 ------------ man/combine_obs.Rd | 10 +++++++ man/construct_cases_by_obs_window.Rd | 10 +++++++ man/draws_to_long.Rd | 13 +++++++++ man/drop_zero.Rd | 8 ++++++ man/dynamical_censoring_adjusted_delay.Rd | 26 ------------------ man/epidist-package.Rd | 1 + man/event_to_incidence.Rd | 10 +++++++ man/extract_epinowcast_draws.Rd | 13 +++++++++ man/extract_lognormal_draws.Rd | 13 +++++++++ man/filter_obs_by_obs_time.Rd | 8 ++++++ man/filter_obs_by_ptime.Rd | 8 ++++++ man/filtered_censoring_adjusted_delay.Rd | 20 -------------- man/filtered_naive_delay.Rd | 18 ------------- man/latent_censoring_adjusted_delay.Rd | 27 ------------------- ...ent_truncation_censoring_adjusted_delay.Rd | 1 + man/linelist_to_cases.Rd | 10 +++++++ man/linelist_to_counts.Rd | 10 +++++++ man/make_relative_to_truth.Rd | 13 +++++++++ man/naive_delay.Rd | 17 ------------ man/observe_process.Rd | 8 ++++++ man/pad_zero.Rd | 8 ++++++ man/plot_cases_by_obs_window.Rd | 12 +++++++++ man/plot_censor_delay.Rd | 12 +++++++++ man/plot_cohort_mean.Rd | 12 +++++++++ man/plot_empirical_delay.Rd | 12 +++++++++ man/plot_mean_posterior_pred.Rd | 12 +++++++++ man/plot_recovery.Rd | 12 +++++++++ man/plot_relative_recovery.Rd | 12 +++++++++ man/primary_censoring_bias_correction.Rd | 13 +++++++++ man/reverse_obs_at.Rd | 10 +++++++ man/sample_epinowcast_model.Rd | 13 +++++++++ man/sample_model.Rd | 13 +++++++++ man/simulate_double_censored_pmf.Rd | 8 ++++++ man/simulate_exponential_cases.Rd | 8 ++++++ man/simulate_gillespie.Rd | 8 ++++++ man/simulate_secondary.Rd | 8 ++++++ man/simulate_uniform_cases.Rd | 8 ++++++ man/summarise_draws.Rd | 13 +++++++++ man/summarise_variable.Rd | 13 +++++++++ man/truncation_adjusted_delay.Rd | 17 ------------ man/truncation_censoring_adjusted_delay.Rd | 18 ------------- 47 files changed, 390 insertions(+), 170 deletions(-) delete mode 100644 man/censoring_adjusted_delay.Rd delete mode 100644 man/dynamical_censoring_adjusted_delay.Rd delete mode 100644 man/filtered_censoring_adjusted_delay.Rd delete mode 100644 man/filtered_naive_delay.Rd delete mode 100644 man/latent_censoring_adjusted_delay.Rd delete mode 100644 man/naive_delay.Rd delete mode 100644 man/truncation_adjusted_delay.Rd delete mode 100644 man/truncation_censoring_adjusted_delay.Rd diff --git a/NAMESPACE b/NAMESPACE index 079f428fb..d10c18a3c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,27 +4,19 @@ export(add_natural_scale_mean_sd) export(calculate_censor_delay) export(calculate_cohort_mean) export(calculate_truncated_means) -export(censoring_adjusted_delay) export(combine_obs) export(construct_cases_by_obs_window) export(draws_to_long) export(drop_zero) -export(dynamical_censoring_adjusted_delay) -export(dynamical_censoring_adjusted_delay_wrapper) -export(epinowcast_delay) export(event_to_incidence) export(extract_epinowcast_draws) export(extract_lognormal_draws) export(filter_obs_by_obs_time) export(filter_obs_by_ptime) -export(filtered_censoring_adjusted_delay) -export(filtered_naive_delay) -export(latent_censoring_adjusted_delay) export(latent_truncation_censoring_adjusted_delay) export(linelist_to_cases) export(linelist_to_counts) export(make_relative_to_truth) -export(naive_delay) export(observe_process) export(pad_zero) export(plot_cases_by_obs_window) @@ -45,8 +37,6 @@ export(simulate_secondary) export(simulate_uniform_cases) export(summarise_draws) export(summarise_variable) -export(truncation_adjusted_delay) -export(truncation_censoring_adjusted_delay) import(brms) import(cmdstanr) import(data.table) diff --git a/man/add_natural_scale_mean_sd.Rd b/man/add_natural_scale_mean_sd.Rd index 697a11835..658f382b2 100644 --- a/man/add_natural_scale_mean_sd.Rd +++ b/man/add_natural_scale_mean_sd.Rd @@ -9,3 +9,16 @@ add_natural_scale_mean_sd(dt) \description{ Add natural scale summary parameters for a lognormal distribution } +\seealso{ +Other postprocess: +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/calculate_censor_delay.Rd b/man/calculate_censor_delay.Rd index e9d5f57af..58211ea24 100644 --- a/man/calculate_censor_delay.Rd +++ b/man/calculate_censor_delay.Rd @@ -9,3 +9,13 @@ calculate_censor_delay(truncated_obs, additional_by = c()) \description{ Calculate the mean difference between continuous and discrete event time } +\seealso{ +Other preprocess: +\code{\link{combine_obs}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{linelist_to_counts}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/calculate_cohort_mean.Rd b/man/calculate_cohort_mean.Rd index 738e5e6f1..57e5d71b5 100644 --- a/man/calculate_cohort_mean.Rd +++ b/man/calculate_cohort_mean.Rd @@ -9,3 +9,15 @@ calculate_cohort_mean(data, type = c("cohort", "cumulative"), by = c(), obs_at) \description{ Calculate the cohort-based or cumulative mean } +\seealso{ +Other plot: +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/calculate_truncated_means.Rd b/man/calculate_truncated_means.Rd index 088ffb9ee..39542c32a 100644 --- a/man/calculate_truncated_means.Rd +++ b/man/calculate_truncated_means.Rd @@ -16,3 +16,15 @@ calculate_truncated_means( \description{ Calculate the truncated mean by observation horizon } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/censoring_adjusted_delay.Rd b/man/censoring_adjusted_delay.Rd deleted file mode 100644 index 56c3a79e3..000000000 --- a/man/censoring_adjusted_delay.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{censoring_adjusted_delay} -\alias{censoring_adjusted_delay} -\title{Estimate delays adjusted for censoring} -\usage{ -censoring_adjusted_delay( - formula = brms::bf(delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - ... -) -} -\description{ -Estimate delays adjusted for censoring -} diff --git a/man/combine_obs.Rd b/man/combine_obs.Rd index 5f434c412..36e0340ad 100644 --- a/man/combine_obs.Rd +++ b/man/combine_obs.Rd @@ -9,3 +9,13 @@ combine_obs(truncated_obs, obs) \description{ Combine truncated and fully observed observations } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{linelist_to_counts}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/construct_cases_by_obs_window.Rd b/man/construct_cases_by_obs_window.Rd index 2c61b09ed..af713bc73 100644 --- a/man/construct_cases_by_obs_window.Rd +++ b/man/construct_cases_by_obs_window.Rd @@ -14,3 +14,13 @@ construct_cases_by_obs_window( \description{ Construct case counts by observation window based on secondary observations } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{combine_obs}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{linelist_to_counts}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/draws_to_long.Rd b/man/draws_to_long.Rd index c4203bb09..ff46a5faa 100644 --- a/man/draws_to_long.Rd +++ b/man/draws_to_long.Rd @@ -9,3 +9,16 @@ draws_to_long(draws) \description{ Convert posterior lognormal samples to long format } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/drop_zero.Rd b/man/drop_zero.Rd index 675770bb4..568d1c390 100644 --- a/man/drop_zero.Rd +++ b/man/drop_zero.Rd @@ -9,3 +9,11 @@ drop_zero(data) \description{ Drop zero observations as unstable in a lognormal distribution } +\seealso{ +Other observe: +\code{\link{filter_obs_by_obs_time}()}, +\code{\link{filter_obs_by_ptime}()}, +\code{\link{observe_process}()}, +\code{\link{pad_zero}()} +} +\concept{observe} diff --git a/man/dynamical_censoring_adjusted_delay.Rd b/man/dynamical_censoring_adjusted_delay.Rd deleted file mode 100644 index e24c4510c..000000000 --- a/man/dynamical_censoring_adjusted_delay.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{dynamical_censoring_adjusted_delay} -\alias{dynamical_censoring_adjusted_delay} -\title{Estimate delays from the backward delay distribution + brms} -\usage{ -dynamical_censoring_adjusted_delay( - formula = brms::bf(delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1), - data, - data_cases, - fn = brms::brm, - family = "lognormal", - scode_tparameters = - "\\n array[tlength] real cdenom;\\n \\n cdenom[1] = 0;\\n \\n for (i in 2:tlength) {\\n cdenom[i] = 0;\\n for (j in 1:(i-1)) {\\n if (j==1) {\\n cdenom[i] += \\n exp(lognormal_lcdf(j | Intercept, exp(Intercept_sigma)) +\\n log_cases[i-j]);\\n } else {\\n cdenom[i] += \\n exp(\\n log_diff_exp(\\n lognormal_lcdf(j | Intercept, exp(Intercept_sigma)), \\n lognormal_lcdf(j - 1 | Intercept, exp(Intercept_sigma))\\n ) + \\n log_cases[i-j]\\n );\\n }\\n }\\n }\\n ", - scode_model = - "\\n if (!prior_only) {\\n for (i in 1:N) {\\n target += - log(cdenom[stime_daily[i] - tmin + 1]);\\n }\\n }\\n ", - ... -) -} -\arguments{ -\item{data_cases}{data frame consisting of integer time column and incidence -column} -} -\description{ -Estimate delays from the backward delay distribution + brms -} diff --git a/man/epidist-package.Rd b/man/epidist-package.Rd index d23459e67..167072c19 100644 --- a/man/epidist-package.Rd +++ b/man/epidist-package.Rd @@ -14,6 +14,7 @@ Understanding and accurately estimating epidemiological delay distributions is i Authors: \itemize{ \item Sam Abbott \email{contact@samabbott.co.uk} (\href{https://orcid.org/0000-0001-8057-8037}{ORCID}) + \item Adam Howes \email{adamthowes@gmail.com} (\href{https://orcid.org/0000-0003-2386-4031}{ORCID}) } } diff --git a/man/event_to_incidence.Rd b/man/event_to_incidence.Rd index cc11ddbb4..89feb6cf1 100644 --- a/man/event_to_incidence.Rd +++ b/man/event_to_incidence.Rd @@ -9,3 +9,13 @@ event_to_incidence(data, by = c()) \description{ Convert from event based to incidence based data } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{combine_obs}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{linelist_to_counts}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/extract_epinowcast_draws.Rd b/man/extract_epinowcast_draws.Rd index 742dfd14f..d21891e53 100644 --- a/man/extract_epinowcast_draws.Rd +++ b/man/extract_epinowcast_draws.Rd @@ -9,3 +9,16 @@ extract_epinowcast_draws(data, id_vars, from_dt = FALSE) \description{ Extract posterior samples for a lognormal epinowcast model } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/extract_lognormal_draws.Rd b/man/extract_lognormal_draws.Rd index 2f7a9e533..09a0edc41 100644 --- a/man/extract_lognormal_draws.Rd +++ b/man/extract_lognormal_draws.Rd @@ -9,3 +9,16 @@ extract_lognormal_draws(data, id_vars, from_dt = FALSE) \description{ Extract posterior samples for a lognormal brms model } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/filter_obs_by_obs_time.Rd b/man/filter_obs_by_obs_time.Rd index 6fb1f887d..0699b37fa 100644 --- a/man/filter_obs_by_obs_time.Rd +++ b/man/filter_obs_by_obs_time.Rd @@ -9,3 +9,11 @@ filter_obs_by_obs_time(linelist, obs_time) \description{ Filter observations based on a observation time of secondary events } +\seealso{ +Other observe: +\code{\link{drop_zero}()}, +\code{\link{filter_obs_by_ptime}()}, +\code{\link{observe_process}()}, +\code{\link{pad_zero}()} +} +\concept{observe} diff --git a/man/filter_obs_by_ptime.Rd b/man/filter_obs_by_ptime.Rd index cc0e20b8a..10add96ec 100644 --- a/man/filter_obs_by_ptime.Rd +++ b/man/filter_obs_by_ptime.Rd @@ -13,3 +13,11 @@ filter_obs_by_ptime( \description{ Filter observations based on the observation time of primary events } +\seealso{ +Other observe: +\code{\link{drop_zero}()}, +\code{\link{filter_obs_by_obs_time}()}, +\code{\link{observe_process}()}, +\code{\link{pad_zero}()} +} +\concept{observe} diff --git a/man/filtered_censoring_adjusted_delay.Rd b/man/filtered_censoring_adjusted_delay.Rd deleted file mode 100644 index 322483e05..000000000 --- a/man/filtered_censoring_adjusted_delay.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{filtered_censoring_adjusted_delay} -\alias{filtered_censoring_adjusted_delay} -\title{Estimate delays with filtering of the most recent data and -censoring adjustment} -\usage{ -filtered_censoring_adjusted_delay( - formula = brms::bf(delay_lwr | cens(censored, delay_upr) ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - truncation = 10, - ... -) -} -\description{ -Estimate delays with filtering of the most recent data and -censoring adjustment -} diff --git a/man/filtered_naive_delay.Rd b/man/filtered_naive_delay.Rd deleted file mode 100644 index c37d94562..000000000 --- a/man/filtered_naive_delay.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{filtered_naive_delay} -\alias{filtered_naive_delay} -\title{Estimate delays with filtering of the most recent data} -\usage{ -filtered_naive_delay( - formula = brms::bf(delay_daily ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - truncation = 10, - ... -) -} -\description{ -Estimate delays with filtering of the most recent data -} diff --git a/man/latent_censoring_adjusted_delay.Rd b/man/latent_censoring_adjusted_delay.Rd deleted file mode 100644 index 34e7dfc52..000000000 --- a/man/latent_censoring_adjusted_delay.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{latent_censoring_adjusted_delay} -\alias{latent_censoring_adjusted_delay} -\title{Estimate delays adjusted forcensoring using a -latent model} -\usage{ -latent_censoring_adjusted_delay( - formula = brms::bf(delay_central | vreal(pwindow_upr, swindow_upr) ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = brms::custom_family("latent_lognormal", dpars = c("mu", "sigma"), links = - c("identity", "log"), lb = c(NA, 0), ub = c(NA, NA), type = "real", vars = - c("pwindow", "swindow"), loop = FALSE), - scode_functions = - "\\n real latent_lognormal_lpdf(vector y, vector mu, vector sigma,\\n vector pwindow, vector swindow) {\\n int n = num_elements(y);\\n vector[n] d = y - pwindow + swindow;\\n return lognormal_lpdf(d | mu, sigma);\\n }\\n ", - scode_parameters = - "\\n vector[N] pwindow;\\n vector[N] swindow;\\n ", - scode_prior = - "\\n pwindow ~ uniform(0, to_vector(vreal1));\\n swindow ~ uniform(0, to_vector(vreal2));\\n ", - ... -) -} -\description{ -Estimate delays adjusted forcensoring using a -latent model -} diff --git a/man/latent_truncation_censoring_adjusted_delay.Rd b/man/latent_truncation_censoring_adjusted_delay.Rd index b8778d408..288d7204e 100644 --- a/man/latent_truncation_censoring_adjusted_delay.Rd +++ b/man/latent_truncation_censoring_adjusted_delay.Rd @@ -28,3 +28,4 @@ latent_truncation_censoring_adjusted_delay( Estimate delays adjusted for right truncation and censoring using a latent model } +\concept{model} diff --git a/man/linelist_to_cases.Rd b/man/linelist_to_cases.Rd index 1eabfd94f..db8714438 100644 --- a/man/linelist_to_cases.Rd +++ b/man/linelist_to_cases.Rd @@ -9,3 +9,13 @@ linelist_to_cases(linelist) \description{ Convert primary and secondary observations to counts in long format } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{combine_obs}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_counts}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/linelist_to_counts.Rd b/man/linelist_to_counts.Rd index ceaa40b29..9cede409c 100644 --- a/man/linelist_to_counts.Rd +++ b/man/linelist_to_counts.Rd @@ -14,3 +14,13 @@ linelist_to_counts( \description{ For a target variable convert from individual data to counts } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{combine_obs}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{reverse_obs_at}()} +} +\concept{preprocess} diff --git a/man/make_relative_to_truth.Rd b/man/make_relative_to_truth.Rd index 773c86d9b..26c25f095 100644 --- a/man/make_relative_to_truth.Rd +++ b/man/make_relative_to_truth.Rd @@ -9,3 +9,16 @@ make_relative_to_truth(draws, secondary_dist, by = "parameter") \description{ Make posterior lognormal samples relative to true values } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/naive_delay.Rd b/man/naive_delay.Rd deleted file mode 100644 index 74f0b2909..000000000 --- a/man/naive_delay.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{naive_delay} -\alias{naive_delay} -\title{Estimate delays naively} -\usage{ -naive_delay( - formula = brms::bf(delay_daily ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - ... -) -} -\description{ -Estimate delays naively -} diff --git a/man/observe_process.Rd b/man/observe_process.Rd index 69eae4351..2fe2e427f 100644 --- a/man/observe_process.Rd +++ b/man/observe_process.Rd @@ -9,3 +9,11 @@ observe_process(linelist) \description{ Observation process for primary and secondary events } +\seealso{ +Other observe: +\code{\link{drop_zero}()}, +\code{\link{filter_obs_by_obs_time}()}, +\code{\link{filter_obs_by_ptime}()}, +\code{\link{pad_zero}()} +} +\concept{observe} diff --git a/man/pad_zero.Rd b/man/pad_zero.Rd index 260bf26af..a9bb2c682 100644 --- a/man/pad_zero.Rd +++ b/man/pad_zero.Rd @@ -9,3 +9,11 @@ pad_zero(data, pad = 0.001) \description{ Pad zero observations as unstable in a lognormal distribution } +\seealso{ +Other observe: +\code{\link{drop_zero}()}, +\code{\link{filter_obs_by_obs_time}()}, +\code{\link{filter_obs_by_ptime}()}, +\code{\link{observe_process}()} +} +\concept{observe} diff --git a/man/plot_cases_by_obs_window.Rd b/man/plot_cases_by_obs_window.Rd index 91fbff972..01788b46d 100644 --- a/man/plot_cases_by_obs_window.Rd +++ b/man/plot_cases_by_obs_window.Rd @@ -9,3 +9,15 @@ plot_cases_by_obs_window(cases) \description{ Plot cases by observation window } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_censor_delay.Rd b/man/plot_censor_delay.Rd index ad33dde87..2c2f11f76 100644 --- a/man/plot_censor_delay.Rd +++ b/man/plot_censor_delay.Rd @@ -9,3 +9,15 @@ plot_censor_delay(censor_delay) \description{ Plot the mean difference between continuous and discrete event time } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_cohort_mean.Rd b/man/plot_cohort_mean.Rd index 7d92397a0..6a1cc59f6 100644 --- a/man/plot_cohort_mean.Rd +++ b/man/plot_cohort_mean.Rd @@ -9,3 +9,15 @@ plot_cohort_mean(data) \description{ Plot empirical cohort-based or cumulative mean } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_empirical_delay.Rd b/man/plot_empirical_delay.Rd index adc0170de..cad90c63b 100644 --- a/man/plot_empirical_delay.Rd +++ b/man/plot_empirical_delay.Rd @@ -9,3 +9,15 @@ plot_empirical_delay(cases, meanlog, sdlog) \description{ Plot the empirical delay distribution } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_mean_posterior_pred.Rd b/man/plot_mean_posterior_pred.Rd index 60059a225..cbb3613ca 100644 --- a/man/plot_mean_posterior_pred.Rd +++ b/man/plot_mean_posterior_pred.Rd @@ -34,3 +34,15 @@ plot_mean_posterior_pred( \description{ plot empirical cohort-based or cumulative mean vs posterior mean } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_recovery}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_recovery.Rd b/man/plot_recovery.Rd index 861bbbb63..427d34087 100644 --- a/man/plot_recovery.Rd +++ b/man/plot_recovery.Rd @@ -9,3 +9,15 @@ plot_recovery(data, alpha = 0.8, quantiles = c(0.05, 0.35, 0.65, 0.95), ...) \description{ Plot the posterior estimates as densities } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_relative_recovery}()} +} +\concept{plot} diff --git a/man/plot_relative_recovery.Rd b/man/plot_relative_recovery.Rd index badc56493..c73cdf9c6 100644 --- a/man/plot_relative_recovery.Rd +++ b/man/plot_relative_recovery.Rd @@ -14,3 +14,15 @@ plot_relative_recovery( \description{ Plot the relative difference between true values and posterior estimates } +\seealso{ +Other plot: +\code{\link{calculate_cohort_mean}()}, +\code{\link{calculate_truncated_means}()}, +\code{\link{plot_cases_by_obs_window}()}, +\code{\link{plot_censor_delay}()}, +\code{\link{plot_cohort_mean}()}, +\code{\link{plot_empirical_delay}()}, +\code{\link{plot_mean_posterior_pred}()}, +\code{\link{plot_recovery}()} +} +\concept{plot} diff --git a/man/primary_censoring_bias_correction.Rd b/man/primary_censoring_bias_correction.Rd index 3681a778a..e4193c7cc 100644 --- a/man/primary_censoring_bias_correction.Rd +++ b/man/primary_censoring_bias_correction.Rd @@ -9,3 +9,16 @@ primary_censoring_bias_correction(draws) \description{ Primary event bias correction } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/reverse_obs_at.Rd b/man/reverse_obs_at.Rd index b25fade5d..4c41f3ebe 100644 --- a/man/reverse_obs_at.Rd +++ b/man/reverse_obs_at.Rd @@ -9,3 +9,13 @@ reverse_obs_at(dt) \description{ For the observation observed at variable reverse the factor ordering } +\seealso{ +Other preprocess: +\code{\link{calculate_censor_delay}()}, +\code{\link{combine_obs}()}, +\code{\link{construct_cases_by_obs_window}()}, +\code{\link{event_to_incidence}()}, +\code{\link{linelist_to_cases}()}, +\code{\link{linelist_to_counts}()} +} +\concept{preprocess} diff --git a/man/sample_epinowcast_model.Rd b/man/sample_epinowcast_model.Rd index a18fa6d52..66da7af39 100644 --- a/man/sample_epinowcast_model.Rd +++ b/man/sample_epinowcast_model.Rd @@ -15,3 +15,16 @@ sample_epinowcast_model( \description{ Sample from the posterior of an epinowcast model with additional diagnositics } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/sample_model.Rd b/man/sample_model.Rd index 8d93cdc51..f7c1c030f 100644 --- a/man/sample_model.Rd +++ b/man/sample_model.Rd @@ -15,3 +15,16 @@ sample_model( \description{ Sample from the posterior of a model with additional diagnositics } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{summarise_draws}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/simulate_double_censored_pmf.Rd b/man/simulate_double_censored_pmf.Rd index b5385b5fb..e73214386 100644 --- a/man/simulate_double_censored_pmf.Rd +++ b/man/simulate_double_censored_pmf.Rd @@ -46,3 +46,11 @@ primary events, secondary events, and delays. \examples{ simulate_double_censored_pmf(0.6, 0.5, 10, 1000) } +\seealso{ +Other simulate: +\code{\link{simulate_exponential_cases}()}, +\code{\link{simulate_gillespie}()}, +\code{\link{simulate_secondary}()}, +\code{\link{simulate_uniform_cases}()} +} +\concept{simulate} diff --git a/man/simulate_exponential_cases.Rd b/man/simulate_exponential_cases.Rd index 4ea74a8da..032831589 100644 --- a/man/simulate_exponential_cases.Rd +++ b/man/simulate_exponential_cases.Rd @@ -26,3 +26,11 @@ survival time. If the rate parameter is 0, then this function defaults to the uniform distribution. } +\seealso{ +Other simulate: +\code{\link{simulate_double_censored_pmf}()}, +\code{\link{simulate_gillespie}()}, +\code{\link{simulate_secondary}()}, +\code{\link{simulate_uniform_cases}()} +} +\concept{simulate} diff --git a/man/simulate_gillespie.Rd b/man/simulate_gillespie.Rd index def8607c5..c06c02414 100644 --- a/man/simulate_gillespie.Rd +++ b/man/simulate_gillespie.Rd @@ -26,3 +26,11 @@ This function simulates cases from an Stochastic SIR model. The user may specify the rate of infection r, the rate of recovery gamma, the initial number of infected cases I0, and the total population size N. } +\seealso{ +Other simulate: +\code{\link{simulate_double_censored_pmf}()}, +\code{\link{simulate_exponential_cases}()}, +\code{\link{simulate_secondary}()}, +\code{\link{simulate_uniform_cases}()} +} +\concept{simulate} diff --git a/man/simulate_secondary.Rd b/man/simulate_secondary.Rd index d9db6a8c1..924db0eee 100644 --- a/man/simulate_secondary.Rd +++ b/man/simulate_secondary.Rd @@ -22,3 +22,11 @@ This function simulates secondary events based on a given delay distribution. The input dataset should have the primary event times in a column named 'ptime'. } +\seealso{ +Other simulate: +\code{\link{simulate_double_censored_pmf}()}, +\code{\link{simulate_exponential_cases}()}, +\code{\link{simulate_gillespie}()}, +\code{\link{simulate_uniform_cases}()} +} +\concept{simulate} diff --git a/man/simulate_uniform_cases.Rd b/man/simulate_uniform_cases.Rd index 0a6c848ba..caa7e134c 100644 --- a/man/simulate_uniform_cases.Rd +++ b/man/simulate_uniform_cases.Rd @@ -20,3 +20,11 @@ event time). This function simulates cases from a uniform distribution, where the primary event times are uniformly distributed between 0 and t. } +\seealso{ +Other simulate: +\code{\link{simulate_double_censored_pmf}()}, +\code{\link{simulate_exponential_cases}()}, +\code{\link{simulate_gillespie}()}, +\code{\link{simulate_secondary}()} +} +\concept{simulate} diff --git a/man/summarise_draws.Rd b/man/summarise_draws.Rd index 43d3dc7a7..47fc2c2a4 100644 --- a/man/summarise_draws.Rd +++ b/man/summarise_draws.Rd @@ -19,3 +19,16 @@ This will be overridden if by is specified.} \description{ Summarise posterior draws } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_variable}()} +} +\concept{postprocess} diff --git a/man/summarise_variable.Rd b/man/summarise_variable.Rd index 0b8acc32a..7a5213e70 100644 --- a/man/summarise_variable.Rd +++ b/man/summarise_variable.Rd @@ -18,3 +18,16 @@ summarise_variable(draws, variable, sf = 6, by = c()) \description{ Summarise a variable } +\seealso{ +Other postprocess: +\code{\link{add_natural_scale_mean_sd}()}, +\code{\link{draws_to_long}()}, +\code{\link{extract_epinowcast_draws}()}, +\code{\link{extract_lognormal_draws}()}, +\code{\link{make_relative_to_truth}()}, +\code{\link{primary_censoring_bias_correction}()}, +\code{\link{sample_epinowcast_model}()}, +\code{\link{sample_model}()}, +\code{\link{summarise_draws}()} +} +\concept{postprocess} diff --git a/man/truncation_adjusted_delay.Rd b/man/truncation_adjusted_delay.Rd deleted file mode 100644 index c7a8dd3e1..000000000 --- a/man/truncation_adjusted_delay.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{truncation_adjusted_delay} -\alias{truncation_adjusted_delay} -\title{Estimate delays adjusted for right truncation} -\usage{ -truncation_adjusted_delay( - formula = brms::bf(delay_daily | trunc(lb = 1, ub = censored_obs_time) ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - ... -) -} -\description{ -Estimate delays adjusted for right truncation -} diff --git a/man/truncation_censoring_adjusted_delay.Rd b/man/truncation_censoring_adjusted_delay.Rd deleted file mode 100644 index 12f035aca..000000000 --- a/man/truncation_censoring_adjusted_delay.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/models.R -\name{truncation_censoring_adjusted_delay} -\alias{truncation_censoring_adjusted_delay} -\title{Estimate delays adjusted for censoring and right truncation} -\usage{ -truncation_censoring_adjusted_delay( - formula = brms::bf(delay_lwr | cens(censored, delay_upr) + trunc(lb = 0.001, ub = - censored_obs_time) ~ 1, sigma ~ 1), - data, - fn = brms::brm, - family = "lognormal", - ... -) -} -\description{ -Estimate delays adjusted for censoring and right truncation -} From d4447b8da1c266f4b3d6e8247289e99522a555f6 Mon Sep 17 00:00:00 2001 From: athowes Date: Mon, 13 May 2024 15:13:53 +0100 Subject: [PATCH 3/3] Remove deprecated models from vignette --- vignettes/epidist.Rmd | 71 ++----------------------------------------- 1 file changed, 3 insertions(+), 68 deletions(-) diff --git a/vignettes/epidist.Rmd b/vignettes/epidist.Rmd index 5cd8d7475..83a50fb22 100644 --- a/vignettes/epidist.Rmd +++ b/vignettes/epidist.Rmd @@ -116,53 +116,7 @@ censor_delay <- calculate_censor_delay(truncated_obs) plot_censor_delay(censor_delay) ``` -### Models - -First fit a naive lognormal model with no adjustment. - -```{r} -naive_fit <- naive_delay(data = truncated_obs, cores = 4, refresh = 0) -``` - -Estimate the delay after filtering out the most recent data as crude adjustement for right truncation. - -```{r} -filtered_fit <- filtered_naive_delay( - data = truncated_obs, cores = 4, refresh = 0 -) -``` - -Adjust for date censoring. - -```{r} -censored_fit <- censoring_adjusted_delay( - data = truncated_obs, cores = 4, refresh = 0 -) -``` - -Adjust for censoring and filter to crudely adjust for right truncation. - -```{r} -filtered_censored_fit <- filtered_censoring_adjusted_delay( - data = truncated_obs, cores = 4, refresh = 0 -) -``` - -Adjust for right truncation. - -```{r} -truncation_fit <- truncation_adjusted_delay( - data = truncated_obs, cores = 4, refresh = 0 -) -``` - -Adjust for right truncation and date censoring. - -```{r} -truncation_censoring_fit <- truncation_censoring_adjusted_delay( - data = truncated_obs, cores = 4, refresh = 0 -) -``` +### Model Adjust for right truncation and date censoring using a latent variable approach. @@ -172,32 +126,13 @@ latent_truncation_censoring_fit <- latent_truncation_censoring_adjusted_delay( ) ``` -Fit a joint model to estimate primary incidence and the delay to reporting secondary incidence (this is a thin wrapper around the `epinowcast` package that is not suggested for real-world usage). - -```{r} -epinowcast_fit <- epinowcast_delay( - data = truncated_obs, parallel_chains = 4, adapt_delta = 0.95, - show_messages = FALSE, refresh = 0, with_epinowcast_output = FALSE -) -epinowcast_draws <- extract_epinowcast_draws(epinowcast_fit) -epinowcast_draws[, model := "Joint incidence and forward delay"] - -``` - -### Summarise model posteriors and compare to known truth +### Summarise model posterior and compare to known truth Combine models into a named list. ```{r} models <- list( - "Naive" = naive_fit, - "Filtered" = filtered_fit, - "Censoring adjusted" = censored_fit, - "Filtered and censoring adjusted" = filtered_censored_fit, - "Truncation adjusted" = truncation_fit, - "Truncation and censoring adjusted" = truncation_censoring_fit, - "Latent variable truncation and censoring adjusted" = - latent_truncation_censoring_fit + "Latent variable truncation and censoring adjusted" = latent_truncation_censoring_fit ) ```