Skip to content

Commit

Permalink
Remove serodata from pre-loaded datasets of the package (#107)
Browse files Browse the repository at this point in the history
* remove serodata .Rdata and .Rd files

* remove R/serodata.R

* doc: update functions  documentation replacing  for  in examples

* doc: update serofoi logo

* doc: update README and vignettes
This commit changes the removed preloaded dataset `serodata` for the identical `chagas2012`.

* fix: minor correction to test_modelling
  • Loading branch information
ntorresd authored and jpavlich committed Feb 21, 2024
1 parent 2ca608e commit c5eb2dc
Show file tree
Hide file tree
Showing 20 changed files with 323 additions and 183 deletions.
18 changes: 7 additions & 11 deletions R/model_comparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
#' @inheritParams get_foi_central_estimates
#' @return rhats table
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(serodata = chagas2012)
#' model_constant <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1500
#' )
#' cohort_ages <- get_cohort_ages(serodata)
#' get_table_rhats(
#' seromodel_object = model_constant,
#' cohort_ages = cohort_ages
#' )
#' 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)
#' }
#' @export
get_table_rhats <- function(seromodel_object,
cohort_ages) {
Expand Down
46 changes: 23 additions & 23 deletions R/modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ validate_prepared_serodata <- function(serodata) {
#' the implementation of the model. For further details refer to
#' [fit_seromodel].
#' @examples
#' data(chagas2012)
#' \dontrun{
#' serodata <- prepare_serodata(chagas2012)
#' run_seromodel(
#' serodata,
#' foi_model = "constant"
#' )
#' run_seromodel (chagas2012,
#' foi_model = "constant")
#' }
#' @export
run_seromodel <- function(
serodata,
Expand Down Expand Up @@ -220,12 +219,12 @@ run_seromodel <- function(
#' @return `seromodel_object`. `stanfit` object returned by the function
#' [sampling][rstan::sampling]
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_fit <- fit_seromodel(
#' serodata = serodata,
#' foi_model = "constant"
#' )
#' seromodel_fit <- fit_seromodel(serodata = serodata,
#' foi_model = "constant")
#' }
#'
#' @export
fit_seromodel <- function(
Expand Down Expand Up @@ -317,9 +316,11 @@ fit_seromodel <- function(
#' @return `cohort_ages`. A data.frame containing the age of each cohort
#' corresponding to each birth year
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(serodata = chagas2012, alpha = 0.05)
#' cohort_ages <- get_cohort_ages(serodata = serodata)
#' exposure_ages <- get_exposure_ages(serodata)
#' }
#' @export
get_cohort_ages <- function(serodata) {
birth_year <- (min(serodata$birth_year):serodata$tsur[1])
Expand All @@ -341,6 +342,7 @@ get_cohort_ages <- function(serodata) {
#' @return `exposure_output`. An atomic matrix containing the expositions for
#' each entry of `serodata` by year.
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(serodata = chagas2012)
#' exposure_matrix <- get_exposure_matrix(serodata = serodata)
Expand Down Expand Up @@ -429,15 +431,13 @@ get_foi_central_estimates <- function(seromodel_object,
#' \item{`converged`}{convergence}
#' }
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant"
#' )
#' extract_seromodel_summary(seromodel_object,
#' serodata = serodata
#' )
#' seromodel_object <- run_seromodel(serodata = serodata,
#' foi_model = "constant")
#' extract_seromodel_summary(seromodel_object)
#' }
#' @export
extract_seromodel_summary <- function(seromodel_object,
serodata) {
Expand Down Expand Up @@ -503,14 +503,14 @@ extract_seromodel_summary <- function(seromodel_object,
#' @return `prev_final`. The expanded prevalence data. This is used for plotting
#' purposes in the `visualization` module.
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant"
#' )
#' foi <- rstan::extract(seromodel_object, "foi")[[1]]
#' get_prev_expanded(foi, serodata)
#' seromodel_object <- run_seromodel(serodata = serodata,
#' foi_model = "constant")
#' foi <- rstan::extract(seromodel_object$fit, "foi")[[1]]
#' get_prev_expanded <- function(foi, serodata)
#' }
#' @export
get_prev_expanded <- function(foi,
serodata,
Expand Down
10 changes: 6 additions & 4 deletions R/seroprevalence_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
#' observed prevalence}
#' }
#' @examples
#'\dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' }
#' @export
prepare_serodata <- function(serodata = serodata,
alpha = 0.05) {
Expand Down Expand Up @@ -93,11 +95,11 @@ prepare_serodata <- function(serodata = serodata,
#' @inheritParams run_seromodel
#' @return data set with the binomial confidence intervals
#' @examples
#'\dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' prepare_bin_data(serodata)
#' @keywords internal
#' @noRd
#' prepare_bin_data(chagas2012)
#' }
#' @export
prepare_bin_data <- function(serodata) {
if (!any(colnames(serodata) == "age_mean_f")) {
serodata <- serodata %>%
Expand Down
109 changes: 53 additions & 56 deletions R/visualisation.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
#' data of a given seroprevalence survey with its corresponding binomial
#' confidence interval.
#' @examples
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' plot_seroprev(serodata, size_text = 15)
#' \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)
#' }
#' @export
plot_seroprev <- function(serodata,
size_text = 6) {
Expand Down Expand Up @@ -48,17 +55,14 @@ plot_seroprev <- function(serodata,
#' @return A ggplot object containing the seropositivity-vs-age graph including
#' the data, the fitted model and their corresponding confidence intervals.
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1000
#' )
#' plot_seroprev_fitted(seromodel_object,
#' serodata = serodata,
#' size_text = 15
#' )
#' 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,
serodata,
Expand Down Expand Up @@ -148,19 +152,16 @@ plot_seroprev_fitted <- function(seromodel_object,
#' @return A ggplot2 object containing the Force-of-infection-vs-time including
#' the corresponding confidence interval.
#' @examples
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1000
#' )
#' cohort_ages <- get_cohort_ages(serodata)
#' plot_foi(
#' seromodel_object = seromodel_object,
#' cohort_ages = cohort_ages,
#' size_text = 15
#' )
#' \dontrun{
#' 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
plot_foi <- function(seromodel_object,
cohort_ages,
Expand Down Expand Up @@ -266,18 +267,17 @@ plot_foi <- function(seromodel_object,
#' function.
#' @return The rhats-convergence plot of the selected model.
#' @examples
#' \dontrun{
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1000
#' )
#' cohort_ages <- get_cohort_ages(serodata = serodata)
#' serodata = serodata,
#' foi_model = "constant",
#' n_iters = 1000
#' )
#' plot_rhats(seromodel_object,
#' cohort_ages = cohort_ages,
#' size_text = 15
#' )
#' size_text = 15)
#' }
#' @export
plot_rhats <- function(seromodel_object,
cohort_ages,
Expand Down Expand Up @@ -344,17 +344,16 @@ plot_rhats <- function(seromodel_object,
#' @return A ggplot object with a vertical arrange containing the
#' seropositivity, force of infection, and convergence plots.
#' @examples
#' data(chagas2012)
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1000
#' )
#' plot_seromodel(seromodel_object,
#' serodata = serodata,
#' size_text = 15
#' )
#' \dontrun{
#' 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
plot_seromodel <- function(seromodel_object,
serodata,
Expand Down Expand Up @@ -451,18 +450,16 @@ 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
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' iter = 1000
#' )
#' seromodel_summary <- extract_seromodel_summary(
#' seromodel_object = seromodel_object,
#' serodata = serodata
#' )
#' info <- t(seromodel_summary)
#' plot_info_table(info, size_text = 15)
#' \dontrun{
#' serodata <- prepare_serodata(chagas2012)
#' seromodel_object <- run_seromodel(
#' serodata = serodata,
#' foi_model = "constant",
#' n_iters = 1000
#' )
#' info = t(seromodel_object$model_summary)
#' plot_info_table (info, size_text = 15)
#' }
#' @export
plot_info_table <- function(info, size_text) {
dato <- data.frame(
Expand Down
12 changes: 5 additions & 7 deletions man/extract_seromodel_summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/fit_seromodel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions man/get_exposure_ages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/get_exposure_matrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c5eb2dc

Please sign in to comment.