From 14a7c86797295c8068c737774eae69d7ea64d594 Mon Sep 17 00:00:00 2001 From: Adam Howes Date: Wed, 17 Jul 2024 22:14:29 +0100 Subject: [PATCH] Remove correct_primary_censoring_bias and call document (#168) --- NAMESPACE | 2 +- R/fitting-and-postprocessing.R | 14 -------------- R/globals.R | 23 +++++++++++++++++++++++ man/add_natural_scale_mean_sd.Rd | 1 - man/correct_primary_censoring_bias.Rd | 25 ------------------------- man/draws_to_long.Rd | 1 - man/extract_lognormal_draws.Rd | 1 - man/make_relative_to_truth.Rd | 1 - man/sample_model.Rd | 1 - man/summarise_draws.Rd | 1 - man/summarise_variable.Rd | 1 - 11 files changed, 24 insertions(+), 47 deletions(-) delete mode 100644 man/correct_primary_censoring_bias.Rd diff --git a/NAMESPACE b/NAMESPACE index c04f42354..d8c3ebd06 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,7 +17,6 @@ export(calculate_cohort_mean) export(calculate_truncated_means) export(combine_obs) export(construct_cases_by_obs_window) -export(correct_primary_censoring_bias) export(draws_to_long) export(drop_zero) export(epidist) @@ -63,6 +62,7 @@ importFrom(checkmate,assert_int) importFrom(checkmate,assert_names) importFrom(checkmate,assert_numeric) importFrom(posterior,as_draws_df) +importFrom(rstan,lookup) importFrom(stats,as.formula) importFrom(stats,ecdf) importFrom(stats,integrate) diff --git a/R/fitting-and-postprocessing.R b/R/fitting-and-postprocessing.R index 0f8333a85..9ee948a24 100644 --- a/R/fitting-and-postprocessing.R +++ b/R/fitting-and-postprocessing.R @@ -112,20 +112,6 @@ extract_lognormal_draws <- function(data, id_vars, from_dt = FALSE) { return(draws[]) } -#' Primary event bias correction -#' -#' @param draws ... -#' @family postprocess -#' @export -correct_primary_censoring_bias <- function(draws) { - draws <- data.table::copy(draws) - draws[, mean := mean - runif(.N, min = 0, max = 1)] - draws[, meanlog := log(mean^2 / sqrt(sd^2 + mean^2))] - draws[, sdlog := sqrt(log(1 + (sd^2 / mean^2)))] - - return(draws[]) -} - #' Convert posterior lognormal samples to long format #' #' @param draws ... diff --git a/R/globals.R b/R/globals.R index b4a8d25ba..88d1e6932 100644 --- a/R/globals.R +++ b/R/globals.R @@ -1,23 +1,30 @@ # Generated by roxyglobals: do not edit by hand utils::globalVariables(c( + ":=", # "error", # "no_at_max_treedepth", # "max_treedepth", # "per_at_max_treedepth", # "run_time", # + ":=", # "meanlog", # "sdlog", # "sd", # + ":=", # "sdlog", # "sdlog_log", # "meanlog", # "id", # + ":=", # "true_value", # "value", # "rel_value", # + ":=", # "value", # + ":=", # "id", # + ".N", # "obs_t", # "obs_at", # "ptime_lwr", # @@ -31,6 +38,7 @@ utils::globalVariables(c( "row_id", # "woverlap", # "row_id", # + ":=", # "ptime_daily", # "ptime", # "ptime_lwr", # @@ -43,12 +51,14 @@ utils::globalVariables(c( "delay_lwr", # "delay_upr", # "obs_at", # + ":=", # "obs_at", # "ptime", # "censored_obs_time", # "ptime_lwr", # "censored", # "stime_upr", # + ":=", # "censored", # "ptime_upr", # "stime_upr", # @@ -56,8 +66,10 @@ utils::globalVariables(c( "censored_obs_time", # "ptime_lwr", # "censored_obs_time", # + ":=", # "delay_lwr", # "delay_daily", # + ":=", # "value", # "rel_value", # "case_type", # @@ -73,15 +85,23 @@ utils::globalVariables(c( "ptime_daily", # "n", # "obs_horizon", # + ".data", # + ":=", # "time", # + ".N", # + ":=", # "primary", # "secondary", # + ":=", # "obs_at", # "stime", # "ptime", # + ":=", # "case_type", # + ":=", # "obs_at", # "stime_daily", # + ":=", # "ptime_delay", # "ptime", # "ptime_daily", # @@ -91,9 +111,12 @@ utils::globalVariables(c( "stime_delay", # "stime", # "stime_daily", # + ".N", # "ptime_daily", # "rlnorm", # + ":=", # "delay", # + ".N", # "stime", # "ptime", # NULL diff --git a/man/add_natural_scale_mean_sd.Rd b/man/add_natural_scale_mean_sd.Rd index 269283932..3e54240d4 100644 --- a/man/add_natural_scale_mean_sd.Rd +++ b/man/add_natural_scale_mean_sd.Rd @@ -14,7 +14,6 @@ Add natural scale summary parameters for a lognormal distribution } \seealso{ Other postprocess: -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{make_relative_to_truth}()}, diff --git a/man/correct_primary_censoring_bias.Rd b/man/correct_primary_censoring_bias.Rd deleted file mode 100644 index 1b167e343..000000000 --- a/man/correct_primary_censoring_bias.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/fitting-and-postprocessing.R -\name{correct_primary_censoring_bias} -\alias{correct_primary_censoring_bias} -\title{Primary event bias correction} -\usage{ -correct_primary_censoring_bias(draws) -} -\arguments{ -\item{draws}{...} -} -\description{ -Primary event bias correction -} -\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{sample_model}()}, -\code{\link{summarise_draws}()}, -\code{\link{summarise_variable}()} -} -\concept{postprocess} diff --git a/man/draws_to_long.Rd b/man/draws_to_long.Rd index 0c64dfdaf..631e5adb6 100644 --- a/man/draws_to_long.Rd +++ b/man/draws_to_long.Rd @@ -15,7 +15,6 @@ Convert posterior lognormal samples to long format \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{make_relative_to_truth}()}, \code{\link{sample_model}()}, diff --git a/man/extract_lognormal_draws.Rd b/man/extract_lognormal_draws.Rd index d154b6abb..7b1a4c69f 100644 --- a/man/extract_lognormal_draws.Rd +++ b/man/extract_lognormal_draws.Rd @@ -19,7 +19,6 @@ Extract posterior samples for a lognormal brms model \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{make_relative_to_truth}()}, \code{\link{sample_model}()}, diff --git a/man/make_relative_to_truth.Rd b/man/make_relative_to_truth.Rd index 99573f12a..446bec6de 100644 --- a/man/make_relative_to_truth.Rd +++ b/man/make_relative_to_truth.Rd @@ -19,7 +19,6 @@ Make posterior lognormal samples relative to true values \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{sample_model}()}, diff --git a/man/sample_model.Rd b/man/sample_model.Rd index fbb6a5e40..22506ef23 100644 --- a/man/sample_model.Rd +++ b/man/sample_model.Rd @@ -29,7 +29,6 @@ Sample from the posterior of a model with additional diagnositics \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{make_relative_to_truth}()}, diff --git a/man/summarise_draws.Rd b/man/summarise_draws.Rd index 617082e01..96f5e5b5e 100644 --- a/man/summarise_draws.Rd +++ b/man/summarise_draws.Rd @@ -21,7 +21,6 @@ Summarise posterior draws \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{make_relative_to_truth}()}, diff --git a/man/summarise_variable.Rd b/man/summarise_variable.Rd index 955897398..048a7cbac 100644 --- a/man/summarise_variable.Rd +++ b/man/summarise_variable.Rd @@ -21,7 +21,6 @@ Summarise a variable \seealso{ Other postprocess: \code{\link{add_natural_scale_mean_sd}()}, -\code{\link{correct_primary_censoring_bias}()}, \code{\link{draws_to_long}()}, \code{\link{extract_lognormal_draws}()}, \code{\link{make_relative_to_truth}()},