From 552b7bcfa2e387e40b96e5c102c963eca110c221 Mon Sep 17 00:00:00 2001 From: "Jaime A. Pavlich-Mariscal" Date: Wed, 6 Sep 2023 14:41:48 -0500 Subject: [PATCH] Fixes #115 --- R/model_comparison.R | 4 +--- R/modelling.R | 20 +++-------------- R/seroprevalence_data.R | 7 ++---- R/visualisation.R | 38 +++++++++----------------------- man/extract_seromodel_summary.Rd | 2 -- man/fit_seromodel.Rd | 2 -- man/get_exposure_ages.Rd | 2 -- man/get_exposure_matrix.Rd | 2 -- man/get_foi_central_estimates.Rd | 3 --- man/get_prev_expanded.Rd | 8 +++---- man/get_table_rhats.Rd | 4 +--- man/plot_foi.Rd | 2 -- man/plot_info_table.Rd | 17 +++++++------- man/plot_rhats.Rd | 2 -- man/plot_seromodel.Rd | 2 -- man/plot_seroprev.Rd | 13 +++-------- man/plot_seroprev_fitted.Rd | 2 -- man/prepare_bin_data.Rd | 5 ++--- man/prepare_serodata.Rd | 2 -- man/run_seromodel.Rd | 5 ++--- 20 files changed, 36 insertions(+), 106 deletions(-) diff --git a/R/model_comparison.R b/R/model_comparison.R index 32825a8c..f9f11671 100644 --- a/R/model_comparison.R +++ b/R/model_comparison.R @@ -5,14 +5,12 @@ #' @param seromodel_object seromodel_object #' @return rhats table #' @examples -#' \dontrun{ #' data(chagas2012) #' data_test <- prepare_serodata(serodata = chagas2012) #' model_constant <- run_seromodel(serodata = data_test, #' foi_model = "constant", #' n_iters = 1500) -#' get_table_rhats(model_object = model_constant) -#' } +#' get_table_rhats(seromodel_object = model_constant) #' @export get_table_rhats <- function(seromodel_object) { rhats <- bayesplot::rhat(seromodel_object$seromodel_fit, "foi") diff --git a/R/modelling.R b/R/modelling.R index 36a25f80..0f59ae23 100644 --- a/R/modelling.R +++ b/R/modelling.R @@ -42,11 +42,10 @@ #' @param print_summary TBD #' @return \code{seromodel_object}. An object containing relevant information about the implementation of the model. For further details refer to \link{fit_seromodel}. #' @examples -#' \dontrun{ +#' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) -#' run_seromodel (chagas2012, +#' run_seromodel (serodata, #' foi_model = "constant") -#' } #' @export run_seromodel <- function(serodata, foi_model = "constant", @@ -114,12 +113,10 @@ run_seromodel <- function(serodata, #' } #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_fit <- fit_seromodel(serodata = serodata, #' foi_model = "constant") -#' } #' #' @export fit_seromodel <- function(serodata, @@ -203,11 +200,9 @@ fit_seromodel <- function(serodata, #' @param serodata A data frame containing the data from a seroprevalence survey. This data frame must contain the year of birth for each individual (birth_year) and the time of the survey (tsur). birth_year can be constructed by means of the \link{prepare_serodata} function. #' @return \code{exposure_ages}. An atomic vector with the numeration of the exposition years in serodata #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(serodata = chagas2012, alpha = 0.05) #' exposure_ages <- get_exposure_ages(serodata) -#' } #' @export get_exposure_ages <- function(serodata) { return(seq_along(min(serodata$birth_year):(serodata$tsur[1] - 1))) @@ -219,11 +214,9 @@ get_exposure_ages <- function(serodata) { #' @param serodata A data frame containing the data from a seroprevalence survey. This data frame must contain the year of birth for each individual (birth_year) and the time of the survey (tsur). birth_year can be constructed by means of the \link{prepare_serodata} function. #' @return \code{exposure_output}. An atomic matrix containing the expositions for each entry of \code{serodata} by year. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(serodata = chagas2012) #' exposure_matrix <- get_exposure_matrix(serodata = serodata) -#' } #' @export get_exposure_matrix <- function(serodata) { age_class <- serodata$age_mean_f @@ -242,14 +235,11 @@ get_exposure_matrix <- function(serodata) { #' generated by means of \link{get_exposure_ages}. #' @return \code{foi_central_estimates}. Central estimates for the fitted forced FoI #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- fit_seromodel(serodata = serodata, #' foi_model = "constant") #' foi_central_estimates <- get_foi_central_estimates(seromodel_object) -#' } -#' #' @export get_foi_central_estimates <- function(seromodel_object) { @@ -301,13 +291,11 @@ get_foi_central_estimates <- function(seromodel_object) { #' \code{converged} \tab convergence \cr \tab \cr #' } #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel(serodata = serodata, #' foi_model = "constant") #' extract_seromodel_summary(seromodel_object) -#' } #' @export extract_seromodel_summary <- function(seromodel_object) { #------- Loo estimates @@ -352,14 +340,12 @@ extract_seromodel_summary <- function(seromodel_object) { #' @param bin_data TBD #' @return \code{prev_final}. The expanded prevalence data. This is used for plotting purposes in the \code{visualization} module. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel(serodata = serodata, #' foi_model = "constant") #' foi <- rstan::extract(seromodel_object$seromodel_fit, "foi")[[1]] -#' get_prev_expanded <- function(foi, serodata) -#' } +#' get_prev_expanded(foi, serodata) #' @export get_prev_expanded <- function(foi, serodata, diff --git a/R/seroprevalence_data.R b/R/seroprevalence_data.R index 8c466f26..05e634df 100644 --- a/R/seroprevalence_data.R +++ b/R/seroprevalence_data.R @@ -29,10 +29,8 @@ #' \code{prev_obs_upper} \tab Upper limit of the confidence interval for the observed prevalence \cr \tab \cr #' } #' @examples -#'\dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) -#' } #' @export prepare_serodata <- function(serodata = serodata, alpha = 0.05, @@ -90,10 +88,9 @@ prepare_serodata <- function(serodata = serodata, #' The last six colums can be added to \code{serodata} by means of the function \code{\link{prepare_serodata}}. #' @return data set with the binomial confidence intervals #' @examples -#'\dontrun{ #' data(chagas2012) -#' prepare_bin_data(chagas2012) -#' } +#' serodata <- prepare_serodata(chagas2012) +#' prepare_bin_data(serodata) #' @export prepare_bin_data <- function(serodata) { serodata$cut_ages <- diff --git a/R/visualisation.R b/R/visualisation.R index 2188a76f..b897f504 100644 --- a/R/visualisation.R +++ b/R/visualisation.R @@ -16,16 +16,9 @@ #' @param size_text Text size use in the theme of the graph returned by the function. #' @return A ggplot object containing the seropositivity-vs-age graph of the raw data of a given seroprevalence survey with its corresponging binomial confidence interval. #' @examples -#' \dontrun{ -#' data(chagas2012) -#' serodata <- prepare_serodata(chagas2012) -#' seromodel_object <- run_seromodel( -#' serodata = serodata, -#' foi_model = "constant", -#' n_iters = 1000 -#') -#' plot_seroprev(seromodel_object, size_text = 15) -#' } +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) +#' plot_seroprev(serodata, size_text = 15) #' @export plot_seroprev <- function(serodata, size_text = 6) { @@ -52,14 +45,12 @@ plot_seroprev <- function(serodata, #' @param size_text Text size of the graph returned by the function. #' @return A ggplot object containing the seropositivity-vs-age graph including the data, the fitted model and their corresponding confindence intervals. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel(serodata = serodata, #' foi_model = "constant", #' n_iters = 1000) #' plot_seroprev_fitted(seromodel_object, size_text = 15) -#' } #' @export plot_seroprev_fitted <- function(seromodel_object, size_text = 6) { @@ -133,7 +124,6 @@ plot_seroprev_fitted <- function(seromodel_object, #' @param foi_sim TBD #' @return A ggplot2 object containing the Force-of-infection-vs-time including the corresponding confidence interval. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( @@ -142,7 +132,6 @@ plot_seroprev_fitted <- function(seromodel_object, #' n_iters = 1000 #' ) #' plot_foi(seromodel_object, size_text = 15) -#' } #' @export plot_foi <- function(seromodel_object, max_lambda = NA, @@ -229,7 +218,6 @@ plot_foi <- function(seromodel_object, #' @param size_text Text size use in the theme of the graph returned by the function. #' @return The rhats-convergence plot of the selected model. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( @@ -239,7 +227,6 @@ plot_foi <- function(seromodel_object, #' ) #' plot_rhats(seromodel_object, #' size_text = 15) -#' } #' @export plot_rhats <- function(seromodel_object, size_text = 25) { @@ -295,7 +282,6 @@ plot_rhats <- function(seromodel_object, #' @param foi_sim TBD #' @return A ggplot object with a vertical arrange containing the seropositivity, force of infection, and convergence plots. #' @examples -#' \dontrun{ #' data(chagas2012) #' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( @@ -304,7 +290,6 @@ plot_rhats <- function(seromodel_object, #' n_iters = 1000 #' ) #' plot_seromodel(seromodel_object, size_text = 15) -#' } #' @export plot_seromodel <- function(seromodel_object, max_lambda = NA, @@ -380,16 +365,15 @@ plot_seromodel <- function(seromodel_object, #' @param size_text Text size of the graph returned by the function #' @return p the plot for the given table #' @examples -#' \dontrun{ -#' serodata <- prepare_serodata(chagas2012) -#' seromodel_object <- run_seromodel( -#' serodata = serodata, -#' foi_model = "constant", -#' n_iters = 1000 -#' ) -#' info = t(seromodel_object$model_summary) +#' serodata <- prepare_serodata(chagas2012) +#' seromodel_object <- run_seromodel( +#' serodata = serodata, +#' foi_model = "constant", +#' n_iters = 1000 +#' ) +#' seromodel_summary = extract_seromodel_summary(seromodel_object) +#' info = t(seromodel_summary) #' plot_info_table (info, size_text = 15) -#' } #' @export plot_info_table <- function(info, size_text) { dato <- data.frame(y = NROW(info):seq_len(1), diff --git a/man/extract_seromodel_summary.Rd b/man/extract_seromodel_summary.Rd index 106b1ca7..00128724 100644 --- a/man/extract_seromodel_summary.Rd +++ b/man/extract_seromodel_summary.Rd @@ -34,11 +34,9 @@ as well as information about the convergence of the model, like the expected log corresponding standar deviation. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel(serodata = serodata, foi_model = "constant") extract_seromodel_summary(seromodel_object) } -} diff --git a/man/fit_seromodel.Rd b/man/fit_seromodel.Rd index 30770ff1..9111a87e 100644 --- a/man/fit_seromodel.Rd +++ b/man/fit_seromodel.Rd @@ -63,11 +63,9 @@ by means of the \link[rstan]{sampling} method. The function determines whether t object needs to be compiled by rstan. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_fit <- fit_seromodel(serodata = serodata, foi_model = "constant") -} } diff --git a/man/get_exposure_ages.Rd b/man/get_exposure_ages.Rd index 3a1e2ca1..6325d084 100644 --- a/man/get_exposure_ages.Rd +++ b/man/get_exposure_ages.Rd @@ -17,9 +17,7 @@ This function generates an atomic vector containing the exposition years corresp The exposition years to the disease for each individual corresponds to the time from birth to the moment of the survey. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(serodata = chagas2012, alpha = 0.05) exposure_ages <- get_exposure_ages(serodata) } -} diff --git a/man/get_exposure_matrix.Rd b/man/get_exposure_matrix.Rd index b92816f5..4c95e9db 100644 --- a/man/get_exposure_matrix.Rd +++ b/man/get_exposure_matrix.Rd @@ -16,9 +16,7 @@ get_exposure_matrix(serodata) Function that generates the exposure matrix corresponding to a serological survey } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(serodata = chagas2012) exposure_matrix <- get_exposure_matrix(serodata = serodata) } -} diff --git a/man/get_foi_central_estimates.Rd b/man/get_foi_central_estimates.Rd index d85285e8..f0d42db6 100644 --- a/man/get_foi_central_estimates.Rd +++ b/man/get_foi_central_estimates.Rd @@ -17,12 +17,9 @@ generated by means of \link{get_exposure_ages}.} Function that generates the central estimates for the fitted forced FoI } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- fit_seromodel(serodata = serodata, foi_model = "constant") foi_central_estimates <- get_foi_central_estimates(seromodel_object) } - -} diff --git a/man/get_prev_expanded.Rd b/man/get_prev_expanded.Rd index 2138efa4..95ceffc1 100644 --- a/man/get_prev_expanded.Rd +++ b/man/get_prev_expanded.Rd @@ -8,7 +8,7 @@ Force-of-Infection fitting} get_prev_expanded(foi, serodata, bin_data = FALSE) } \arguments{ -\item{foi}{Object containing the information of the force of infection. It is obtained from \code{rstan::extract(seromodel_object$fit, "foi", inc_warmup = FALSE)[[1]]}.} +\item{foi}{Object containing the information of the force of infection. It is obtained from \code{rstan::extract(seromodel_object$seromodel, "foi", inc_warmup = FALSE)[[1]]}.} \item{serodata}{A data frame containing the data from a seroprevalence survey. For further details refer to \link{run_seromodel}.} @@ -22,12 +22,10 @@ This function computes the corresponding binomial confidence intervals for the o of the Force-of-Infection \code{foi} for plotting an analysis purposes. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel(serodata = serodata, foi_model = "constant") -foi <- rstan::extract(seromodel_object$fit, "foi")[[1]] -get_prev_expanded <- function(foi, serodata) -} +foi <- rstan::extract(seromodel_object$seromodel_fit, "foi")[[1]] +get_prev_expanded(foi, serodata) } diff --git a/man/get_table_rhats.Rd b/man/get_table_rhats.Rd index 7fb2f4b8..a5a46546 100644 --- a/man/get_table_rhats.Rd +++ b/man/get_table_rhats.Rd @@ -17,12 +17,10 @@ This method relies in the function \link[bayesplot]{rhat} to extract the R-hat e \code{seromodel_object} and returns a table a dataframe with the estimates for each year of birth. } \examples{ -\dontrun{ data(chagas2012) data_test <- prepare_serodata(serodata = chagas2012) model_constant <- run_seromodel(serodata = data_test, foi_model = "constant", n_iters = 1500) -get_table_rhats(model_object = model_constant) -} +get_table_rhats(seromodel_object = model_constant) } diff --git a/man/plot_foi.Rd b/man/plot_foi.Rd index f9f3a061..46a405a0 100644 --- a/man/plot_foi.Rd +++ b/man/plot_foi.Rd @@ -24,7 +24,6 @@ This includes the corresponding binomial confidence interval. The x axis corresponds to the decades covered by the survey the y axis to the Force-of-Infection. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( @@ -34,4 +33,3 @@ The x axis corresponds to the decades covered by the survey the y axis to the Fo ) plot_foi(seromodel_object, size_text = 15) } -} diff --git a/man/plot_info_table.Rd b/man/plot_info_table.Rd index 1ec2cd73..78354adc 100644 --- a/man/plot_info_table.Rd +++ b/man/plot_info_table.Rd @@ -18,14 +18,13 @@ p the plot for the given table Function that generates a plot for a given table } \examples{ -\dontrun{ - serodata <- prepare_serodata(chagas2012) - seromodel_object <- run_seromodel( - serodata = serodata, - foi_model = "constant", - n_iters = 1000 - ) -info = t(seromodel_object$model_summary) +serodata <- prepare_serodata(chagas2012) +seromodel_object <- run_seromodel( + serodata = serodata, + foi_model = "constant", + n_iters = 1000 +) +seromodel_summary = extract_seromodel_summary(seromodel_object) +info = t(seromodel_summary) plot_info_table (info, size_text = 15) } -} diff --git a/man/plot_rhats.Rd b/man/plot_rhats.Rd index b1d42253..53a958dd 100644 --- a/man/plot_rhats.Rd +++ b/man/plot_rhats.Rd @@ -20,7 +20,6 @@ The x axis corresponds to the decades covered by the survey and the y axis to th All rhats must be smaller than 1 to ensure convergence (for further details check \link[bayesplot]{rhat}). } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( @@ -31,4 +30,3 @@ seromodel_object <- run_seromodel( plot_rhats(seromodel_object, size_text = 15) } -} diff --git a/man/plot_seromodel.Rd b/man/plot_seromodel.Rd index 2a2964bd..a701695d 100644 --- a/man/plot_seromodel.Rd +++ b/man/plot_seromodel.Rd @@ -29,7 +29,6 @@ Function that generates a vertical arrange of plots showing a summary of a model the Force-of-Infection fit and the R-hat estimates plots. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( @@ -39,4 +38,3 @@ the Force-of-Infection fit and the R-hat estimates plots. ) plot_seromodel(seromodel_object, size_text = 15) } -} diff --git a/man/plot_seroprev.Rd b/man/plot_seroprev.Rd index f61698e8..1f37a15c 100644 --- a/man/plot_seroprev.Rd +++ b/man/plot_seroprev.Rd @@ -30,14 +30,7 @@ A ggplot object containing the seropositivity-vs-age graph of the raw data of a Function that generates the sero-positivity plot from a raw serological survey dataset } \examples{ -\dontrun{ - data(chagas2012) - serodata <- prepare_serodata(chagas2012) - seromodel_object <- run_seromodel( - serodata = serodata, - foi_model = "constant", - n_iters = 1000 -) -plot_seroprev(seromodel_object, size_text = 15) -} +data(chagas2012) +serodata <- prepare_serodata(chagas2012) +plot_seroprev(serodata, size_text = 15) } diff --git a/man/plot_seroprev_fitted.Rd b/man/plot_seroprev_fitted.Rd index a7663518..eb2a5828 100644 --- a/man/plot_seroprev_fitted.Rd +++ b/man/plot_seroprev_fitted.Rd @@ -20,7 +20,6 @@ as well as the obtained fitting from the model implementation. Age is located on corresponding confidence interval. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel(serodata = serodata, @@ -28,4 +27,3 @@ seromodel_object <- run_seromodel(serodata = serodata, n_iters = 1000) plot_seroprev_fitted(seromodel_object, size_text = 15) } -} diff --git a/man/prepare_bin_data.Rd b/man/prepare_bin_data.Rd index bcb324e8..39e93d0d 100644 --- a/man/prepare_bin_data.Rd +++ b/man/prepare_bin_data.Rd @@ -37,8 +37,7 @@ This function prepapares a given pre-processed serological dataset (see \code{\l of its corresponding seroprevalence grouped by age group. } \examples{ -\dontrun{ data(chagas2012) -prepare_bin_data(chagas2012) -} +serodata <- prepare_serodata(chagas2012) +prepare_bin_data(serodata) } diff --git a/man/prepare_serodata.Rd b/man/prepare_serodata.Rd index 273e7b32..17efc2e9 100644 --- a/man/prepare_serodata.Rd +++ b/man/prepare_serodata.Rd @@ -40,8 +40,6 @@ serodata with additional columns necessary for the analysis. These columns are: This function adds the necessary additional variables to the given dataset \code{serodata} corresponding to a serological survey. } \examples{ -\dontrun{ data(chagas2012) serodata <- prepare_serodata(chagas2012) } -} diff --git a/man/run_seromodel.Rd b/man/run_seromodel.Rd index a8432187..f335bc4d 100644 --- a/man/run_seromodel.Rd +++ b/man/run_seromodel.Rd @@ -66,9 +66,8 @@ This function runs the specified model for the Force-of-Infection \code{foi_mode \code{serodata} as the input data. See \link{fit_seromodel} for further details. } \examples{ -\dontrun{ +data(chagas2012) serodata <- prepare_serodata(chagas2012) -run_seromodel (chagas2012, +run_seromodel (serodata, foi_model = "constant") } -}