diff --git a/R/model_comparison.R b/R/model_comparison.R index 3c6dd0ff..c2bb29c9 100644 --- a/R/model_comparison.R +++ b/R/model_comparison.R @@ -6,10 +6,10 @@ #' @return rhats table #' @examples #' \dontrun{ -#' data("serodata") -#' data_test <- prepare_serodata(serodata = serodata) -#' model_constant <- run_seromodel(serodata = data_test, -#' foi_model = "constant", +#' 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) #' } diff --git a/R/modelling.R b/R/modelling.R index 8558f109..1da29f19 100644 --- a/R/modelling.R +++ b/R/modelling.R @@ -43,9 +43,9 @@ #' @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{ -#' serodata <- prepare_serodata(serodata) -#' run_seromodel (serodata, -#' foi_model = "constant") +#' serodata <- prepare_serodata(chagas2012) +#' run_seromodel (chagas2012, +#' foi_model = "constant") #' } #' @export run_seromodel <- function(serodata, @@ -114,8 +114,8 @@ run_seromodel <- function(serodata, #' @examples #' \dontrun{ -#' data("serodata") -#' serodata <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_fit <- fit_seromodel(serodata = serodata, #' foi_model = "constant") #' } @@ -255,8 +255,8 @@ fit_seromodel <- function(serodata, #' @return \code{exposure_ages}. An atomic vector with the numeration of the exposition years in serodata #' @examples #' \dontrun{ -#' data("serodata") -#' serodata <- prepare_serodata(serodata = serodata, alpha = 0.05) +#' data(chagas2012) +#' serodata <- prepare_serodata(serodata = chagas2012, alpha = 0.05) #' exposure_ages <- get_exposure_ages(serodata) #' } #' @export @@ -271,8 +271,8 @@ get_exposure_ages <- function(serodata) { #' @return \code{exposure_output}. An atomic matrix containing the expositions for each entry of \code{serodata} by year. #' @examples #' \dontrun{ -#' data("serodata") -#' serodata <- prepare_serodata(serodata = serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(serodata = chagas2012) #' exposure_matrix <- get_exposure_matrix(serodata = serodata) #' } #' @export @@ -313,8 +313,8 @@ get_exposure_matrix <- function(serodata) { #' } #' @examples #' \dontrun{ -#' data("serodata") -#' serodata <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel(serodata = serodata, #' foi_model = "constant") #' extract_seromodel_summary(seromodel_object) @@ -366,7 +366,8 @@ extract_seromodel_summary <- function(seromodel_object) { #' @return \code{prev_final}. The expanded prevalence data. This is used for plotting purposes in the \code{visualization} module. #' @examples #' \dontrun{ -#' serodata <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel(serodata = serodata, #' foi_model = "constant") #' foi <- rstan::extract(seromodel_object$fit, "foi")[[1]] diff --git a/R/serodata.R b/R/serodata.R deleted file mode 100644 index 1404ed4f..00000000 --- a/R/serodata.R +++ /dev/null @@ -1,15 +0,0 @@ -#' Seroprevalence data on serofoi -#' -#' Data from a serological surveys -#' -#' @docType data -#' -#' @usage serodata -#' -#' @format An object of class \code{"cross"}; see \code{\link[qtl]{read.cross}}. -#' -#' @keywords datasets -#' -#' @examples -#' serodata -"serodata" \ No newline at end of file diff --git a/R/seroprevalence_data.R b/R/seroprevalence_data.R index f4168cfe..8c466f26 100644 --- a/R/seroprevalence_data.R +++ b/R/seroprevalence_data.R @@ -30,8 +30,8 @@ #' } #' @examples #'\dontrun{ -#' data("serodata") -#' data_test <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' } #' @export prepare_serodata <- function(serodata = serodata, @@ -91,7 +91,8 @@ prepare_serodata <- function(serodata = serodata, #' @return data set with the binomial confidence intervals #' @examples #'\dontrun{ -#' prepare_bin_data (serodata) +#' data(chagas2012) +#' prepare_bin_data(chagas2012) #' } #' @export prepare_bin_data <- function(serodata) { diff --git a/R/visualisation.R b/R/visualisation.R index 26f7fd81..775b06eb 100644 --- a/R/visualisation.R +++ b/R/visualisation.R @@ -17,9 +17,10 @@ #' @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_test <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( -#' serodata = data_test, +#' serodata = serodata, #' foi_model = "constant", #' n_iters = 1000 #') @@ -52,9 +53,9 @@ plot_seroprev <- function(serodata, #' @return A ggplot object containing the seropositivity-vs-age graph including the data, the fitted model and their corresponding confindence intervals. #' @examples #' \dontrun{ -#' data("serodata") -#' data_test <- prepare_serodata(serodata) -#' seromodel_object <- run_seromodel(serodata = data_test, +#' 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) @@ -133,12 +134,13 @@ plot_seroprev_fitted <- function(seromodel_object, #' @return A ggplot2 object containing the Force-of-infection-vs-time including the corresponding confidence interval. #' @examples #' \dontrun{ -#' data_test <- prepare_serodata(serodata) -#' seromodel_object <- run_seromodel( -#' serodata = data_test, +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) +#' seromodel_object <- run_seromodel( +#' serodata = serodata, #' foi_model = "constant", #' n_iters = 1000 -#' ) +#' ) #' plot_foi(seromodel_object, size_text = 15) #' } #' @export @@ -228,14 +230,14 @@ plot_foi <- function(seromodel_object, #' @return The rhats-convergence plot of the selected model. #' @examples #' \dontrun{ -#' data("serodata") -#' data_test <- prepare_serodata(serodata) +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( -#' serodata = data_test, +#' serodata = serodata, #' foi_model = "constant", #' n_iters = 1000 -#') -#' plot_rhats(seromodel_object, +#' ) +#' plot_rhats(seromodel_object, #' size_text = 15) #' } #' @export @@ -294,12 +296,13 @@ plot_rhats <- function(seromodel_object, #' @return A ggplot object with a vertical arrange containing the seropositivity, force of infection, and convergence plots. #' @examples #' \dontrun{ -#' data_test <- prepare_serodata(serodata) -#' seromodel_object <- run_seromodel( -#' serodata = data_test, -#' foi_model = "constant", -#' n_iters = 1000 -#') +#' data(chagas2012) +#' serodata <- prepare_serodata(chagas2012) +#' seromodel_object <- run_seromodel( +#' serodata = serodata, +#' foi_model = "constant", +#' n_iters = 1000 +#' ) #' plot_seromodel(seromodel_object, size_text = 15) #' } #' @export @@ -378,12 +381,12 @@ plot_seromodel <- function(seromodel_object, #' @return p the plot for the given table #' @examples #' \dontrun{ -#' data_test <- prepare_serodata(serodata) +#' serodata <- prepare_serodata(chagas2012) #' seromodel_object <- run_seromodel( -#' serodata = data_test, -#' foi_model = "constant", -#' n_iters = 1000 -#') +#' serodata = serodata, +#' foi_model = "constant", +#' n_iters = 1000 +#' ) #' info = t(seromodel_object$model_summary) #' plot_info_table (info, size_text = 15) #' } diff --git a/README.Rmd b/README.Rmd index e15802fb..65fc44b1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -15,7 +15,7 @@ knitr::opts_chunk$set( ) ``` -## *serofoi*: force-of-infection from population based serosurveys with age-disagregated data +## *serofoi*: force-of-infection from population based serosurveys with age-disagregated data @@ -47,22 +47,20 @@ remotes::install_github("epiverse-trace/serofoi") ```{r cleaning, include = FALSE, echo = TRUE} library(serofoi) -rownames(serodata) <- NULL - ``` ***serofoi*** provides a minimal serosurvey dataset, `serodata`, that can be used to test out the package. ```{r ex, include = TRUE} -# Load example serodata data included with the package -data("serodata") -head(serodata, 5) +# Load example dataset chagas2012 included with the package +data(chagas2012) +head(chagas2012, 5) ``` The function `prepare_serodata` will prepare the entry data for the use of the modelling module; this function computes the sample size, the years of birth and the binomial confidence interval for each age group in the provided dataset. A visualisation of the prepared seroprevalence data can be obtained using the function plot_seroprev: ```{r data_test, include = TRUE, out.fig.height="30%", out.width="50%", fig.align="center", message=FALSE} -serodata_test <- prepare_serodata(serodata) +serodata_test <- prepare_serodata(chagas2012) plot_seroprev(serodata_test, size_text = 15) ``` diff --git a/README.md b/README.md index 5eef2793..0b6a0862 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -## *serofoi*: force-of-infection from population based serosurveys with age-disagregated data +## *serofoi*: force-of-infection from population based serosurveys with age-disagregated data @@ -48,9 +48,9 @@ remotes::install_github("epiverse-trace/serofoi") can be used to test out the package. ``` r -# Load example serodata data included with the package -data("serodata") -head(serodata, 5) +# Load example dataset chagas2012 included with the package +data(chagas2012) +head(chagas2012, 5) #> survey total counts age_min age_max tsur country test antibody #> 1 COL-035-93 34 0 1 1 2012 COL ELISA IgG anti-T.cruzi #> 2 COL-035-93 25 0 2 2 2012 COL ELISA IgG anti-T.cruzi @@ -66,7 +66,7 @@ in the provided dataset. A visualisation of the prepared seroprevalence data can be obtained using the function plot_seroprev: ``` r -serodata_test <- prepare_serodata(serodata) +serodata_test <- prepare_serodata(chagas2012) plot_seroprev(serodata_test, size_text = 15) ``` @@ -97,10 +97,10 @@ More details on how to use ***serofoi*** can be found in the [online documentation](https://epiverse-trace.github.io/serofoi/) as package vignettes, under [**Get Started**](https://epiverse-trace.github.io/serofoi/articles/serofoi.html), -[**FoI +[**An Introduction to FoI Models**](https://epiverse-trace.github.io/serofoi/articles/foi_models.html) -and [**Use -Cases**](https://epiverse-trace.github.io/serofoi/articles/use_cases.html) +and [**Real-life Use Cases for +serofoi**](https://epiverse-trace.github.io/serofoi/articles/use_cases.html) ## Help diff --git a/data/serodata.RData b/data/serodata.RData deleted file mode 100644 index f9570b14..00000000 Binary files a/data/serodata.RData and /dev/null differ diff --git a/man/extract_seromodel_summary.Rd b/man/extract_seromodel_summary.Rd index cd037799..106b1ca7 100644 --- a/man/extract_seromodel_summary.Rd +++ b/man/extract_seromodel_summary.Rd @@ -35,8 +35,8 @@ corresponding standar deviation. } \examples{ \dontrun{ -data("serodata") -serodata <- prepare_serodata(serodata) +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 67908578..30770ff1 100644 --- a/man/fit_seromodel.Rd +++ b/man/fit_seromodel.Rd @@ -64,8 +64,8 @@ object needs to be compiled by rstan. } \examples{ \dontrun{ -data("serodata") -serodata <- prepare_serodata(serodata) +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 aec51f06..3a1e2ca1 100644 --- a/man/get_exposure_ages.Rd +++ b/man/get_exposure_ages.Rd @@ -18,8 +18,8 @@ The exposition years to the disease for each individual corresponds to the time } \examples{ \dontrun{ -data("serodata") -serodata <- prepare_serodata(serodata = serodata, alpha = 0.05) +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 8b4f1abf..b92816f5 100644 --- a/man/get_exposure_matrix.Rd +++ b/man/get_exposure_matrix.Rd @@ -17,8 +17,8 @@ Function that generates the exposure matrix corresponding to a serological surve } \examples{ \dontrun{ -data("serodata") -serodata <- prepare_serodata(serodata = serodata) +data(chagas2012) +serodata <- prepare_serodata(serodata = chagas2012) exposure_matrix <- get_exposure_matrix(serodata = serodata) } } diff --git a/man/get_prev_expanded.Rd b/man/get_prev_expanded.Rd index a95f4899..2138efa4 100644 --- a/man/get_prev_expanded.Rd +++ b/man/get_prev_expanded.Rd @@ -23,7 +23,8 @@ of the Force-of-Infection \code{foi} for plotting an analysis purposes. } \examples{ \dontrun{ -serodata <- prepare_serodata(serodata) +data(chagas2012) +serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel(serodata = serodata, foi_model = "constant") foi <- rstan::extract(seromodel_object$fit, "foi")[[1]] diff --git a/man/get_table_rhats.Rd b/man/get_table_rhats.Rd index 4aac86a0..7fb2f4b8 100644 --- a/man/get_table_rhats.Rd +++ b/man/get_table_rhats.Rd @@ -18,10 +18,10 @@ This method relies in the function \link[bayesplot]{rhat} to extract the R-hat e } \examples{ \dontrun{ -data("serodata") -data_test <- prepare_serodata(serodata = serodata) -model_constant <- run_seromodel(serodata = data_test, - foi_model = "constant", +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) } diff --git a/man/plot_foi.Rd b/man/plot_foi.Rd index 6e376c70..f9f3a061 100644 --- a/man/plot_foi.Rd +++ b/man/plot_foi.Rd @@ -25,12 +25,13 @@ The x axis corresponds to the decades covered by the survey the y axis to the Fo } \examples{ \dontrun{ - data_test <- prepare_serodata(serodata) - seromodel_object <- run_seromodel( - serodata = data_test, + data(chagas2012) + serodata <- prepare_serodata(chagas2012) + seromodel_object <- run_seromodel( + serodata = serodata, foi_model = "constant", n_iters = 1000 -) + ) plot_foi(seromodel_object, size_text = 15) } } diff --git a/man/plot_info_table.Rd b/man/plot_info_table.Rd index 72ddc003..1ec2cd73 100644 --- a/man/plot_info_table.Rd +++ b/man/plot_info_table.Rd @@ -19,12 +19,12 @@ Function that generates a plot for a given table } \examples{ \dontrun{ - data_test <- prepare_serodata(serodata) + serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( - serodata = data_test, - foi_model = "constant", - n_iters = 1000 -) + serodata = serodata, + foi_model = "constant", + n_iters = 1000 + ) info = t(seromodel_object$model_summary) plot_info_table (info, size_text = 15) } diff --git a/man/plot_rhats.Rd b/man/plot_rhats.Rd index 02b73f00..b1d42253 100644 --- a/man/plot_rhats.Rd +++ b/man/plot_rhats.Rd @@ -21,14 +21,14 @@ All rhats must be smaller than 1 to ensure convergence (for further details chec } \examples{ \dontrun{ -data("serodata") -data_test <- prepare_serodata(serodata) +data(chagas2012) +serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( - serodata = data_test, + serodata = serodata, foi_model = "constant", n_iters = 1000 -) -plot_rhats(seromodel_object, + ) +plot_rhats(seromodel_object, size_text = 15) } } diff --git a/man/plot_seromodel.Rd b/man/plot_seromodel.Rd index 6a36f736..2a2964bd 100644 --- a/man/plot_seromodel.Rd +++ b/man/plot_seromodel.Rd @@ -30,12 +30,13 @@ the Force-of-Infection fit and the R-hat estimates plots. } \examples{ \dontrun{ -data_test <- prepare_serodata(serodata) -seromodel_object <- run_seromodel( - serodata = data_test, - foi_model = "constant", - n_iters = 1000 -) + data(chagas2012) + serodata <- prepare_serodata(chagas2012) + seromodel_object <- run_seromodel( + serodata = serodata, + foi_model = "constant", + n_iters = 1000 + ) plot_seromodel(seromodel_object, size_text = 15) } } diff --git a/man/plot_seroprev.Rd b/man/plot_seroprev.Rd index 8948decb..f61698e8 100644 --- a/man/plot_seroprev.Rd +++ b/man/plot_seroprev.Rd @@ -31,9 +31,10 @@ Function that generates the sero-positivity plot from a raw serological survey d } \examples{ \dontrun{ - data_test <- prepare_serodata(serodata) + data(chagas2012) + serodata <- prepare_serodata(chagas2012) seromodel_object <- run_seromodel( - serodata = data_test, + serodata = serodata, foi_model = "constant", n_iters = 1000 ) diff --git a/man/plot_seroprev_fitted.Rd b/man/plot_seroprev_fitted.Rd index 18740584..a7663518 100644 --- a/man/plot_seroprev_fitted.Rd +++ b/man/plot_seroprev_fitted.Rd @@ -21,9 +21,9 @@ corresponding confidence interval. } \examples{ \dontrun{ -data("serodata") -data_test <- prepare_serodata(serodata) -seromodel_object <- run_seromodel(serodata = data_test, +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) diff --git a/man/prepare_bin_data.Rd b/man/prepare_bin_data.Rd index a2d767a4..bcb324e8 100644 --- a/man/prepare_bin_data.Rd +++ b/man/prepare_bin_data.Rd @@ -38,6 +38,7 @@ of its corresponding seroprevalence grouped by age group. } \examples{ \dontrun{ -prepare_bin_data (serodata) +data(chagas2012) +prepare_bin_data(chagas2012) } } diff --git a/man/prepare_serodata.Rd b/man/prepare_serodata.Rd index 33b4a1de..273e7b32 100644 --- a/man/prepare_serodata.Rd +++ b/man/prepare_serodata.Rd @@ -41,7 +41,7 @@ This function adds the necessary additional variables to the given dataset \code } \examples{ \dontrun{ -data("serodata") -data_test <- prepare_serodata(serodata) +data(chagas2012) +serodata <- prepare_serodata(chagas2012) } } diff --git a/man/run_seromodel.Rd b/man/run_seromodel.Rd index becb135a..a8432187 100644 --- a/man/run_seromodel.Rd +++ b/man/run_seromodel.Rd @@ -67,8 +67,8 @@ This function runs the specified model for the Force-of-Infection \code{foi_mode } \examples{ \dontrun{ -serodata <- prepare_serodata(serodata) -run_seromodel (serodata, - foi_model = "constant") +serodata <- prepare_serodata(chagas2012) +run_seromodel (chagas2012, + foi_model = "constant") } } diff --git a/man/serodata.Rd b/man/serodata.Rd deleted file mode 100644 index a0644814..00000000 --- a/man/serodata.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/serodata.R -\docType{data} -\name{serodata} -\alias{serodata} -\title{Seroprevalence data on serofoi} -\format{ -An object of class \code{"cross"}; see \code{\link[qtl]{read.cross}}. -} -\usage{ -serodata -} -\description{ -Data from a serological surveys -} -\examples{ -serodata -} -\keyword{datasets} diff --git a/tests/testthat/test_modelling.R b/tests/testthat/test_modelling.R index 76494b19..edea5876 100644 --- a/tests/testthat/test_modelling.R +++ b/tests/testthat/test_modelling.R @@ -7,12 +7,11 @@ test_that("individual models", { set.seed(1234) # For reproducibility library(devtools) - library(dplyr) library(vdiffr) #----- Read and prepare data - data("serodata") - data_test <- serodata %>% prepare_serodata(alpha = 0.05) + data(chagas2012) + serodata <- prepare_serodata(chagas2012, alpha = 0.05) data_constant_path <- testthat::test_path("extdata", "prev_expanded_constant.RDS") data_tv_normal_path <- testthat::test_path("extdata", "prev_expanded_tv_normal.RDS") @@ -23,7 +22,7 @@ test_that("individual models", { #----- Test for the constant model model_name <- "constant" - model_object <- run_seromodel(serodata = data_test, + model_object <- run_seromodel(serodata = serodata, foi_model = model_name, n_iters = 1000, print_summary = FALSE) @@ -37,7 +36,7 @@ test_that("individual models", { #----- Test for the tv_normal model model_name <- "tv_normal" - model_object <- run_seromodel(serodata = data_test, + model_object <- run_seromodel(serodata = serodata, foi_model = model_name, n_iters = 1000) @@ -49,7 +48,7 @@ test_that("individual models", { #----- Test for the tv_normal_log model model_name <- "tv_normal_log" - model_object <- run_seromodel(serodata = data_test, + model_object <- run_seromodel(serodata = serodata, foi_model = model_name, n_iters = 1000) diff --git a/vignettes/foi_models.Rmd b/vignettes/foi_models.Rmd index 2c53d6a9..e8c9a2f1 100644 --- a/vignettes/foi_models.Rmd +++ b/vignettes/foi_models.Rmd @@ -18,8 +18,6 @@ knitr::opts_chunk$set( ```{r cleaning, include = FALSE, echo = TRUE} library(serofoi) -rownames(serodata) <- NULL - ``` The current version of ***serofoi*** supports three different models for estimating the *Force-of-Infection (FoI)*, including constant and time-varying trajectories. For fitting the model to the sero-prevalence data we use a suit of bayesian models that include prior and upper prior distributions diff --git a/vignettes/serofoi.Rmd b/vignettes/serofoi.Rmd index 082e86ef..3fe42205 100644 --- a/vignettes/serofoi.Rmd +++ b/vignettes/serofoi.Rmd @@ -60,8 +60,8 @@ The integrated dataset `serodata_test` provides a minimal example of the input o ```{r model_constant, include = TRUE, echo = TRUE, results="hide", errors = FALSE, warning = FALSE, message = FALSE, fig.width=4, fig.asp=1.5, fig.align="center"} library(serofoi) # Loading and preparing data for modelling -data("serodata") -serodata_test <- prepare_serodata(serodata) +data(chagas2012) +serodata_test <- prepare_serodata(chagas2012) # Model implementation model_constant <- run_seromodel(serodata = serodata_test, foi_model = "constant")