From a178a1549999a7f2f292c70e6f775d5f6afee555 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Thu, 23 May 2024 10:14:32 -0700 Subject: [PATCH 01/33] automated spell check with `spelling` package --- DESCRIPTION | 3 +- inst/WORDLIST | 104 ++++++++++++++++---------------- man/plot_curve_params_one_ab.Rd | 32 +++++++--- tests/spelling.R | 3 + 4 files changed, 80 insertions(+), 62 deletions(-) create mode 100644 tests/spelling.R diff --git a/DESCRIPTION b/DESCRIPTION index 4a02fb1b..6aeb952c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,7 +41,8 @@ Suggests: readr, bookdown, ggbeeswarm, - DT + DT, + spelling LazyData: true Encoding: UTF-8 URL: https://github.com/UCD-SERG/serocalculator, https://ucd-serg.github.io/serocalculator/ diff --git a/inst/WORDLIST b/inst/WORDLIST index b90d28ff..9d8bfcc4 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,134 +1,132 @@ -Aga AKU -al +Aga Ang Anik BMC Bonačić Bordetella +CMD Campylobacter -campylobacteriosis Ceper Chiang -CMD De -de -der -devtools -df Dhulikhel Diekmann -doi Duynhoven Eijkeren -epidem -et -Falkenhorst FIC +Falkenhorst Fogarty Friesema -fx Gageldonk Graaf Gras Grolemund Hassen Heijden -hemolysin Hessians HlyE IgA IgG IgM -isos -isotype -isotypes Jernberg -jinf -jitter Juba Juma -Kamenskaya -kDa KGH +Kamenskaya Kretzschmar Krogfelt Kuusi Linneberg Marinović -mc -mcmc Melker Mertens -modelled Molbak Monge Mughini Muktadir -multicohort Munira -Nadu NIAID NLL -nr -Orientia +Nadu OSF -param -params -Pebody +Orientia PLoS -pmed +Pebody Polina +RStudio Rai -recombinant Roord -RStudio Rtools Rumunu +SErologic Sadkowska Saha Saiful Sajib Sarkar -savePath Schellekens Seidman Senjuti Sero +Seroincidence +Serological +Simonsen +Sira +Sium +Strid +Syed +TW +Todys +Valk +Vellore +Versteegh +Wetering +Wiens +Zota +al +behaviour +campylobacteriosis +de +der +devtools +doi +epidem +et +fx +hemolysin +isos +isotype +isotypes +jinf +jitter +kDa +mc +mcmc +modelled +multicohort +nr +param +params +pmed +recombinant +savePath seroconversion seroconversions seroepidemiology -Seroincidence seroincidence seroincidences -SErologic serologic -Serological serological seroresponse seroresponses serosurvey serosurveys -Simonsen -Sira -Sium smp smpl -Strid subfigures -Syed -tbl tibble titers -Todys tsutsugamushi -TW unstratified -Valk varepsilon -Vellore -Versteegh -Wetering -Wiens -Zota - diff --git a/man/plot_curve_params_one_ab.Rd b/man/plot_curve_params_one_ab.Rd index 868cb5f3..e5739f2d 100644 --- a/man/plot_curve_params_one_ab.Rd +++ b/man/plot_curve_params_one_ab.Rd @@ -48,14 +48,30 @@ plot_curve_params_one_ab( at the top level of the plot. You must supply \code{mapping} if there is no plot mapping.} \item{\code{data}}{Ignored by \code{stat_function()}, do not use.} - \item{\code{stat}}{The statistical transformation to use on the data for this -layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the -stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than -\code{"stat_count"})} - \item{\code{position}}{Position adjustment, either as a string naming the adjustment -(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a -position adjustment function. Use the latter if you need to change the -settings of the adjustment.} + \item{\code{stat}}{The statistical transformation to use on the data for this layer. +When using a \verb{geom_*()} function to construct a layer, the \code{stat} +argument can be used the override the default coupling between geoms and +stats. The \code{stat} argument accepts the following: +\itemize{ +\item A \code{Stat} ggproto subclass, for example \code{StatCount}. +\item A string naming the stat. To give the stat as a string, strip the +function name of the \code{stat_} prefix. For example, to use \code{stat_count()}, +give the stat as \code{"count"}. +\item For more information and other ways to specify the stat, see the +\link[ggplot2:layer_stats]{layer stat} documentation. +}} + \item{\code{position}}{A position adjustment to use on the data for this layer. This +can be used in various ways, including to prevent overplotting and +improving the display. The \code{position} argument accepts the following: +\itemize{ +\item The result of calling a position function, such as \code{position_jitter()}. +This method allows for passing extra arguments to the position. +\item A string naming the position adjustment. To give the position as a +string, strip the function name of the \code{position_} prefix. For example, +to use \code{position_jitter()}, give the position as \code{"jitter"}. +\item For more information and other ways to specify the position, see the +\link[ggplot2:layer_positions]{layer position} documentation. +}} \item{\code{na.rm}}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} \item{\code{show.legend}}{logical. Should this layer be included in the legends? diff --git a/tests/spelling.R b/tests/spelling.R new file mode 100644 index 00000000..6713838f --- /dev/null +++ b/tests/spelling.R @@ -0,0 +1,3 @@ +if(requireNamespace('spelling', quietly = TRUE)) + spelling::spell_check_test(vignettes = TRUE, error = FALSE, + skip_on_cran = TRUE) From 238a66f9f093fc1f42031e305b8974592bb32c44 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 30 May 2024 08:39:27 +0300 Subject: [PATCH 02/33] add groupby --- R/summary.pop_data.R | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index b602dbb9..2f176377 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -4,6 +4,7 @@ #' This function is a `summary()` method for `pop_data` objects #' #' @param object a `pop_data` object +#' @param strata a [character()] providing the grouping column #' @param ... unused #' #' @returns a list containing two summary tables: one of `age` and one of `value`, stratified by `antigen_iso` @@ -18,15 +19,23 @@ summary.pop_data <- function(object, ...) { ages <- object %>% - distinct(.data$id, .data$age) + distinct(.data$id, .data$age, .data[[strata]]) cat("\nn =", nrow(ages), "\n") cat("\nDistribution of age: \n\n") age_summary <- ages %>% - pull("age") %>% - summary() %>% + select(age, all_of(strata)) %>% + group_by(across(all_of(strata))) %>% + summarise( + age_min = min(age), + age_first_quartile = quantile(age, 0.25), + age_median = median(age), + age_mean = mean(age), + age_third_quartile = quantile(age, 0.75), + age_max = max(age) + ) %>% print() cat("\nDistributions of antigen-isotype measurements:\n\n") From 3daf5767e28cb2c491b8a17067bc0d2ea44e6649 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 30 May 2024 23:01:50 +0300 Subject: [PATCH 03/33] change age column referencing' --- R/summary.pop_data.R | 58 +++++++++++++++++++++++++++++------------ man/summary.pop_data.Rd | 7 ++--- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index 2f176377..ea8554d6 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -13,28 +13,39 @@ #' library(dplyr) #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") +#' summary(xs_data, strata = "Country") #' -#' summary(xs_data) -#' -summary.pop_data <- function(object, ...) { +summary.pop_data <- function(object, strata = "Country", ...) { + # get relevant columns from object + age_column <- object %>% get_age_var() + value_column <- object %>% get_value_var() + id_column <- object %>% get_id_var() + ages <- object %>% - distinct(.data$id, .data$age, .data[[strata]]) + distinct( + .data[[age_column]], + .data[[id_column]], + .data[[strata]] + ) cat("\nn =", nrow(ages), "\n") cat("\nDistribution of age: \n\n") age_summary <- ages %>% - select(age, all_of(strata)) %>% + select( + age_column, + all_of(strata) + ) %>% group_by(across(all_of(strata))) %>% summarise( - age_min = min(age), - age_first_quartile = quantile(age, 0.25), - age_median = median(age), - age_mean = mean(age), - age_third_quartile = quantile(age, 0.75), - age_max = max(age) + age_min = min(.data[[age_column]]), + age_first_quartile = quantile(.data[[age_column]], 0.25), + age_median = median(.data[[age_column]]), + age_mean = mean(.data[[age_column]]), + age_third_quartile = quantile(.data[[age_column]], 0.75), + age_max = max(.data[[age_column]]) ) %>% print() @@ -44,12 +55,25 @@ summary.pop_data <- function(object, ...) { object %>% dplyr::summarize( .by = .data$antigen_iso, - Min = object %>% get_value() %>% min(na.rm = TRUE), - `1st Qu.` = object %>% get_value() %>% quantile(.25, na.rm = TRUE), - Median = object %>% get_value() %>% median(), - `3rd Qu.` = object %>% get_value() %>% quantile(.75, na.rm = TRUE), - Max = object %>% get_value() %>% max(na.rm = TRUE), - `# NAs` = object %>% get_value() %>% is.na() %>% sum() + Min = object %>% + get_value() %>% + min(na.rm = TRUE), + `1st Qu.` = object %>% + get_value() %>% + quantile(.25, na.rm = TRUE), + Median = object %>% + get_value() %>% + median(), + `3rd Qu.` = object %>% + get_value() %>% + quantile(.75, na.rm = TRUE), + Max = object %>% + get_value() %>% + max(na.rm = TRUE), + `# NAs` = object %>% + get_value() %>% + is.na() %>% + sum() ) %>% as.data.frame() %>% print() diff --git a/man/summary.pop_data.Rd b/man/summary.pop_data.Rd index 1a36d356..a3b56392 100644 --- a/man/summary.pop_data.Rd +++ b/man/summary.pop_data.Rd @@ -4,11 +4,13 @@ \alias{summary.pop_data} \title{Summarize a cross-sectional antibody survey data set} \usage{ -\method{summary}{pop_data}(object, ...) +\method{summary}{pop_data}(object, strata = "Country", ...) } \arguments{ \item{object}{a \code{pop_data} object} +\item{strata}{a \code{\link[=character]{character()}} providing the grouping column} + \item{...}{unused} } \value{ @@ -21,7 +23,6 @@ This function is a \code{summary()} method for \code{pop_data} objects library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") - -summary(xs_data) +summary(xs_data, strata = "Country") } From a509cbfa49f9a28134deef2fdbb819ee7d227c80 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 30 May 2024 23:25:27 +0300 Subject: [PATCH 04/33] change country option to smaller letter for vignette --- vignettes/articles/scrubTyphus_example.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/articles/scrubTyphus_example.Rmd b/vignettes/articles/scrubTyphus_example.Rmd index 19dd2ec2..704f91b8 100644 --- a/vignettes/articles/scrubTyphus_example.Rmd +++ b/vignettes/articles/scrubTyphus_example.Rmd @@ -113,7 +113,7 @@ xs_data %>% check_pop_data() We can compute numerical summaries of our cross-sectional antibody data with a `summary()` method for `pop_data` objects: ```{r} -xs_data %>% summary() +xs_data %>% summary(strata = "country") ``` From 11b217b57d04def223a01208630702d7baee0856 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 31 May 2024 08:34:43 +0300 Subject: [PATCH 05/33] set strata to NULL --- R/summary.pop_data.R | 170 ++++++++++++++++++++++++++-------------- man/summary.pop_data.Rd | 2 +- 2 files changed, 113 insertions(+), 59 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index ea8554d6..9a8c8a65 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -15,74 +15,128 @@ #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' summary(xs_data, strata = "Country") #' -summary.pop_data <- function(object, strata = "Country", ...) { +summary.pop_data <- function(object, strata = NULL, ...) { # get relevant columns from object age_column <- object %>% get_age_var() value_column <- object %>% get_value_var() id_column <- object %>% get_id_var() - ages <- - object %>% - distinct( - .data[[age_column]], - .data[[id_column]], - .data[[strata]] + if (is.null(strata)) { + ages <- + object %>% + distinct( + .data[[age_column]], + .data[[id_column]] + ) + + age_summary <- + ages %>% + pull(age_column) %>% + summary() %>% + print() + + cat("\nn =", nrow(ages), "\n") + + cat("\nDistribution of age: \n\n") + + ab_summary <- + object %>% + dplyr::summarize( + .by = .data$antigen_iso, + Min = object %>% + get_value() %>% + min(na.rm = TRUE), + `1st Qu.` = object %>% + get_value() %>% + quantile(.25, na.rm = TRUE), + Median = object %>% + get_value() %>% + median(), + `3rd Qu.` = object %>% + get_value() %>% + quantile(.75, na.rm = TRUE), + Max = object %>% + get_value() %>% + max(na.rm = TRUE), + `# NAs` = object %>% + get_value() %>% + is.na() %>% + sum() + ) %>% + as.data.frame() %>% + print() + + to_return <- list( + n = nrow(ages), + age_summary = age_summary, + ab_summary = ab_summary ) - cat("\nn =", nrow(ages), "\n") + return(invisible(to_return)) + } else { + ages <- + object %>% + distinct( + .data[[age_column]], + .data[[id_column]], + .data[[strata]] + ) + + cat("\nn =", nrow(ages), "\n") - cat("\nDistribution of age: \n\n") - age_summary <- - ages %>% - select( - age_column, - all_of(strata) - ) %>% - group_by(across(all_of(strata))) %>% - summarise( - age_min = min(.data[[age_column]]), - age_first_quartile = quantile(.data[[age_column]], 0.25), - age_median = median(.data[[age_column]]), - age_mean = mean(.data[[age_column]]), - age_third_quartile = quantile(.data[[age_column]], 0.75), - age_max = max(.data[[age_column]]) - ) %>% - print() + cat("\nDistribution of age: \n\n") + age_summary <- + ages %>% + select( + all_of(age_column), + all_of(strata) + ) %>% + summarise( + age_min = min(.data[[age_column]]), + age_first_quartile = quantile(.data[[age_column]], 0.25), + age_median = median(.data[[age_column]]), + age_mean = mean(.data[[age_column]]), + age_third_quartile = quantile(.data[[age_column]], 0.75), + age_max = max(.data[[age_column]]), + .by = strata + ) %>% + print() - cat("\nDistributions of antigen-isotype measurements:\n\n") + cat("\nDistributions of antigen-isotype measurements:\n\n") - ab_summary <- - object %>% - dplyr::summarize( - .by = .data$antigen_iso, - Min = object %>% - get_value() %>% - min(na.rm = TRUE), - `1st Qu.` = object %>% - get_value() %>% - quantile(.25, na.rm = TRUE), - Median = object %>% - get_value() %>% - median(), - `3rd Qu.` = object %>% - get_value() %>% - quantile(.75, na.rm = TRUE), - Max = object %>% - get_value() %>% - max(na.rm = TRUE), - `# NAs` = object %>% - get_value() %>% - is.na() %>% - sum() - ) %>% - as.data.frame() %>% - print() + ab_summary <- + object %>% + dplyr::summarize( + .by = .data$antigen_iso, + Min = object %>% + get_value() %>% + min(na.rm = TRUE), + `1st Qu.` = object %>% + get_value() %>% + quantile(.25, na.rm = TRUE), + Median = object %>% + get_value() %>% + median(), + `3rd Qu.` = object %>% + get_value() %>% + quantile(.75, na.rm = TRUE), + Max = object %>% + get_value() %>% + max(na.rm = TRUE), + `# NAs` = object %>% + get_value() %>% + is.na() %>% + sum() + ) %>% + as.data.frame() %>% + print() - to_return <- list( - n = nrow(ages), - age_summary = age_summary, - ab_summary = ab_summary - ) + to_return <- list( + n = nrow(ages), + age_summary = age_summary, + ab_summary = ab_summary + ) - return(invisible(to_return)) + return(invisible(to_return)) + } } diff --git a/man/summary.pop_data.Rd b/man/summary.pop_data.Rd index a3b56392..b7b59276 100644 --- a/man/summary.pop_data.Rd +++ b/man/summary.pop_data.Rd @@ -4,7 +4,7 @@ \alias{summary.pop_data} \title{Summarize a cross-sectional antibody survey data set} \usage{ -\method{summary}{pop_data}(object, strata = "Country", ...) +\method{summary}{pop_data}(object, strata = NULL, ...) } \arguments{ \item{object}{a \code{pop_data} object} From ef22922550a064de6c4e30a15c1f480106d137bc Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Mon, 3 Jun 2024 23:07:42 +0300 Subject: [PATCH 06/33] correct workflow of summary --- R/summary.pop_data.R | 106 ++++++++++++------------- man/plot_curve_params_one_ab.Rd | 32 ++------ tests/testthat/test-summary.pop_data.R | 92 +++++++++++++++++++++ 3 files changed, 150 insertions(+), 80 deletions(-) create mode 100644 tests/testthat/test-summary.pop_data.R diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index 9a8c8a65..f2063911 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -21,28 +21,59 @@ summary.pop_data <- function(object, strata = NULL, ...) { value_column <- object %>% get_value_var() id_column <- object %>% get_id_var() - if (is.null(strata)) { + if (!is.null(strata)) { ages <- object %>% distinct( .data[[age_column]], - .data[[id_column]] + .data[[id_column]], + .data[[strata]] ) age_summary <- ages %>% - pull(age_column) %>% - summary() %>% + select( + all_of(age_column), + all_of(strata) + ) %>% + summarise( + age_min = min(.data[[age_column]]), + age_first_quartile = quantile(.data[[age_column]], 0.25), + age_median = median(.data[[age_column]]), + age_mean = mean(.data[[age_column]]), + age_third_quartile = quantile(.data[[age_column]], 0.75), + age_max = max(.data[[age_column]]), + .by = strata + ) %>% + print() + } else { + ages <- object %>% + distinct( + .data[[age_column]], + .data[[id_column]] + ) + + age_summary <- ages %>% + select(all_of(age_column)) %>% + summarise( + age_min = min(.data[[age_column]]), + age_first_quartile = quantile(.data[[age_column]], 0.25), + age_median = median(.data[[age_column]]), + age_mean = mean(.data[[age_column]]), + age_third_quartile = quantile(.data[[age_column]], 0.75), + age_max = max(.data[[age_column]]) + ) %>% print() + } - cat("\nn =", nrow(ages), "\n") + cat("\nn =", nrow(ages), "\n") - cat("\nDistribution of age: \n\n") + cat("\nDistribution of age: \n\n") - ab_summary <- - object %>% + ab_summary <- if (!is.null(strata)) { + object %>% dplyr::summarize( - .by = .data$antigen_iso, + .by = c(.data$antigen_iso, .data[[strata]]), Min = object %>% get_value() %>% min(na.rm = TRUE), @@ -65,47 +96,8 @@ summary.pop_data <- function(object, strata = NULL, ...) { ) %>% as.data.frame() %>% print() - - to_return <- list( - n = nrow(ages), - age_summary = age_summary, - ab_summary = ab_summary - ) - - return(invisible(to_return)) } else { - ages <- - object %>% - distinct( - .data[[age_column]], - .data[[id_column]], - .data[[strata]] - ) - - cat("\nn =", nrow(ages), "\n") - - cat("\nDistribution of age: \n\n") - age_summary <- - ages %>% - select( - all_of(age_column), - all_of(strata) - ) %>% - summarise( - age_min = min(.data[[age_column]]), - age_first_quartile = quantile(.data[[age_column]], 0.25), - age_median = median(.data[[age_column]]), - age_mean = mean(.data[[age_column]]), - age_third_quartile = quantile(.data[[age_column]], 0.75), - age_max = max(.data[[age_column]]), - .by = strata - ) %>% - print() - - cat("\nDistributions of antigen-isotype measurements:\n\n") - - ab_summary <- - object %>% + object %>% dplyr::summarize( .by = .data$antigen_iso, Min = object %>% @@ -130,13 +122,15 @@ summary.pop_data <- function(object, strata = NULL, ...) { ) %>% as.data.frame() %>% print() + } - to_return <- list( - n = nrow(ages), - age_summary = age_summary, - ab_summary = ab_summary - ) - return(invisible(to_return)) - } + + to_return <- list( + n = nrow(ages), + age_summary = age_summary, + ab_summary = ab_summary + ) + + return(invisible(to_return)) } diff --git a/man/plot_curve_params_one_ab.Rd b/man/plot_curve_params_one_ab.Rd index e5739f2d..868cb5f3 100644 --- a/man/plot_curve_params_one_ab.Rd +++ b/man/plot_curve_params_one_ab.Rd @@ -48,30 +48,14 @@ plot_curve_params_one_ab( at the top level of the plot. You must supply \code{mapping} if there is no plot mapping.} \item{\code{data}}{Ignored by \code{stat_function()}, do not use.} - \item{\code{stat}}{The statistical transformation to use on the data for this layer. -When using a \verb{geom_*()} function to construct a layer, the \code{stat} -argument can be used the override the default coupling between geoms and -stats. The \code{stat} argument accepts the following: -\itemize{ -\item A \code{Stat} ggproto subclass, for example \code{StatCount}. -\item A string naming the stat. To give the stat as a string, strip the -function name of the \code{stat_} prefix. For example, to use \code{stat_count()}, -give the stat as \code{"count"}. -\item For more information and other ways to specify the stat, see the -\link[ggplot2:layer_stats]{layer stat} documentation. -}} - \item{\code{position}}{A position adjustment to use on the data for this layer. This -can be used in various ways, including to prevent overplotting and -improving the display. The \code{position} argument accepts the following: -\itemize{ -\item The result of calling a position function, such as \code{position_jitter()}. -This method allows for passing extra arguments to the position. -\item A string naming the position adjustment. To give the position as a -string, strip the function name of the \code{position_} prefix. For example, -to use \code{position_jitter()}, give the position as \code{"jitter"}. -\item For more information and other ways to specify the position, see the -\link[ggplot2:layer_positions]{layer position} documentation. -}} + \item{\code{stat}}{The statistical transformation to use on the data for this +layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the +stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than +\code{"stat_count"})} + \item{\code{position}}{Position adjustment, either as a string naming the adjustment +(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a +position adjustment function. Use the latter if you need to change the +settings of the adjustment.} \item{\code{na.rm}}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} \item{\code{show.legend}}{logical. Should this layer be included in the legends? diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R new file mode 100644 index 00000000..982e4a1b --- /dev/null +++ b/tests/testthat/test-summary.pop_data.R @@ -0,0 +1,92 @@ +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) + +unstratified_summary <- xs_data %>% + summary() %>% + magrittr::extract2("age_summary") + +test_that("`summary.pop_data()` produces same results when stratified", { + min_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_min) %>% + min() + + expect_equal(object = unstratified_summary %>% pull(age_min), expected = min_country) +}) + +test_that("`summary.pop_data()` produces same results when stratified", { + first_quartile_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_first_quartile) %>% + mean() + + expect_equal( + unstratified_summary %>% pull(age_first_quartile) %>% as.numeric(), + first_quartile_country, + tolerance = 0.5 + ) +}) + +test_that("`summary.pop_data()` produces same results when stratified", { + median_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_median) %>% + mean() + + expect_equal( + unstratified_summary %>% pull(age_median) %>% as.numeric(), + median_country, + tolerance = 0.5 + ) +}) + +test_that("`summary.pop_data()` produces same results when stratified", { + mean_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_mean) %>% + mean() + + expect_equal( + unstratified_summary %>% pull(age_mean) %>% as.numeric(), + mean_country, + tolerance = 0.5 + ) +}) + +test_that("`summary.pop_data()` produces same results when stratified", { + third_quartile_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_mean) %>% + mean() + + expect_equal( + unstratified_summary %>% pull(age_third_quartile) %>% as.numeric(), + third_quartile_country, + tolerance = 0.5 + ) +}) + +test_that("`summary.pop_data()` produces same results when stratified", { + max_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") %>% + pull(age_max) %>% + mean() + + expect_equal( + unstratified_summary %>% pull(age_max), + max_country, + tolerance = 0.5 + ) +}) + From a182519c707391fd4305f10b54e855899f3a57c0 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Tue, 4 Jun 2024 09:30:33 +0300 Subject: [PATCH 07/33] remove redundant code --- tests/testthat/test-summary.pop_data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 982e4a1b..3ef64f0e 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -42,7 +42,7 @@ test_that("`summary.pop_data()` produces same results when stratified", { mean() expect_equal( - unstratified_summary %>% pull(age_median) %>% as.numeric(), + unstratified_summary %>% pull(age_median), median_country, tolerance = 0.5 ) @@ -56,7 +56,7 @@ test_that("`summary.pop_data()` produces same results when stratified", { mean() expect_equal( - unstratified_summary %>% pull(age_mean) %>% as.numeric(), + unstratified_summary %>% pull(age_mean), mean_country, tolerance = 0.5 ) From 9f8de011347f1dcb0ebc0c330e7ae077979662f5 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Wed, 5 Jun 2024 10:09:28 +0300 Subject: [PATCH 08/33] reduce redundancy --- R/summary.pop_data.R | 143 ++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 96 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index f2063911..d86cc323 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -21,110 +21,61 @@ summary.pop_data <- function(object, strata = NULL, ...) { value_column <- object %>% get_value_var() id_column <- object %>% get_id_var() - if (!is.null(strata)) { - ages <- - object %>% - distinct( - .data[[age_column]], - .data[[id_column]], - .data[[strata]] - ) + # create a list of the columns + cols <- c(age_column, id_column, strata) - age_summary <- - ages %>% - select( - all_of(age_column), - all_of(strata) - ) %>% - summarise( - age_min = min(.data[[age_column]]), - age_first_quartile = quantile(.data[[age_column]], 0.25), - age_median = median(.data[[age_column]]), - age_mean = mean(.data[[age_column]]), - age_third_quartile = quantile(.data[[age_column]], 0.75), - age_max = max(.data[[age_column]]), - .by = strata - ) %>% - print() - } else { - ages <- object %>% - distinct( - .data[[age_column]], - .data[[id_column]] - ) + ages <- + object %>% + distinct( + across(all_of(cols)) + ) - age_summary <- ages %>% - select(all_of(age_column)) %>% - summarise( - age_min = min(.data[[age_column]]), - age_first_quartile = quantile(.data[[age_column]], 0.25), - age_median = median(.data[[age_column]]), - age_mean = mean(.data[[age_column]]), - age_third_quartile = quantile(.data[[age_column]], 0.75), - age_max = max(.data[[age_column]]) - ) %>% - print() - } + age_summary <- + ages %>% + select( + all_of(c(age_column, strata)) + ) %>% + summarise( + age_min = min(.data[[age_column]]), + age_first_quartile = quantile(.data[[age_column]], 0.25), + age_median = median(.data[[age_column]]), + age_mean = mean(.data[[age_column]]), + age_third_quartile = quantile(.data[[age_column]], 0.75), + age_max = max(.data[[age_column]]), + .by = strata + ) %>% + print() cat("\nn =", nrow(ages), "\n") cat("\nDistribution of age: \n\n") - ab_summary <- if (!is.null(strata)) { - object %>% - dplyr::summarize( - .by = c(.data$antigen_iso, .data[[strata]]), - Min = object %>% - get_value() %>% - min(na.rm = TRUE), - `1st Qu.` = object %>% - get_value() %>% - quantile(.25, na.rm = TRUE), - Median = object %>% - get_value() %>% - median(), - `3rd Qu.` = object %>% - get_value() %>% - quantile(.75, na.rm = TRUE), - Max = object %>% - get_value() %>% - max(na.rm = TRUE), - `# NAs` = object %>% - get_value() %>% - is.na() %>% - sum() - ) %>% - as.data.frame() %>% - print() - } else { + ab_summary <- object %>% - dplyr::summarize( - .by = .data$antigen_iso, - Min = object %>% - get_value() %>% - min(na.rm = TRUE), - `1st Qu.` = object %>% - get_value() %>% - quantile(.25, na.rm = TRUE), - Median = object %>% - get_value() %>% - median(), - `3rd Qu.` = object %>% - get_value() %>% - quantile(.75, na.rm = TRUE), - Max = object %>% - get_value() %>% - max(na.rm = TRUE), - `# NAs` = object %>% - get_value() %>% - is.na() %>% - sum() - ) %>% - as.data.frame() %>% - print() - } - - + dplyr::summarize( + .by = c(all_of(c("antigen_iso", strata))), + Min = object %>% + get_value() %>% + min(na.rm = TRUE), + `1st Qu.` = object %>% + get_value() %>% + quantile(.25, na.rm = TRUE), + Median = object %>% + get_value() %>% + median(), + `3rd Qu.` = object %>% + get_value() %>% + quantile(.75, na.rm = TRUE), + Max = object %>% + get_value() %>% + max(na.rm = TRUE), + `# NAs` = object %>% + get_value() %>% + is.na() %>% + sum() + ) %>% + as.data.frame() %>% + print() to_return <- list( n = nrow(ages), From 321a7abb60c080de8be236a419288995729bc30b Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 7 Jun 2024 11:15:45 +0300 Subject: [PATCH 09/33] make test changes --- R/summary.pop_data.R | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index d86cc323..f5624ac0 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -30,25 +30,27 @@ summary.pop_data <- function(object, strata = NULL, ...) { across(all_of(cols)) ) + cat("\nn =", nrow(ages), "\n") + + cat("\nDistribution of age: \n\n") + age_summary <- ages %>% select( all_of(c(age_column, strata)) ) %>% summarise( - age_min = min(.data[[age_column]]), - age_first_quartile = quantile(.data[[age_column]], 0.25), - age_median = median(.data[[age_column]]), - age_mean = mean(.data[[age_column]]), - age_third_quartile = quantile(.data[[age_column]], 0.75), - age_max = max(.data[[age_column]]), + min = min(.data[[age_column]]), + first_quartile = quantile(.data[[age_column]], 0.25), + median = median(.data[[age_column]]), + mean = mean(.data[[age_column]]), + third_quartile = quantile(.data[[age_column]], 0.75), + max = max(.data[[age_column]]), .by = strata ) %>% print() - cat("\nn =", nrow(ages), "\n") - - cat("\nDistribution of age: \n\n") + cat("\nDistributions of antigen-isotype measurements:\n\n") ab_summary <- object %>% From aa76cf2e8cdff4ec972f188e521c584def92bf95 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 7 Jun 2024 11:38:58 +0300 Subject: [PATCH 10/33] modify unit test for summary() --- inst/extdata/country.rds | Bin 0 -> 628 bytes tests/testthat/test-summary.pop_data.R | 93 ++++++------------------- 2 files changed, 21 insertions(+), 72 deletions(-) create mode 100644 inst/extdata/country.rds diff --git a/inst/extdata/country.rds b/inst/extdata/country.rds new file mode 100644 index 0000000000000000000000000000000000000000..ec359abe68d2411f244c223687199db9e3d0ffa4 GIT binary patch literal 628 zcma#xVqjokVqjrrVqjthGMR;e1UnE5fH({+44gok%PBE0Jtr|GwKxMR!s?e=keCDI za0Db~XBL+v<^h%Rfwb8_HU zmgFVorWOMQkln&;WU304M`toH{DZl`K`9Lk98?>CLJSNJN?-~^KwO}7$NsuX@^lBa zHM&>#K3(jf;`QEi{h#%47wSONI~Z&RJJCTG<^zxm8UF)iQ5% - summary() %>% - magrittr::extract2("age_summary") +#write_rds(x = country,file = 'country.rds') -test_that("`summary.pop_data()` produces same results when stratified", { - min_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_min) %>% - min() - - expect_equal(object = unstratified_summary %>% pull(age_min), expected = min_country) +test_that("`summary.pop_data()` produces an error when wrong stratification is provied", { + expect_error(object = xs_data %>% summary(strata = "province")) }) -test_that("`summary.pop_data()` produces same results when stratified", { - first_quartile_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_first_quartile) %>% - mean() - - expect_equal( - unstratified_summary %>% pull(age_first_quartile) %>% as.numeric(), - first_quartile_country, - tolerance = 0.5 - ) +test_that("`summary.pop_data()` does not produce an error when NULL", { + expect_no_error(object = xs_data %>% summary(strata = NULL)) }) -test_that("`summary.pop_data()` produces same results when stratified", { - median_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_median) %>% - mean() - - expect_equal( - unstratified_summary %>% pull(age_median), - median_country, - tolerance = 0.5 - ) +test_that("`summary.pop_data()` does not produce an error when stratified", { + expect_no_error(object = xs_data %>% summary(strata = "Country")) }) -test_that("`summary.pop_data()` produces same results when stratified", { - mean_country <- xs_data %>% +# compare outputs +test_that("`summary.pop_data()` expected", { + country <- + fs::path_package( + "inst", + "extdata", + "country.rds", + package = "serocalculator" + ) %>% + readRDS() + + gen_country <- xs_data %>% summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_mean) %>% - mean() + magrittr::extract2("age_summary") - expect_equal( - unstratified_summary %>% pull(age_mean), - mean_country, - tolerance = 0.5 - ) + expect_equal(object = gen_country,expected = country) }) -test_that("`summary.pop_data()` produces same results when stratified", { - third_quartile_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_mean) %>% - mean() - - expect_equal( - unstratified_summary %>% pull(age_third_quartile) %>% as.numeric(), - third_quartile_country, - tolerance = 0.5 - ) -}) - -test_that("`summary.pop_data()` produces same results when stratified", { - max_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") %>% - pull(age_max) %>% - mean() - - expect_equal( - unstratified_summary %>% pull(age_max), - max_country, - tolerance = 0.5 - ) -}) From 7fa24bd66bce7732f1d9f56c09fc4529e103faab Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Mon, 10 Jun 2024 11:00:28 +0300 Subject: [PATCH 11/33] skip test --- tests/testthat/test-summary.pop_data.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index bba8bb97..4473d338 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -6,8 +6,6 @@ xs_data <- load_pop_data( standardize = TRUE ) -#write_rds(x = country,file = 'country.rds') - test_that("`summary.pop_data()` produces an error when wrong stratification is provied", { expect_error(object = xs_data %>% summary(strata = "province")) }) @@ -22,10 +20,9 @@ test_that("`summary.pop_data()` does not produce an error when stratified", { # compare outputs test_that("`summary.pop_data()` expected", { + skip(message = "skipping to fix file access iisue") country <- fs::path_package( - "inst", - "extdata", "country.rds", package = "serocalculator" ) %>% From 11145f67435e97aa9d1f57efd623e6fa80063c60 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Tue, 11 Jun 2024 17:12:04 +0300 Subject: [PATCH 12/33] add unit tests --- data-raw/typhoid_results.qmd | 57 +++++++++------------ inst/extdata/country.rds | Bin 628 -> 0 bytes tests/testthat/test-est.incidence.R | 68 +++++++++++-------------- tests/testthat/test-summary.pop_data.R | 6 ++- 4 files changed, 58 insertions(+), 73 deletions(-) delete mode 100644 inst/extdata/country.rds diff --git a/data-raw/typhoid_results.qmd b/data-raw/typhoid_results.qmd index 17bb39c0..fed4d2cc 100644 --- a/data-raw/typhoid_results.qmd +++ b/data-raw/typhoid_results.qmd @@ -20,44 +20,35 @@ library(tidyverse) ``` ```{r longdata} -c.hlye.IgG <- - fs::path_package( - "extdata", - "dmcmc_hlyeigg_09.30.rds", - package = "serocalculator" - ) %>% # Load longitudinal parameters dataset - readRDS() %>% + +# pop data +csdata <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) %>% + filter(Country == "Bangladesh") %>% + select(age, antigen_iso, value) + + +# get curve data +lnpars <- load_curve_params("https://osf.io/download/rtw5k/") %>% mutate( - alpha = alpha * 365.25, # Create alpha and d d = r - 1 - ) %>% - select(y1, alpha, d) # Select only the variables needed for analysis + ) %>% + select(alpha, y1, d) ``` ``` {r simdata} -library(fs) # filesystem utility functions -p.hlye.IgG <- - fs::path_package( - package = "serocalculator", - "extdata/simpophlyeigg.2.csv" - ) %>% # Load simulated cross-sectional dataset - read_csv() %>% - rename( # rename variables - y = y.smpl, - a = a.smpl - ) %>% - select(y, a) # Select only the variables needed for analysis +# get noise data +cond <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Bangladesh") %>% + select(nu, eps, y.low, y.high) + ``` -``` {r conditions} -cond.hlye.IgG <- data.frame( - nu = 1.027239, # B noise - eps = 0.2, # M noise - y.low = 0.0, # low cutoff - y.high = 5e4, - antigen_iso = "HlyE_IgG" -) -``` ```{r seroinc} start <- .05 @@ -70,7 +61,7 @@ log.lmax <- log(10 * lambda) objfunc <- function(llam) { - return(res <- fdev(llam, p.hlye.IgG, c.hlye.IgG, cond.hlye.IgG)) + return(res <- fdev(lambda, xs_data, lnpars, cond)) } @@ -92,7 +83,7 @@ typhoid_results <- fit %>% ageCat = NULL, antigen.iso = paste(collapse = "+", "HlyE_IgG") ) %>% - structure(noise.parameters = cond.hlye.IgG) + structure(noise.parameters = cond) usethis::use_data(typhoid_results, internal = TRUE, overwrite = TRUE) ``` diff --git a/inst/extdata/country.rds b/inst/extdata/country.rds deleted file mode 100644 index ec359abe68d2411f244c223687199db9e3d0ffa4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 628 zcma#xVqjokVqjrrVqjthGMR;e1UnE5fH({+44gok%PBE0Jtr|GwKxMR!s?e=keCDI za0Db~XBL+v<^h%Rfwb8_HU zmgFVorWOMQkln&;WU304M`toH{DZl`K`9Lk98?>CLJSNJN?-~^KwO}7$NsuX@^lBa zHM&>#K3(jf;`QEi{h#%47wSONI~Z&RJJCTG<^zxm8UF)iQ5% # Load longitudinal parameters dataset - readRDS() %>% - select(y1, alpha, r, antigen_iso) - - p.hlye.IgG <- - fs::path_package( - package = "serocalculator", - "extdata/simpophlyeigg.2.csv" - ) %>% # Load simulated cross-sectional dataset - read_csv( - col_types = cols( - a.smpl = col_double(), - y.smpl = col_double(), - i = col_double(), - t = col_double() - ) - ) %>% - rename( # rename variables - y = y.smpl, - a = a.smpl - ) %>% - select(y, a) %>% - mutate(antigen_iso = "HlyE_IgG") cond.hlye.IgG <- data.frame( nu = 1.027239, # B noise @@ -45,16 +34,19 @@ test_that( start <- .05 fit <- est.incidence( - dpop = p.hlye.IgG, - dmcmc = c.hlye.IgG, - c.age = NULL, - antigen_isos = "HlyE_IgG", - noise_params = cond.hlye.IgG, - start = start, - print.level = 2, - iterlim = 100, - stepmax = 1 - ) + pop_data = xs_data %>% filter(Country == "Pakistan"), + curve_param = curve, + noise_param = noise %>% filter(Country == "Pakistan"), + antigen_isos = c("HlyE_IgG", "HlyE_IgA") + ) %>% summary.seroincidence( + coverage = .95, + start = start + ) %>% + mutate( + ageCat = NULL, + antigen.iso = paste(collapse = "+", "HlyE_IgG") + ) %>% + structure(noise.parameters = noise) # compare with `typhoid_results` from data-raw/typhoid_results.qmd diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 4473d338..65ccee8b 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -23,10 +23,12 @@ test_that("`summary.pop_data()` expected", { skip(message = "skipping to fix file access iisue") country <- fs::path_package( - "country.rds", + "extdata", + "country.rda", package = "serocalculator" ) %>% - readRDS() + load() + #readRDS() gen_country <- xs_data %>% summary(strata = "Country") %>% From f0ac5f5cf388be7428252eb0520f8d5cdc1852d3 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Wed, 12 Jun 2024 20:57:22 +0300 Subject: [PATCH 13/33] make changes to tests --- R/summary.pop_data.R | 9 +++++---- R/sysdata.rda | Bin 510 -> 818 bytes data-raw/nlm_exit_codes.R | 3 ++- data-raw/summary_country.R | 5 +++++ tests/testthat/test-summary.pop_data.R | 13 ++----------- 5 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 data-raw/summary_country.R diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index f5624ac0..d59e724c 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -34,11 +34,12 @@ summary.pop_data <- function(object, strata = NULL, ...) { cat("\nDistribution of age: \n\n") + # columns to use + cols_select <- c(age_column, strata) + age_summary <- ages %>% - select( - all_of(c(age_column, strata)) - ) %>% + select(all_of(cols_select)) %>% summarise( min = min(.data[[age_column]]), first_quartile = quantile(.data[[age_column]], 0.25), @@ -55,7 +56,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { ab_summary <- object %>% dplyr::summarize( - .by = c(all_of(c("antigen_iso", strata))), + .by = all_of(c("antigen_iso", strata)), Min = object %>% get_value() %>% min(na.rm = TRUE), diff --git a/R/sysdata.rda b/R/sysdata.rda index 8c5f3fc127e15d697f2c15ac3e0b3a69b5691a29..a46d3796493b896b4e67e0995861c198175b6267 100644 GIT binary patch literal 818 zcmV-21I_$GT4*^jL0KkKSw_#=$p8Ut|NsB<$^chqe)!%MP(c6h|L{Nn0I&!Ihynx# z0)z@Af(O6?ye$`2-Cc0h$c+h*o{5u914fMlO*ArKng)Q=CWeC(5X2g%p*E_1nrW0H z8iPOp0079)0000014fdblT&IxNYrF#XaE2J00000002m!nwn)Erl;sh>STI=XaE2J z^$h`_8UO*N)@~krv__gKb6S^#g}M`3P9)%rae_8+-pGo5nkC@aEa!6RTUxD8i_>j^?!h#L&2c0ihpOAjR+q z$O|Tkmq98pn@B>?@wF#mm_Q*P@Lgn|#7@?MK3N*HP8a3%2CgBXbI1c0jvY7?JL8Mq;> zlb6XMCT3}u9RR@*0x%FE0ESL2SgM&2aAvlAHPKFnX*N8{^_K zsn_gPISQ6VyCz7zt~5Kfs92h375!Gfa02HYPA%I>83Fn| z(N6(NvemU<9N>z8!~sh(WS|<5dWZt7lBhdR$!4yp3bHFzg+rE+CN&FK%gDkSWd~g; w@1*6>5t9V6tOiVZyRGHtz7bC{Tz4fB%tJFjpT>b11`qsQ$rRy2K^s47Bt>Uuq5uE@ literal 510 zcmV(`9|AhWAKmb5zei#M?5J3O$-|z$g0s%k)*JD*` z4O7!8k*Vp5pQ(y^ntGZv)6-KS>Szy9=p_iyDtSzvjF12T0ibE2hK7Iu0MGyc00L7) z6+NmwJyT49qd))#ngB5*CiNhDsu^vd5y6l`t9G1n)tID}CQ(y3A^=6*q8w&!TRARz znms#G_9dz{W+=4yJm6N>uag|GCnbXN{X-kvvOtl78j(JZD}&-07G@buD~n5+RnJ<+9L1b;a^_(FvyQ{4kU_FRCWxCIqU}0vZWL z+N~mlL}RMk4tCF>z+8gLRXqaWTLY~spjyh#s~E+#s5^rUz~8pH;y@KOZLKDcj1@)F z*&8i#Ou0ophBG1N)i<-+S;sAl70QfbMajVG%7xd`q~{`~>wyA-sv?q>Z1zFjSilw& zc>;I@<0c+J?3G_=k}w@ZSpu!@OBTZdVwH&@4%RUt-i8#XSbvMTBAh5lNQX|6fONj* AMgRZ+ diff --git a/data-raw/nlm_exit_codes.R b/data-raw/nlm_exit_codes.R index c22577ac..0f33bcce 100644 --- a/data-raw/nlm_exit_codes.R +++ b/data-raw/nlm_exit_codes.R @@ -6,4 +6,5 @@ nlm_exit_codes <- c( "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." ) -usethis::use_data(nlm_exit_codes, overwrite = TRUE, internal = TRUE) +usethis::use_data(nlm_exit_codes, summary_country,overwrite = TRUE, internal = TRUE) + diff --git a/data-raw/summary_country.R b/data-raw/summary_country.R new file mode 100644 index 00000000..d2033cb2 --- /dev/null +++ b/data-raw/summary_country.R @@ -0,0 +1,5 @@ +summary_country <- xs_data %>% + summary(strata = "Country") %>% + magrittr::extract2("age_summary") + +usethis::use_data(summary_country, overwrite = TRUE, internal = TRUE) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 65ccee8b..6d07bc7e 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -19,22 +19,13 @@ test_that("`summary.pop_data()` does not produce an error when stratified", { }) # compare outputs -test_that("`summary.pop_data()` expected", { - skip(message = "skipping to fix file access iisue") - country <- - fs::path_package( - "extdata", - "country.rda", - package = "serocalculator" - ) %>% - load() - #readRDS() +test_that("`summary.pop_data()` expected same results", { gen_country <- xs_data %>% summary(strata = "Country") %>% magrittr::extract2("age_summary") - expect_equal(object = gen_country,expected = country) + expect_equal(object = gen_country,expected = summary_country) }) From cc249a4759f5960818a6ee96cc2c41d91b482349 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Wed, 19 Jun 2024 11:12:42 +0300 Subject: [PATCH 14/33] add tests --- R/add_point_to_graph.R | 2 +- R/graph.loglik.R | 4 +- R/nll.R | 2 +- R/summary.pop_data.R | 10 +--- R/sysdata.rda | Bin 818 -> 1644 bytes data-raw/nlm_exit_codes.R | 55 +++++++++++++++++++++- data-raw/summary_country.R | 17 +++++-- data-raw/typhoid_results.R | 41 ++++++++++++++++ data-raw/typhoid_results.qmd | 43 +++++++---------- man/dot-nll.Rd | 2 +- tests/testthat/test-est.incidence.R | 62 ++++++++++--------------- tests/testthat/test-summary.pop_data.R | 23 ++++----- 12 files changed, 169 insertions(+), 92 deletions(-) create mode 100644 data-raw/typhoid_results.R diff --git a/R/add_point_to_graph.R b/R/add_point_to_graph.R index 523c8040..2da2e54a 100644 --- a/R/add_point_to_graph.R +++ b/R/add_point_to_graph.R @@ -5,7 +5,7 @@ add_point_to_graph <- function( point_data = tibble( x = fit$estimate %>% exp(), - y = llik(.data$x, ...), + y = log_likelihood(.data$x, ...), label = "est.incidence" ), ...) { diff --git a/R/graph.loglik.R b/R/graph.loglik.R index b86babc7..a8d5b699 100644 --- a/R/graph.loglik.R +++ b/R/graph.loglik.R @@ -68,7 +68,7 @@ graph.loglik = function( plot_data <- tibble( x = x %>% sort(), - y = llik( + y = log_likelihood( pop_data = pop_data, curve_params = curve_params, noise_params = noise_params, @@ -94,7 +94,7 @@ graph.loglik = function( ggplot2::geom_point( data = tibble( x = highlight_points, - y = llik( + y = log_likelihood( pop_data = pop_data, curve_params = curve_params, noise_params = noise_params, diff --git a/R/nll.R b/R/nll.R index 044dfcf2..442c9f32 100644 --- a/R/nll.R +++ b/R/nll.R @@ -1,6 +1,6 @@ #' Calculate negative log-likelihood #' @description -#' Same as [llik()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`). +#' Same as [log_likelihood()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`). #' @param log.lambda natural logarithm of incidence rate #' @inheritDotParams llik -lambda diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index d59e724c..2dd2c1f2 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -22,24 +22,18 @@ summary.pop_data <- function(object, strata = NULL, ...) { id_column <- object %>% get_id_var() # create a list of the columns - cols <- c(age_column, id_column, strata) + cols <- c(age_column, strata) ages <- object %>% - distinct( - across(all_of(cols)) - ) + distinct(across(all_of(cols))) cat("\nn =", nrow(ages), "\n") cat("\nDistribution of age: \n\n") - # columns to use - cols_select <- c(age_column, strata) - age_summary <- ages %>% - select(all_of(cols_select)) %>% summarise( min = min(.data[[age_column]]), first_quartile = quantile(.data[[age_column]], 0.25), diff --git a/R/sysdata.rda b/R/sysdata.rda index a46d3796493b896b4e67e0995861c198175b6267..d1bd56d9799c8ab2fa923841b68119f924b3668c 100644 GIT binary patch literal 1644 zcmV-y29xaND;W`lMixr`>z2nkQ@J|@ix}B2HEV(Lni!37I z$cRxaD3~o{X@yC-S=@&DjQO?^!&A@-j|!P-ybWR~ofTS}Sx~SbTf(Iye{_5Wg_?n>rTt)t<7u2%cxo&5CdEYFMg>|%pyw@p(h zB4AWW1fU5tg<8ZVbIS?BE$2=vUc^lTm87A7ODsZg%JK=Ah+-`8B69+FHWdacMxp}P zgaSxjgawEJBM=lMkOGn)lYPyo0lD*F=~XecqURk0-vF9&;q64C`RTqY%q%=}u| zAg^zv+pi0H>#qn*ld93cc4w#yYEr^w0QG>q?iwiRbOH@ToaRM^pd<;avn@Jvm_2`6B+etI7-m>4E$}3u zW9ErEwYC}@#3*QJXvlAv>THnMyJdsuXEr9G+3n!>9F}5vUm~gqWCQG6su;dDR}6ye z8U#6}400Y5ulP@kf7Yp;`82t3bYRWuqnammho)t0g;0siubdbljob2X84?@k|wqbvPp7kBmQn7k#A_@T$qX zlAwFAM;K9gNUA}bWlx*+?#<#(R3l6)``ZG?p`u-4ZD-c)u(hq^Adgx?1564FPKZ?( zjz_v7GCX9r7y|XBeb(a__#=LJWJ* z(*mb5yW0t_xe1!f_A;^R#83sXAEvc_2QcW&V8C{l0a~C3XA*ZZY9M_90EK6p7ep89 z7d-|pK$Ydz;tX9%p;Cs<(U)^ktwTcN3#`;@DsEir(oDHcubKGaa0yc8L2=w>FKebny%zsM}`1(uj2P;*8`~5l=mr z9LL{)QDF2`QZC;yg)Rud$PQ~ESy@Z?pG`s2gDa$pKxn8}r6MJiOjOcSgo^JGdUP%h z%_62Dg0(GBa54dk#(k&UU3%#X6KEw!VxWk<4Kc8am)TN-rR3fl`zr{LV?MkhNX*!^ zs0%GaB_ZRX0STI=XaE2J z^$h`_8UO*N)@~krv__gKb6S^#g}M`3P9)%rae_8+-pGo5nkC@aEa!6RTUxD8i_>j^?!h#L&2c0ihpOAjR+q z$O|Tkmq98pn@B>?@wF#mm_Q*P@Lgn|#7@?MK3N*HP8a3%2CgBXbI1c0jvY7?JL8Mq;> zlb6XMCT3}u9RR@*0x%FE0ESL2SgM&2aAvlAHPKFnX*N8{^_K zsn_gPISQ6VyCz7zt~5Kfs92h375!Gfa02HYPA%I>83Fn| z(N6(NvemU<9N>z8!~sh(WS|<5dWZt7lBhdR$!4yp3bHFzg+rE+CN&FK%gDkSWd~g; w@1*6>5t9V6tOiVZyRGHtz7bC{Tz4fB%tJFjpT>b11`qsQ$rRy2K^s47Bt>Uuq5uE@ diff --git a/data-raw/nlm_exit_codes.R b/data-raw/nlm_exit_codes.R index 0f33bcce..45548c96 100644 --- a/data-raw/nlm_exit_codes.R +++ b/data-raw/nlm_exit_codes.R @@ -1,3 +1,4 @@ + nlm_exit_codes <- c( "1" = "1: relative gradient is close to zero, current iterate is probably solution.", "2" = "2: successive iterates within tolerance, current iterate is probably solution.", @@ -6,5 +7,57 @@ nlm_exit_codes <- c( "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." ) -usethis::use_data(nlm_exit_codes, summary_country,overwrite = TRUE, internal = TRUE) +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) + +summary_country <- xs_data %>% + summary.pop_data(strata = "Country") + +# Filter population data for Pakistan +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) %>% + filter(Country == "Pakistan") + +# get noise data +noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Pakistan") + +# get curve data +curve <- load_curve_params("https://osf.io/download/rtw5k/") + +# Initial estimates for lambda +start <- .05 + +# Estimate incidence +fit <- est.incidence( + pop_data = xs_data, + curve_param = curve, + noise_param = noise, + antigen_isos = c("HlyE_IgG", "HlyE_IgA") +) + +typhoid_results <- fit %>% + summary.seroincidence( + coverage = .95, + start = start + ) %>% + mutate( + ageCat = NULL, + antigen.iso = paste(collapse = "+", "HlyE_IgG") + ) %>% + structure(noise.parameters = noise) + + +usethis::use_data(typhoid_results, summary_country, nlm_exit_codes, overwrite = TRUE, internal = TRUE) + diff --git a/data-raw/summary_country.R b/data-raw/summary_country.R index d2033cb2..bb14b6a2 100644 --- a/data-raw/summary_country.R +++ b/data-raw/summary_country.R @@ -1,5 +1,12 @@ -summary_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") - -usethis::use_data(summary_country, overwrite = TRUE, internal = TRUE) +# xs_data <- load_pop_data( +# file_path = "https://osf.io/download//n6cp3/", +# age = "Age", +# value = "result", +# id = "index_id", +# standardize = TRUE +# ) +# +# summary_country <- xs_data %>% +# summary.pop_data(strata = "Country") +# +# usethis::use_data(summary_country, overwrite = TRUE, internal = TRUE) diff --git a/data-raw/typhoid_results.R b/data-raw/typhoid_results.R new file mode 100644 index 00000000..d36aa99e --- /dev/null +++ b/data-raw/typhoid_results.R @@ -0,0 +1,41 @@ + +# Filter population data for Pakistan +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) %>% + filter(Country == "Pakistan") + +# get noise data +noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Pakistan") + +# get curve data +curve <- load_curve_params("https://osf.io/download/rtw5k/") + +# Initial estimates for lambda +start <- .05 + +# Estimate incidence +fit <- est.incidence( + pop_data = xs_data, + curve_param = curve, + noise_param = noise, + antigen_isos = c("HlyE_IgG", "HlyE_IgA") +) + +typhoid_results <- fit %>% + summary.seroincidence( + coverage = .95, + start = start + ) %>% + mutate( + ageCat = NULL, + antigen.iso = paste(collapse = "+", "HlyE_IgG") + ) %>% + structure(noise.parameters = noise) + +usethis::use_data(typhoid_results, internal = TRUE, overwrite = TRUE) diff --git a/data-raw/typhoid_results.qmd b/data-raw/typhoid_results.qmd index fed4d2cc..bc4df22c 100644 --- a/data-raw/typhoid_results.qmd +++ b/data-raw/typhoid_results.qmd @@ -22,30 +22,25 @@ library(tidyverse) ```{r longdata} # pop data -csdata <- load_pop_data( +xs_data <- load_pop_data( file_path = "https://osf.io/download//n6cp3/", age = "Age", value = "result", id = "index_id", standardize = TRUE ) %>% - filter(Country == "Bangladesh") %>% - select(age, antigen_iso, value) + filter(Country == 'Pakistan') # get curve data -lnpars <- load_curve_params("https://osf.io/download/rtw5k/") %>% - mutate( - d = r - 1 - ) %>% - select(alpha, y1, d) +curve <- load_curve_params("https://osf.io/download/rtw5k/") + ``` ``` {r simdata} # get noise data -cond <- load_noise_params("https://osf.io/download//hqy4v/") %>% - filter(Country == "Bangladesh") %>% - select(nu, eps, y.low, y.high) +noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == 'Pakistan') ``` @@ -58,20 +53,15 @@ log.lambda <- log(lambda) log.lmin <- log(lambda / 10) log.lmax <- log(10 * lambda) +# objfunc <- function(llam) { +# return(res <- f_dev(lambda, csdata, lnpars, cond)) +# } - -objfunc <- function(llam) { - return(res <- fdev(lambda, xs_data, lnpars, cond)) -} - - -fit <- nlm( - objfunc, - p = log.lambda, - hessian = TRUE, - print.level = 0, - stepmax = 1, - iterlim = 100 +fit <- est.incidence( + pop_data = xs_data, + curve_param = curve, + noise_param = noise, + antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) typhoid_results <- fit %>% @@ -83,7 +73,10 @@ typhoid_results <- fit %>% ageCat = NULL, antigen.iso = paste(collapse = "+", "HlyE_IgG") ) %>% - structure(noise.parameters = cond) + structure(noise.parameters = noise) usethis::use_data(typhoid_results, internal = TRUE, overwrite = TRUE) + + + ``` diff --git a/man/dot-nll.Rd b/man/dot-nll.Rd index 9f4fa97c..2a4601e3 100644 --- a/man/dot-nll.Rd +++ b/man/dot-nll.Rd @@ -19,6 +19,6 @@ the negative log-likelihood of the data with the current parameter values } \description{ -Same as \code{\link[=llik]{llik()}}, except negated and requiring lambda on log scale (used in combination with \code{nlm()}, to ensure that the optimization search doesn't stray into negative values of \code{lambda}). +Same as \code{\link[=log_likelihood]{log_likelihood()}}, except negated and requiring lambda on log scale (used in combination with \code{nlm()}, to ensure that the optimization search doesn't stray into negative values of \code{lambda}). } \keyword{internal} diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index 5ef4ad14..8156194b 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -1,47 +1,36 @@ - -# get pop data -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) - -# get noise data -noise <- load_noise_params("https://osf.io/download//hqy4v/") - -# get curve data -curve <- load_curve_params("https://osf.io/download/rtw5k/") - - test_that( "est.incidence() produces expected results for typhoid data", { - skip(message = "Skipping test of `est.incidence()` for now, because github was producing miniscule differences in SE (and thus CIs) for some reason that I don't have time to hunt down.") + # get pop data + xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE + ) %>% + filter(Country == "Pakistan") - library(readr) - library(dplyr) + # get noise data + noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Pakistan") - cond.hlye.IgG <- data.frame( - nu = 1.027239, # B noise - eps = 0.2, # M noise - y.low = 0.0, # low cutoff - y.high = 5e4, - antigen_iso = "HlyE_IgG" - ) + # get curve data + curve <- load_curve_params("https://osf.io/download/rtw5k/") + # set start start <- .05 fit <- est.incidence( - pop_data = xs_data %>% filter(Country == "Pakistan"), + pop_data = xs_data, curve_param = curve, - noise_param = noise %>% filter(Country == "Pakistan"), + noise_param = noise, antigen_isos = c("HlyE_IgG", "HlyE_IgA") - ) %>% summary.seroincidence( - coverage = .95, - start = start ) %>% + summary.seroincidence( + coverage = .95, + start = start + ) %>% mutate( ageCat = NULL, antigen.iso = paste(collapse = "+", "HlyE_IgG") @@ -49,10 +38,9 @@ test_that( structure(noise.parameters = noise) # compare with `typhoid_results` from data-raw/typhoid_results.qmd - - expect_equal( - object = fit, - expected = typhoid_results - ) + expect_equal( + object = fit, + expected = typhoid_results + ) } ) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 6d07bc7e..9b046443 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -8,24 +8,25 @@ xs_data <- load_pop_data( test_that("`summary.pop_data()` produces an error when wrong stratification is provied", { expect_error(object = xs_data %>% summary(strata = "province")) + # add condition for exact error - use regexp option in expect_error() }) test_that("`summary.pop_data()` does not produce an error when NULL", { - expect_no_error(object = xs_data %>% summary(strata = NULL)) + suppressWarnings({ + expect_no_error(object = xs_data %>% summary(strata = NULL)) + }) }) test_that("`summary.pop_data()` does not produce an error when stratified", { - expect_no_error(object = xs_data %>% summary(strata = "Country")) + + suppressWarnings({ + expect_no_error(object = xs_data %>% summary(strata = "Country")) + }) }) -# compare outputs test_that("`summary.pop_data()` expected same results", { - - gen_country <- xs_data %>% - summary(strata = "Country") %>% - magrittr::extract2("age_summary") - - expect_equal(object = gen_country,expected = summary_country) + suppressWarnings({ + expect_equal(object = xs_data %>% + summary(strata = "Country"), expected = summary_country) + }) }) - - From f774fa7a1e7fb22c912e6fffaa5c9c2020113719 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Wed, 19 Jun 2024 18:49:23 +0300 Subject: [PATCH 15/33] clean up tests --- data-raw/{nlm_exit_codes.R => data_objects.R} | 3 -- data-raw/summary_country.R | 12 ------ data-raw/typhoid_results.R | 41 ------------------- tests/testthat/test-summary.pop_data.R | 11 +++-- 4 files changed, 8 insertions(+), 59 deletions(-) rename data-raw/{nlm_exit_codes.R => data_objects.R} (99%) delete mode 100644 data-raw/summary_country.R delete mode 100644 data-raw/typhoid_results.R diff --git a/data-raw/nlm_exit_codes.R b/data-raw/data_objects.R similarity index 99% rename from data-raw/nlm_exit_codes.R rename to data-raw/data_objects.R index 45548c96..e0b26ead 100644 --- a/data-raw/nlm_exit_codes.R +++ b/data-raw/data_objects.R @@ -1,4 +1,3 @@ - nlm_exit_codes <- c( "1" = "1: relative gradient is close to zero, current iterate is probably solution.", "2" = "2: successive iterates within tolerance, current iterate is probably solution.", @@ -59,5 +58,3 @@ typhoid_results <- fit %>% usethis::use_data(typhoid_results, summary_country, nlm_exit_codes, overwrite = TRUE, internal = TRUE) - - diff --git a/data-raw/summary_country.R b/data-raw/summary_country.R deleted file mode 100644 index bb14b6a2..00000000 --- a/data-raw/summary_country.R +++ /dev/null @@ -1,12 +0,0 @@ -# xs_data <- load_pop_data( -# file_path = "https://osf.io/download//n6cp3/", -# age = "Age", -# value = "result", -# id = "index_id", -# standardize = TRUE -# ) -# -# summary_country <- xs_data %>% -# summary.pop_data(strata = "Country") -# -# usethis::use_data(summary_country, overwrite = TRUE, internal = TRUE) diff --git a/data-raw/typhoid_results.R b/data-raw/typhoid_results.R deleted file mode 100644 index d36aa99e..00000000 --- a/data-raw/typhoid_results.R +++ /dev/null @@ -1,41 +0,0 @@ - -# Filter population data for Pakistan -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) %>% - filter(Country == "Pakistan") - -# get noise data -noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% - filter(Country == "Pakistan") - -# get curve data -curve <- load_curve_params("https://osf.io/download/rtw5k/") - -# Initial estimates for lambda -start <- .05 - -# Estimate incidence -fit <- est.incidence( - pop_data = xs_data, - curve_param = curve, - noise_param = noise, - antigen_isos = c("HlyE_IgG", "HlyE_IgA") -) - -typhoid_results <- fit %>% - summary.seroincidence( - coverage = .95, - start = start - ) %>% - mutate( - ageCat = NULL, - antigen.iso = paste(collapse = "+", "HlyE_IgG") - ) %>% - structure(noise.parameters = noise) - -usethis::use_data(typhoid_results, internal = TRUE, overwrite = TRUE) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 9b046443..1ffba04b 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -7,24 +7,29 @@ xs_data <- load_pop_data( ) test_that("`summary.pop_data()` produces an error when wrong stratification is provied", { - expect_error(object = xs_data %>% summary(strata = "province")) - # add condition for exact error - use regexp option in expect_error() + expect_error( + object = xs_data %>% summary(strata = "province"), + regexp = "Can't subset columns that don't exist." + ) }) test_that("`summary.pop_data()` does not produce an error when NULL", { + # TO DOs: change calls to deprecated function calls (New PR) suppressWarnings({ expect_no_error(object = xs_data %>% summary(strata = NULL)) }) }) test_that("`summary.pop_data()` does not produce an error when stratified", { - + # TO DOs: change calls to deprecated function calls (New PR) suppressWarnings({ expect_no_error(object = xs_data %>% summary(strata = "Country")) }) }) + test_that("`summary.pop_data()` expected same results", { + # TO DOs: change calls to deprecated function calls (New PR) suppressWarnings({ expect_equal(object = xs_data %>% summary(strata = "Country"), expected = summary_country) From 2f1ac7451c1e80596107635e083ef2fedf7fd1aa Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 20 Jun 2024 12:16:51 +0300 Subject: [PATCH 16/33] modify tests --- tests/testthat/test-est.incidence.R | 92 +++++++++++++------------- tests/testthat/test-summary.pop_data.R | 5 +- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index 8156194b..af18b6be 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -1,46 +1,46 @@ -test_that( - "est.incidence() produces expected results for typhoid data", - { - # get pop data - xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE - ) %>% - filter(Country == "Pakistan") - - # get noise data - noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% - filter(Country == "Pakistan") - - # get curve data - curve <- load_curve_params("https://osf.io/download/rtw5k/") - - # set start - start <- .05 - - fit <- est.incidence( - pop_data = xs_data, - curve_param = curve, - noise_param = noise, - antigen_isos = c("HlyE_IgG", "HlyE_IgA") - ) %>% - summary.seroincidence( - coverage = .95, - start = start - ) %>% - mutate( - ageCat = NULL, - antigen.iso = paste(collapse = "+", "HlyE_IgG") - ) %>% - structure(noise.parameters = noise) - - # compare with `typhoid_results` from data-raw/typhoid_results.qmd - expect_equal( - object = fit, - expected = typhoid_results - ) - } -) +# test_that( +# "est.incidence() produces expected results for typhoid data", +# { +# # get pop data +# xs_data <- load_pop_data( +# file_path = "https://osf.io/download//n6cp3/", +# age = "Age", +# value = "result", +# id = "index_id", +# standardize = TRUE +# ) %>% +# filter(Country == "Pakistan") +# +# # get noise data +# noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% +# filter(Country == "Pakistan") +# +# # get curve data +# curve <- load_curve_params("https://osf.io/download/rtw5k/") +# +# # set start +# start <- .05 +# +# fit <- est.incidence( +# pop_data = xs_data, +# curve_param = curve, +# noise_param = noise, +# antigen_isos = c("HlyE_IgG", "HlyE_IgA") +# ) %>% +# summary.seroincidence( +# coverage = .95, +# start = start +# ) %>% +# mutate( +# ageCat = NULL, +# antigen.iso = paste(collapse = "+", "HlyE_IgG") +# ) %>% +# structure(noise.parameters = noise) +# +# # compare with `typhoid_results` from data-raw/typhoid_results.qmd +# expect_equal( +# object = fit, +# expected = typhoid_results +# ) +# } +# ) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 1ffba04b..6534dc58 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -6,10 +6,11 @@ xs_data <- load_pop_data( standardize = TRUE ) -test_that("`summary.pop_data()` produces an error when wrong stratification is provied", { +test_that("`summary.pop_data()` produces an error when wrong stratification is provide", { expect_error( object = xs_data %>% summary(strata = "province"), - regexp = "Can't subset columns that don't exist." + regexp = "Element `province` doesn't exist.", + fixed = TRUE ) }) From c51e9499df517cb019911b6fe540258fe25b413d Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 20 Jun 2024 13:15:56 +0300 Subject: [PATCH 17/33] modify test comments --- tests/testthat/test-est.incidence.R | 92 +++++++++++++------------- tests/testthat/test-summary.pop_data.R | 8 +-- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index af18b6be..8156194b 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -1,46 +1,46 @@ -# test_that( -# "est.incidence() produces expected results for typhoid data", -# { -# # get pop data -# xs_data <- load_pop_data( -# file_path = "https://osf.io/download//n6cp3/", -# age = "Age", -# value = "result", -# id = "index_id", -# standardize = TRUE -# ) %>% -# filter(Country == "Pakistan") -# -# # get noise data -# noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% -# filter(Country == "Pakistan") -# -# # get curve data -# curve <- load_curve_params("https://osf.io/download/rtw5k/") -# -# # set start -# start <- .05 -# -# fit <- est.incidence( -# pop_data = xs_data, -# curve_param = curve, -# noise_param = noise, -# antigen_isos = c("HlyE_IgG", "HlyE_IgA") -# ) %>% -# summary.seroincidence( -# coverage = .95, -# start = start -# ) %>% -# mutate( -# ageCat = NULL, -# antigen.iso = paste(collapse = "+", "HlyE_IgG") -# ) %>% -# structure(noise.parameters = noise) -# -# # compare with `typhoid_results` from data-raw/typhoid_results.qmd -# expect_equal( -# object = fit, -# expected = typhoid_results -# ) -# } -# ) +test_that( + "est.incidence() produces expected results for typhoid data", + { + # get pop data + xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE + ) %>% + filter(Country == "Pakistan") + + # get noise data + noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Pakistan") + + # get curve data + curve <- load_curve_params("https://osf.io/download/rtw5k/") + + # set start + start <- .05 + + fit <- est.incidence( + pop_data = xs_data, + curve_param = curve, + noise_param = noise, + antigen_isos = c("HlyE_IgG", "HlyE_IgA") + ) %>% + summary.seroincidence( + coverage = .95, + start = start + ) %>% + mutate( + ageCat = NULL, + antigen.iso = paste(collapse = "+", "HlyE_IgG") + ) %>% + structure(noise.parameters = noise) + + # compare with `typhoid_results` from data-raw/typhoid_results.qmd + expect_equal( + object = fit, + expected = typhoid_results + ) + } +) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 6534dc58..2a9660ac 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -6,7 +6,7 @@ xs_data <- load_pop_data( standardize = TRUE ) -test_that("`summary.pop_data()` produces an error when wrong stratification is provide", { +test_that("`summary.pop_data()` produces an error when wrong stratification is provided", { expect_error( object = xs_data %>% summary(strata = "province"), regexp = "Element `province` doesn't exist.", @@ -15,14 +15,14 @@ test_that("`summary.pop_data()` produces an error when wrong stratification is p }) test_that("`summary.pop_data()` does not produce an error when NULL", { - # TO DOs: change calls to deprecated function calls (New PR) + # suppress warning avoids a deprecation tidyverse warning on use of select(data) suppressWarnings({ expect_no_error(object = xs_data %>% summary(strata = NULL)) }) }) test_that("`summary.pop_data()` does not produce an error when stratified", { - # TO DOs: change calls to deprecated function calls (New PR) + # suppress warning avoids a deprecation tidyverse warning on use of select(data) suppressWarnings({ expect_no_error(object = xs_data %>% summary(strata = "Country")) }) @@ -30,7 +30,7 @@ test_that("`summary.pop_data()` does not produce an error when stratified", { test_that("`summary.pop_data()` expected same results", { - # TO DOs: change calls to deprecated function calls (New PR) + # suppress warning avoids a deprecation tidyverse warning on use of select(data) suppressWarnings({ expect_equal(object = xs_data %>% summary(strata = "Country"), expected = summary_country) From 9e4dd7385ab80b3a4fad7db30d76ceeac431110d Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 20 Jun 2024 20:16:17 +0300 Subject: [PATCH 18/33] Increment version number to 1.2.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d1d97891..6e797276 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: serocalculator Type: Package Title: Estimating Infection Rates from Serological Data -Version: 1.1.0 +Version: 1.2.0 Authors@R: c( person(given = "Peter", family = "Teunis", email = "p.teunis@emory.edu", role = c("aut", "cph"), comment = "Author of the method and original code."), person(given = "Kristina", family = "Lai", email = "kwlai@ucdavis.edu", role = c("aut", "cre")), diff --git a/NEWS.md b/NEWS.md index 7dc2b3c4..b792fa89 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# serocalculator 1.2.0 + # serocalculator 1.1.0 * Renamed `llik()` to `log_likelihood()` From 005a68e73292ff35af5e0893726d6064b8f44951 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 20 Jun 2024 20:30:26 +0300 Subject: [PATCH 19/33] add versioning --- NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NEWS.md b/NEWS.md index b792fa89..34a916ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,11 @@ # serocalculator 1.2.0 +* Renamed `nlm_exit_codes` file to `data_objects` + +* Added `test-summary.pop_data` test + +* Modified `test-est.incidence` test + +* Added stratification to `summary.pop_data` # serocalculator 1.1.0 From 5a8f7b0483720e7ee3be35e7068db0c38f881bc6 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 2 Jul 2024 15:15:36 -0400 Subject: [PATCH 20/33] Update enteric_fever_example.Rmd move eval=FALSE from code into chunk options --- vignettes/articles/enteric_fever_example.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vignettes/articles/enteric_fever_example.Rmd b/vignettes/articles/enteric_fever_example.Rmd index 4cbd943e..0464f0b8 100644 --- a/vignettes/articles/enteric_fever_example.Rmd +++ b/vignettes/articles/enteric_fever_example.Rmd @@ -33,8 +33,8 @@ knitr::opts_chunk$set( ### Load packages The first step in conducting this analysis is to load our necessary packages. If you haven't installed already, you will need to do so before loading. -```{r setup, message=FALSE} -# devtools::install_github("ucd-serg/serocalculator", eval=FALSE) +```{r setup, eval=FALSE} +# devtools::install_github("ucd-serg/serocalculator") ``` From 59d2903d618ce58c88b5bc6b6692aa48a888a870 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 5 Jul 2024 08:08:14 +0300 Subject: [PATCH 21/33] correct test errors --- R/summary.pop_data.R | 2 +- data-raw/data_objects.R | 60 -------------------- data-raw/nlm_exit_codes.R | 9 +++ data-raw/summary_country.R | 12 ++++ data-raw/typhoid_results.R | 40 +++++++++++++ tests/testthat/fixtures/summary_country.rds | Bin 0 -> 588 bytes tests/testthat/test-summary.pop_data.R | 24 ++++---- 7 files changed, 73 insertions(+), 74 deletions(-) delete mode 100644 data-raw/data_objects.R create mode 100644 data-raw/nlm_exit_codes.R create mode 100644 data-raw/summary_country.R create mode 100644 data-raw/typhoid_results.R create mode 100644 tests/testthat/fixtures/summary_country.rds diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index 2dd2c1f2..cc89dd50 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -41,7 +41,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { mean = mean(.data[[age_column]]), third_quartile = quantile(.data[[age_column]], 0.75), max = max(.data[[age_column]]), - .by = strata + .by = all_of(strata) ) %>% print() diff --git a/data-raw/data_objects.R b/data-raw/data_objects.R deleted file mode 100644 index e0b26ead..00000000 --- a/data-raw/data_objects.R +++ /dev/null @@ -1,60 +0,0 @@ -nlm_exit_codes <- c( - "1" = "1: relative gradient is close to zero, current iterate is probably solution.", - "2" = "2: successive iterates within tolerance, current iterate is probably solution.", - "3" = "3: Last global step failed to locate a point lower than x. Either x is an approximate local minimum of the function, the function is too non-linear for this algorithm, or `stepmin` in `est.incidence()` (a.k.a. `steptol` in `nlm()`) is too large.", - "4" = "4: iteration limit exceeded; increase `iterlim`.", - "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." -) - -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) - -summary_country <- xs_data %>% - summary.pop_data(strata = "Country") - -# Filter population data for Pakistan -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) %>% - filter(Country == "Pakistan") - -# get noise data -noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% - filter(Country == "Pakistan") - -# get curve data -curve <- load_curve_params("https://osf.io/download/rtw5k/") - -# Initial estimates for lambda -start <- .05 - -# Estimate incidence -fit <- est.incidence( - pop_data = xs_data, - curve_param = curve, - noise_param = noise, - antigen_isos = c("HlyE_IgG", "HlyE_IgA") -) - -typhoid_results <- fit %>% - summary.seroincidence( - coverage = .95, - start = start - ) %>% - mutate( - ageCat = NULL, - antigen.iso = paste(collapse = "+", "HlyE_IgG") - ) %>% - structure(noise.parameters = noise) - - -usethis::use_data(typhoid_results, summary_country, nlm_exit_codes, overwrite = TRUE, internal = TRUE) diff --git a/data-raw/nlm_exit_codes.R b/data-raw/nlm_exit_codes.R new file mode 100644 index 00000000..c22577ac --- /dev/null +++ b/data-raw/nlm_exit_codes.R @@ -0,0 +1,9 @@ +nlm_exit_codes <- c( + "1" = "1: relative gradient is close to zero, current iterate is probably solution.", + "2" = "2: successive iterates within tolerance, current iterate is probably solution.", + "3" = "3: Last global step failed to locate a point lower than x. Either x is an approximate local minimum of the function, the function is too non-linear for this algorithm, or `stepmin` in `est.incidence()` (a.k.a. `steptol` in `nlm()`) is too large.", + "4" = "4: iteration limit exceeded; increase `iterlim`.", + "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." +) + +usethis::use_data(nlm_exit_codes, overwrite = TRUE, internal = TRUE) diff --git a/data-raw/summary_country.R b/data-raw/summary_country.R new file mode 100644 index 00000000..e1c862bb --- /dev/null +++ b/data-raw/summary_country.R @@ -0,0 +1,12 @@ +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) + +summary_country <- xs_data %>% + summary.pop_data(strata = "Country") + +saveRDS(object = summary_country,file = "tests/testthat/fixtures/summary_country.rds") diff --git a/data-raw/typhoid_results.R b/data-raw/typhoid_results.R new file mode 100644 index 00000000..56838c0c --- /dev/null +++ b/data-raw/typhoid_results.R @@ -0,0 +1,40 @@ +# Filter population data for Pakistan +xs_data <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE +) %>% + filter(Country == "Pakistan") + +# get noise data +noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + filter(Country == "Pakistan") + +# get curve data +curve <- load_curve_params("https://osf.io/download/rtw5k/") + +# Initial estimates for lambda +start <- .05 + +# Estimate incidence +fit <- est.incidence( + pop_data = xs_data, + curve_param = curve, + noise_param = noise, + antigen_isos = c("HlyE_IgG", "HlyE_IgA") +) + +typhoid_results <- fit %>% + summary.seroincidence( + coverage = .95, + start = start + ) %>% + mutate( + ageCat = NULL, + antigen.iso = paste(collapse = "+", "HlyE_IgG") + ) %>% + structure(noise.parameters = noise) + +saveRDS(object = typhoid_results,file = "tests/testthat/fixtures/typhoid_results.rds") diff --git a/tests/testthat/fixtures/summary_country.rds b/tests/testthat/fixtures/summary_country.rds new file mode 100644 index 0000000000000000000000000000000000000000..35dcf4a777572ab994533c5725892210a93232f9 GIT binary patch literal 588 zcmV-S0<--eiwFP!0000028-ZgU|?WoU}0urU}gm}8CXL@+;lA%7?^~?5)2HyK+Fi_ z%K^C{F?JvpfM{ai1kzkiiFxTci7BbY8Bh^cztn=n94Ln)ATc|$xFj(T$mRoSvwv(1 z2KH~xfWTS%moq_N7SIZ?yo0bLSinK*SsDd@V?r5$v_?~Zc-9U67|xGfI)?34rft*xgIPCK~c=q03`nZ|Nj@w7wk|C?9Tb6c_l@a zFiUbX^Po(=w9KO7lK8^X#G;bSoK%>ba#K?>6Jcsta#P`KzLJd0q7-!X%(;mbknjMf zG7caOauypT^)WDE(kT96%SkOu&4C3B6D;w0% summary(strata = NULL)) - }) + expect_no_error(object = xs_data %>% summary(strata = NULL)) }) test_that("`summary.pop_data()` does not produce an error when stratified", { - # suppress warning avoids a deprecation tidyverse warning on use of select(data) - suppressWarnings({ - expect_no_error(object = xs_data %>% summary(strata = "Country")) - }) + expect_no_error(object = xs_data %>% summary(strata = "Country")) }) test_that("`summary.pop_data()` expected same results", { - # suppress warning avoids a deprecation tidyverse warning on use of select(data) - suppressWarnings({ - expect_equal(object = xs_data %>% - summary(strata = "Country"), expected = summary_country) - }) + # Define the path to the RDS file in the fixtures directory + summary_country_path <- test_path("fixtures", "summary_country.rds") + + # Load the RDS file + summary_country <- readRDS(summary_country_path) + + + expect_equal(object = xs_data %>% + summary(strata = "Country"), expected = summary_country) }) From 4d243935c4a1bea4707560e74fef2586f0a8faf1 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 5 Jul 2024 09:47:35 +0300 Subject: [PATCH 22/33] remove changes not connected to issue --- R/add_point_to_graph.R | 2 +- R/nll.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/add_point_to_graph.R b/R/add_point_to_graph.R index 2da2e54a..523c8040 100644 --- a/R/add_point_to_graph.R +++ b/R/add_point_to_graph.R @@ -5,7 +5,7 @@ add_point_to_graph <- function( point_data = tibble( x = fit$estimate %>% exp(), - y = log_likelihood(.data$x, ...), + y = llik(.data$x, ...), label = "est.incidence" ), ...) { diff --git a/R/nll.R b/R/nll.R index 442c9f32..044dfcf2 100644 --- a/R/nll.R +++ b/R/nll.R @@ -1,6 +1,6 @@ #' Calculate negative log-likelihood #' @description -#' Same as [log_likelihood()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`). +#' Same as [llik()], except negated and requiring lambda on log scale (used in combination with `nlm()`, to ensure that the optimization search doesn't stray into negative values of `lambda`). #' @param log.lambda natural logarithm of incidence rate #' @inheritDotParams llik -lambda From 72c4ad9a6466145c38640afb1624133ebf02adf2 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Mon, 8 Jul 2024 22:55:58 +0300 Subject: [PATCH 23/33] modify tests --- .Rbuildignore | 1 + NEWS.md | 2 - R/summary.pop_data.R | 2 +- R/sysdata.rda | Bin 1644 -> 512 bytes data-raw/summary_country.R | 3 +- man/dot-nll.Rd | 2 +- tests/testthat/fixtures/summary_country.rds | Bin 588 -> 574 bytes tests/testthat/fixtures/typhoid_results.rds | Bin 0 -> 732 bytes tests/testthat/test-est.incidence-status.R | 70 ++++++++++---------- tests/testthat/test-est.incidence.R | 6 ++ tests/testthat/test-summary.pop_data.R | 12 ++-- 11 files changed, 52 insertions(+), 46 deletions(-) create mode 100644 tests/testthat/fixtures/typhoid_results.rds diff --git a/.Rbuildignore b/.Rbuildignore index 548e44ee..ee64eaaa 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,3 +21,4 @@ allpopsamples_hlye.csv$ ^serocalculator.*\.tgz$ ^inst/extdata ^CRAN-SUBMISSION$ + diff --git a/NEWS.md b/NEWS.md index 34a916ee..dbb438f2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,4 @@ # serocalculator 1.2.0 -* Renamed `nlm_exit_codes` file to `data_objects` - * Added `test-summary.pop_data` test * Modified `test-est.incidence` test diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index cc89dd50..e4027db9 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -22,7 +22,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { id_column <- object %>% get_id_var() # create a list of the columns - cols <- c(age_column, strata) + cols <- c(age_column, id_column, strata) ages <- object %>% diff --git a/R/sysdata.rda b/R/sysdata.rda index d1bd56d9799c8ab2fa923841b68119f924b3668c..a9e7e38937a1547b9467fe7843b7c7c99fb42c3d 100644 GIT binary patch literal 512 zcmV+b0{{I&T4*^jL0KkKS<+PDy#N4?|AhWAKmb5zei#M?5J3O$-|z$g0s%k)+}W*I zhNqPpa3)jLCLX6T0q*E)BRu(!PsJ}COi6gCQ@mrUYjs7U`d$?odY@;IjwR# zCTjHUOW2OsZNQq>;PQBs&p#PfAq0q>dfDeyVvIHMXR9~M?;LbomF2LL7`L>#6&*7n zlmLQJ&X(VoaK&p}p~i_xwdVb;7V5yX^F&JmjrZ{1eczV{5plz&)1b~g=AWZyLL2=lB;x2*qRExH(c;%PCE{ZCSte8(iGDP3?vZ}(MXLj zsF$QvP!k0$Ffh?4)d7a$_rV^N^V~AYK&nwN97=gZOc!DGtWaTtwWz7N*1rLI^PIu<35|VQO zP^6{_;0eY|JVDtiK0+w8bq1;hOYb9RPGkgX41x;k79Oh-agShsi@744C`f54aNdAP C*W`8p literal 1644 zcmV-y29xaND;W`lMixr`>z2nkQ@J|@ix}B2HEV(Lni!37I z$cRxaD3~o{X@yC-S=@&DjQO?^!&A@-j|!P-ybWR~ofTS}Sx~SbTf(Iye{_5Wg_?n>rTt)t<7u2%cxo&5CdEYFMg>|%pyw@p(h zB4AWW1fU5tg<8ZVbIS?BE$2=vUc^lTm87A7ODsZg%JK=Ah+-`8B69+FHWdacMxp}P zgaSxjgawEJBM=lMkOGn)lYPyo0lD*F=~XecqURk0-vF9&;q64C`RTqY%q%=}u| zAg^zv+pi0H>#qn*ld93cc4w#yYEr^w0QG>q?iwiRbOH@ToaRM^pd<;avn@Jvm_2`6B+etI7-m>4E$}3u zW9ErEwYC}@#3*QJXvlAv>THnMyJdsuXEr9G+3n!>9F}5vUm~gqWCQG6su;dDR}6ye z8U#6}400Y5ulP@kf7Yp;`82t3bYRWuqnammho)t0g;0siubdbljob2X84?@k|wqbvPp7kBmQn7k#A_@T$qX zlAwFAM;K9gNUA}bWlx*+?#<#(R3l6)``ZG?p`u-4ZD-c)u(hq^Adgx?1564FPKZ?( zjz_v7GCX9r7y|XBeb(a__#=LJWJ* z(*mb5yW0t_xe1!f_A;^R#83sXAEvc_2QcW&V8C{l0a~C3XA*ZZY9M_90EK6p7ep89 z7d-|pK$Ydz;tX9%p;Cs<(U)^ktwTcN3#`;@DsEir(oDHcubKGaa0yc8L2=w>FKebny%zsM}`1(uj2P;*8`~5l=mr z9LL{)QDF2`QZC;yg)Rud$PQ~ESy@Z?pG`s2gDa$pKxn8}r6MJiOjOcSgo^JGdUP%h z%_62Dg0(GBa54dk#(k&UU3%#X6KEw!VxWk<4Kc8am)TN-rR3fl`zr{LV?MkhNX*!^ zs0%GaB_ZRX0% - summary.pop_data(strata = "Country") + summary(strata = "Country") saveRDS(object = summary_country,file = "tests/testthat/fixtures/summary_country.rds") diff --git a/man/dot-nll.Rd b/man/dot-nll.Rd index 2a4601e3..9f4fa97c 100644 --- a/man/dot-nll.Rd +++ b/man/dot-nll.Rd @@ -19,6 +19,6 @@ the negative log-likelihood of the data with the current parameter values } \description{ -Same as \code{\link[=log_likelihood]{log_likelihood()}}, except negated and requiring lambda on log scale (used in combination with \code{nlm()}, to ensure that the optimization search doesn't stray into negative values of \code{lambda}). +Same as \code{\link[=llik]{llik()}}, except negated and requiring lambda on log scale (used in combination with \code{nlm()}, to ensure that the optimization search doesn't stray into negative values of \code{lambda}). } \keyword{internal} diff --git a/tests/testthat/fixtures/summary_country.rds b/tests/testthat/fixtures/summary_country.rds index 35dcf4a777572ab994533c5725892210a93232f9..dc013bfbe5f4d505f14db6816e71cd61423e6998 100644 GIT binary patch literal 574 zcmV-E0>S+siwFP!0000029;DxZ__{!p4f??<)T&6k?)a z(HE9x3rv8Y5`jJKrDD(C=M{rJ4N}DZd+Xgy=b?S#dGqb7{ipWK<%6Z&@4Gp|x$Lk# z{~|-!97I@3R8XgXBT>vjPzxgI8KIZ2rtMM7?gWUaWgB!Oa9mGjW}cjlizsS&F>95Q zXDsgBZOIn$5o^2`Ns|0fsxU=>d9K%wXuKmY3H?ZzbBp{mUJuc|tRE@MINLZZBV!+Ef9j!ni~!%kfozN>$#*H(Iq$4?R}}wZ7Olx5 z^DG|f&|WO&GLhb2#PWaezTgoY{wNIie@Wx41AJ`m%HH~@TE^M%?Q`RS@p4q1$4$bi z@%bnFqv||v>&B;NUsju=YC+1s^o7q)Phgn5UlsCJMZd>UMEx#~9G~UzH=Inf>@vbh+$1DkrAu~rQH_|)18DInI+L*(Q-^iNTWa=cyakbW4V9AFJ?d@V?r5$v_?~Zc-9U67|xGfI)?34rft*xgIPCK~c=q03`nZ|Nj@w7wk|C?9Tb6c_l@a zFiUbX^Po(=w9KO7lK8^X#G;bSoK%>ba#K?>6Jcsta#P`KzLJd0q7-!X%(;mbknjMf zG7caOauypT^)WDE(kT96%SkOu&4C3B6D;w0i^?V^Xb3ylZx>dJCoy60<#>#Z*4qHt+%=!z8Q z--Dx8bvQR>q5TDE{g1PZnE$qwiws8x%f{G=(vC>#d?l8)FejWSji)Xg$;tc zRqXg|5n-1bSGQYf#OE*V`tK*yhGl^#Em}pp~$ic!YXNMv0(3omfs1KD(fMS}xh$%AQuc&1ks%0(+ zm@plF>XV;Y#KCbPlTMXaK#*@QSqEFxM}8K$<^F!bc)t(;yED9jPmuOkPk1!?Og?`SxG8Tp z_R!2-KP6ck?tlIsy-5DJj@C{s^`*LQ%ywVsA5V48)=2ooea~;Rra$V)-bt=MnEtp? zSWdoXFHhc-zb7}HT=%Va&%iIGJbfj#9{rq>Kjl|8F3qGuN3PZqiHTHv>szr@_VNy7 zJKnh4^0)6kZ%G*%og9H7pG%Jd)6akw9ymMoFSqhXhD92T*f*n^>Vm!UHU6sC>pyqx z5r`iRY(mc61i_XeyG$Hfg$k;wWmh04F2R1uqzq+M)p^qZj)XHPAE0%MFA0% filter(Country == "Pakistan"), - curve_params = curves, - noise_params = noise %>% filter(Country == "Pakistan"), - antigen_isos = c("HlyE_IgG", "HlyE_IgA") - ) - - xs_data_false <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = FALSE - ) - - est_false <- est.incidence( - pop_data = xs_data_false %>% filter(Country == "Pakistan"), - curve_params = curves, - noise_params = noise %>% filter(Country == "Pakistan"), - antigen_isos = c("HlyE_IgG", "HlyE_IgA") - ) - - expect_equal(est_true, est_false) -}) +# test_that("`est.incidence()` produces expected results", { +# curves <- load_curve_params("https://osf.io/download/rtw5k/") +# noise <- load_noise_params("https://osf.io/download//hqy4v/") +# xs_data_true <- load_pop_data( +# file_path = "https://osf.io/download//n6cp3/", +# age = "Age", +# value = "result", +# id = "index_id", +# standardize = TRUE +# ) +# +# est_true <- est.incidence( +# pop_data = xs_data_true %>% filter(Country == "Pakistan"), +# curve_params = curves, +# noise_params = noise %>% filter(Country == "Pakistan"), +# antigen_isos = c("HlyE_IgG", "HlyE_IgA") +# ) +# +# xs_data_false <- load_pop_data( +# file_path = "https://osf.io/download//n6cp3/", +# age = "Age", +# value = "result", +# id = "index_id", +# standardize = FALSE +# ) +# +# est_false <- est.incidence( +# pop_data = xs_data_false %>% filter(Country == "Pakistan"), +# curve_params = curves, +# noise_params = noise %>% filter(Country == "Pakistan"), +# antigen_isos = c("HlyE_IgG", "HlyE_IgA") +# ) +# +# expect_equal(est_true, est_false) +# }) diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index 8156194b..d069c667 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -37,6 +37,12 @@ test_that( ) %>% structure(noise.parameters = noise) + # define the path to the RDS file in the fixtures directory + typhoid_results_path <- test_path("fixtures", "typhoid_results.rds") + + # load the RDS file + typhoid_results <- readRDS(typhoid_results_path) + # compare with `typhoid_results` from data-raw/typhoid_results.qmd expect_equal( object = fit, diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 75933502..a0ccce3e 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -24,13 +24,13 @@ test_that("`summary.pop_data()` does not produce an error when stratified", { test_that("`summary.pop_data()` expected same results", { - # Define the path to the RDS file in the fixtures directory - summary_country_path <- test_path("fixtures", "summary_country.rds") - # Load the RDS file - summary_country <- readRDS(summary_country_path) + # define the path to the RDS file in the fixtures directory + summary_country_path <- test_path("fixtures", "summary_country.rds") + # load the RDS file + sum_country <- readRDS(summary_country_path) - expect_equal(object = xs_data %>% - summary(strata = "Country"), expected = summary_country) + expect_equal(object = xs_data %>% summary(strata = "Country"), + expected = sum_country) }) From 625d3bcae1acf9e73e074dc12d430be109c9f304 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 9 Jul 2024 12:42:04 -0400 Subject: [PATCH 24/33] simplify `summary.pop_data()` and associated tests --- .Rbuildignore | 3 + NAMESPACE | 1 + R/summary.pop_data.R | 97 +++++++++++--------- data-raw/summary_country.R | 13 --- man/summary.pop_data.Rd | 13 ++- tests/testthat/_snaps/summary.pop_data.md | 54 +++++++++++ tests/testthat/fixtures/summary_country.rds | Bin 574 -> 0 bytes tests/testthat/test-summary.pop_data.R | 21 +---- 8 files changed, 126 insertions(+), 76 deletions(-) delete mode 100644 data-raw/summary_country.R create mode 100644 tests/testthat/_snaps/summary.pop_data.md delete mode 100644 tests/testthat/fixtures/summary_country.rds diff --git a/.Rbuildignore b/.Rbuildignore index ee64eaaa..b74354e6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -22,3 +22,6 @@ allpopsamples_hlye.csv$ ^inst/extdata ^CRAN-SUBMISSION$ +^README\.qmd$ +^README_files$ +^codecov\.yml$ diff --git a/NAMESPACE b/NAMESPACE index d0b459fa..9d02f279 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ S3method(autoplot,seroincidence.by) S3method(autoplot,summary.seroincidence.by) S3method(print,seroincidence) S3method(print,seroincidence.by) +S3method(print,summary.pop_data) S3method(print,summary.seroincidence.by) S3method(strata,seroincidence.by) S3method(summary,pop_data) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index e4027db9..0048d90c 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -3,11 +3,15 @@ #' @description #' This function is a `summary()` method for `pop_data` objects #' -#' @param object a `pop_data` object -#' @param strata a [character()] providing the grouping column +#' @param object a `pop_data` object (from [as_pop_data()]) +#' @param strata a [character()] specifying grouping column(s) #' @param ... unused #' -#' @returns a list containing two summary tables: one of `age` and one of `value`, stratified by `antigen_iso` +#' @returns a `summary.pop_data` object, which is a list containing two summary tables: +#' +#' * `age_summary` summarizing `age` +#' * `ab_summary` summarizing `value`, stratified by `antigen_iso` +#' #' @export #' @examples #' library(dplyr) @@ -28,57 +32,64 @@ summary.pop_data <- function(object, strata = NULL, ...) { object %>% distinct(across(all_of(cols))) - cat("\nn =", nrow(ages), "\n") - - cat("\nDistribution of age: \n\n") - age_summary <- ages %>% summarise( + .by = all_of(strata), + n = n(), min = min(.data[[age_column]]), first_quartile = quantile(.data[[age_column]], 0.25), median = median(.data[[age_column]]), mean = mean(.data[[age_column]]), third_quartile = quantile(.data[[age_column]], 0.75), - max = max(.data[[age_column]]), - .by = all_of(strata) - ) %>% - print() - - cat("\nDistributions of antigen-isotype measurements:\n\n") + max = max(.data[[age_column]]) + ) ab_summary <- object %>% dplyr::summarize( .by = all_of(c("antigen_iso", strata)), - Min = object %>% - get_value() %>% - min(na.rm = TRUE), - `1st Qu.` = object %>% - get_value() %>% - quantile(.25, na.rm = TRUE), - Median = object %>% - get_value() %>% - median(), - `3rd Qu.` = object %>% - get_value() %>% - quantile(.75, na.rm = TRUE), - Max = object %>% - get_value() %>% - max(na.rm = TRUE), - `# NAs` = object %>% - get_value() %>% - is.na() %>% - sum() - ) %>% - as.data.frame() %>% - print() - - to_return <- list( - n = nrow(ages), - age_summary = age_summary, - ab_summary = ab_summary - ) - - return(invisible(to_return)) + across( + .cols = all_of(value_column), + .fns = list( + Min = ~ min(.x, na.rm = TRUE), + `1st Qu.` = ~ quantile(.x, p = .25, na.rm = TRUE), + Median = ~ median(.x, na.rm = TRUE), + `3rd Qu.` = ~ quantile(.x, p = .75, na.rm = TRUE), + Max = ~ max(.x, na.rm = TRUE), + `# NAs` = ~ is.na(.x) %>% sum() + ), + .names = "{.fn}" + )) + + to_return <- list(n = nrow(ages), + age_summary = age_summary, + ab_summary = ab_summary) + + class(to_return) = "summary.pop_data" + + return(to_return) +} + + +#' Print method for [summary.pop_data] objects +#' @rdname summary.pop_data +#' @export +print.summary.pop_data = function(x, ...) +{ + n_obs = x$age_summary %>% pull("n") %>% sum() + + cat("\nn =", n_obs, "\n") + + cat("\nDistribution of age: \n\n") + + x$age_summary %>% print() + + cat("\nDistributions of antigen-isotype measurements:\n\n") + + x$ab_summary %>% print() + + cat("\n") + + invisible(x) } diff --git a/data-raw/summary_country.R b/data-raw/summary_country.R deleted file mode 100644 index 7af3e453..00000000 --- a/data-raw/summary_country.R +++ /dev/null @@ -1,13 +0,0 @@ - -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) - -summary_country <- xs_data %>% - summary(strata = "Country") - -saveRDS(object = summary_country,file = "tests/testthat/fixtures/summary_country.rds") diff --git a/man/summary.pop_data.Rd b/man/summary.pop_data.Rd index b7b59276..70270519 100644 --- a/man/summary.pop_data.Rd +++ b/man/summary.pop_data.Rd @@ -2,19 +2,26 @@ % Please edit documentation in R/summary.pop_data.R \name{summary.pop_data} \alias{summary.pop_data} +\alias{print.summary.pop_data} \title{Summarize a cross-sectional antibody survey data set} \usage{ \method{summary}{pop_data}(object, strata = NULL, ...) + +\method{print}{summary.pop_data}(x, ...) } \arguments{ -\item{object}{a \code{pop_data} object} +\item{object}{a \code{pop_data} object (from \code{\link[=as_pop_data]{as_pop_data()}})} -\item{strata}{a \code{\link[=character]{character()}} providing the grouping column} +\item{strata}{a \code{\link[=character]{character()}} specifying grouping column(s)} \item{...}{unused} } \value{ -a list containing two summary tables: one of \code{age} and one of \code{value}, stratified by \code{antigen_iso} +a \code{summary.pop_data} object, which is a list containing two summary tables: +\itemize{ +\item \code{age_summary} summarizing \code{age} +\item \code{ab_summary} summarizing \code{value}, stratified by \code{antigen_iso} +} } \description{ This function is a \code{summary()} method for \code{pop_data} objects diff --git a/tests/testthat/_snaps/summary.pop_data.md b/tests/testthat/_snaps/summary.pop_data.md new file mode 100644 index 00000000..31775ed4 --- /dev/null +++ b/tests/testthat/_snaps/summary.pop_data.md @@ -0,0 +1,54 @@ +# `summary.pop_data()` produces stable results when `strata = NULL` + + Code + xs_data %>% summary(strata = NULL) + Output + + n = 3336 + + Distribution of age: + + # A tibble: 1 x 7 + n min first_quartile median mean third_quartile max + + 1 3336 0.6 5 10 10.5 15 25 + + Distributions of antigen-isotype measurements: + + # A tibble: 2 x 7 + antigen_iso Min `1st Qu.` Median `3rd Qu.` Max `# NAs` + + 1 HlyE_IgA 0 0.851 1.74 3.66 133. 0 + 2 HlyE_IgG 0 1.15 2.70 6.74 219. 0 + + +# `summary.pop_data()` produces stable results with stratification + + Code + xs_data %>% summary(strata = "Country") + Output + + n = 3336 + + Distribution of age: + + # A tibble: 3 x 8 + Country n min first_quartile median mean third_quartile max + + 1 Bangladesh 802 0.6 4.9 9.2 9.43 14 18 + 2 Nepal 1546 0.9 5.3 10.8 11.3 16.7 25 + 3 Pakistan 988 0.8 4.9 9 10.1 14.8 24.3 + + Distributions of antigen-isotype measurements: + + # A tibble: 6 x 8 + antigen_iso Country Min `1st Qu.` Median `3rd Qu.` Max `# NAs` + + 1 HlyE_IgA Bangladesh 0.0418 2.11 3.58 6.70 113. 0 + 2 HlyE_IgG Bangladesh 0.119 4.97 9.32 18.9 219. 0 + 3 HlyE_IgA Nepal 0 0.563 1.02 2.05 57.5 0 + 4 HlyE_IgG Nepal 0 0.897 1.62 3.37 184. 0 + 5 HlyE_IgA Pakistan 0 1.13 2.12 3.89 133. 0 + 6 HlyE_IgG Pakistan 0.192 1.04 2.40 5.15 135. 0 + + diff --git a/tests/testthat/fixtures/summary_country.rds b/tests/testthat/fixtures/summary_country.rds deleted file mode 100644 index dc013bfbe5f4d505f14db6816e71cd61423e6998..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 574 zcmV-E0>S+siwFP!0000029;DxZ__{!p4f??<)T&6k?)a z(HE9x3rv8Y5`jJKrDD(C=M{rJ4N}DZd+Xgy=b?S#dGqb7{ipWK<%6Z&@4Gp|x$Lk# z{~|-!97I@3R8XgXBT>vjPzxgI8KIZ2rtMM7?gWUaWgB!Oa9mGjW}cjlizsS&F>95Q zXDsgBZOIn$5o^2`Ns|0fsxU=>d9K%wXuKmY3H?ZzbBp{mUJuc|tRE@MINLZZBV!+Ef9j!ni~!%kfozN>$#*H(Iq$4?R}}wZ7Olx5 z^DG|f&|WO&GLhb2#PWaezTgoY{wNIie@Wx41AJ`m%HH~@TE^M%?Q`RS@p4q1$4$bi z@%bnFqv||v>&B;NUsju=YC+1s^o7q)Phgn5UlsCJMZd>UMEx#~9G~UzH=Inf>@vbh+$1DkrAu~rQH_|)18DInI+L*(Q-^iNTWa=cyakbW4V9AFJ?% summary(strata = NULL)) +test_that("`summary.pop_data()` produces stable results when `strata = NULL`", { + expect_snapshot(xs_data %>% summary(strata = NULL)) }) -test_that("`summary.pop_data()` does not produce an error when stratified", { - expect_no_error(object = xs_data %>% summary(strata = "Country")) -}) - - -test_that("`summary.pop_data()` expected same results", { - - # define the path to the RDS file in the fixtures directory - summary_country_path <- test_path("fixtures", "summary_country.rds") - - # load the RDS file - sum_country <- readRDS(summary_country_path) - - expect_equal(object = xs_data %>% summary(strata = "Country"), - expected = sum_country) +test_that("`summary.pop_data()` produces stable results with stratification", { + expect_snapshot(xs_data %>% summary(strata = "Country")) }) From fb1a84b7a216f960e09c00689493fb128b6af245 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Tue, 9 Jul 2024 12:53:54 -0400 Subject: [PATCH 25/33] polishing documentation --- R/summary.pop_data.R | 5 +++-- man/summary.pop_data.Rd | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index 0048d90c..bdb718c5 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -1,7 +1,7 @@ #' -#' @title Summarize a cross-sectional antibody survey data set +#' @title Summarize cross-sectional antibody survey data #' @description -#' This function is a `summary()` method for `pop_data` objects +#' [summary()] method for `pop_data` objects #' #' @param object a `pop_data` object (from [as_pop_data()]) #' @param strata a [character()] specifying grouping column(s) @@ -73,6 +73,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { #' Print method for [summary.pop_data] objects +#' @param x an object of class `"summary.pop_data"`; usually, the result of a call to [summary.pop_data()] #' @rdname summary.pop_data #' @export print.summary.pop_data = function(x, ...) diff --git a/man/summary.pop_data.Rd b/man/summary.pop_data.Rd index 70270519..63faaec2 100644 --- a/man/summary.pop_data.Rd +++ b/man/summary.pop_data.Rd @@ -3,7 +3,7 @@ \name{summary.pop_data} \alias{summary.pop_data} \alias{print.summary.pop_data} -\title{Summarize a cross-sectional antibody survey data set} +\title{Summarize cross-sectional antibody survey data} \usage{ \method{summary}{pop_data}(object, strata = NULL, ...) @@ -15,6 +15,8 @@ \item{strata}{a \code{\link[=character]{character()}} specifying grouping column(s)} \item{...}{unused} + +\item{x}{an object of class \code{"summary.pop_data"}; usually, the result of a call to \code{\link[=summary.pop_data]{summary.pop_data()}}} } \value{ a \code{summary.pop_data} object, which is a list containing two summary tables: @@ -24,7 +26,7 @@ a \code{summary.pop_data} object, which is a list containing two summary tables: } } \description{ -This function is a \code{summary()} method for \code{pop_data} objects +\code{\link[=summary]{summary()}} method for \code{pop_data} objects } \examples{ library(dplyr) From 3a8177e3b77672bf9dae65083c1a2eb6b17ec235 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 11 Jul 2024 12:33:03 +0300 Subject: [PATCH 26/33] make changes to the tests --- data-raw/nlm_exit_codes.R | 2 - tests/testthat/_snaps/est.incidence.md | 12 ++++++ tests/testthat/_snaps/summary.pop_data.md | 27 +++++++++++++ tests/testthat/test-est.incidence-status.R | 35 ---------------- tests/testthat/test-est.incidence.R | 47 +++++++++++++++++----- tests/testthat/test-summary.pop_data.R | 8 +--- 6 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 tests/testthat/_snaps/est.incidence.md create mode 100644 tests/testthat/_snaps/summary.pop_data.md delete mode 100644 tests/testthat/test-est.incidence-status.R diff --git a/data-raw/nlm_exit_codes.R b/data-raw/nlm_exit_codes.R index c22577ac..a472d7ce 100644 --- a/data-raw/nlm_exit_codes.R +++ b/data-raw/nlm_exit_codes.R @@ -5,5 +5,3 @@ nlm_exit_codes <- c( "4" = "4: iteration limit exceeded; increase `iterlim`.", "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." ) - -usethis::use_data(nlm_exit_codes, overwrite = TRUE, internal = TRUE) diff --git a/tests/testthat/_snaps/est.incidence.md b/tests/testthat/_snaps/est.incidence.md new file mode 100644 index 00000000..6c19b509 --- /dev/null +++ b/tests/testthat/_snaps/est.incidence.md @@ -0,0 +1,12 @@ +# est.incidence() produces expected results for typhoid data + + Code + typhoid_results + Output + # A tibble: 1 x 11 + est.start incidence.rate SE CI.lwr CI.upr coverage log.lik iterations + * + 1 0.1 0.128 0.00682 0.115 0.142 0.95 -2376. 4 + # i 3 more variables: antigen.isos , nlm.convergence.code , + # antigen.iso + diff --git a/tests/testthat/_snaps/summary.pop_data.md b/tests/testthat/_snaps/summary.pop_data.md new file mode 100644 index 00000000..5317752b --- /dev/null +++ b/tests/testthat/_snaps/summary.pop_data.md @@ -0,0 +1,27 @@ +# `summary.pop_data()` expected same results + + Code + xs_data %>% summary(strata = "Country") + Output + + n = 3336 + + Distribution of age: + + # A tibble: 3 x 7 + Country min first_quartile median mean third_quartile max + + 1 Bangladesh 0.6 4.9 9.2 9.43 14 18 + 2 Nepal 0.9 5.3 10.8 11.3 16.7 25 + 3 Pakistan 0.8 4.9 9 10.1 14.8 24.3 + + Distributions of antigen-isotype measurements: + + antigen_iso Country Min 1st Qu. Median 3rd Qu. Max # NAs + 1 HlyE_IgA Bangladesh 0 0.9810911 2.123017 5.000199 218.6229 0 + 2 HlyE_IgG Bangladesh 0 0.9810911 2.123017 5.000199 218.6229 0 + 3 HlyE_IgA Nepal 0 0.9810911 2.123017 5.000199 218.6229 0 + 4 HlyE_IgG Nepal 0 0.9810911 2.123017 5.000199 218.6229 0 + 5 HlyE_IgA Pakistan 0 0.9810911 2.123017 5.000199 218.6229 0 + 6 HlyE_IgG Pakistan 0 0.9810911 2.123017 5.000199 218.6229 0 + diff --git a/tests/testthat/test-est.incidence-status.R b/tests/testthat/test-est.incidence-status.R deleted file mode 100644 index a579e6dd..00000000 --- a/tests/testthat/test-est.incidence-status.R +++ /dev/null @@ -1,35 +0,0 @@ -# test_that("`est.incidence()` produces expected results", { -# curves <- load_curve_params("https://osf.io/download/rtw5k/") -# noise <- load_noise_params("https://osf.io/download//hqy4v/") -# xs_data_true <- load_pop_data( -# file_path = "https://osf.io/download//n6cp3/", -# age = "Age", -# value = "result", -# id = "index_id", -# standardize = TRUE -# ) -# -# est_true <- est.incidence( -# pop_data = xs_data_true %>% filter(Country == "Pakistan"), -# curve_params = curves, -# noise_params = noise %>% filter(Country == "Pakistan"), -# antigen_isos = c("HlyE_IgG", "HlyE_IgA") -# ) -# -# xs_data_false <- load_pop_data( -# file_path = "https://osf.io/download//n6cp3/", -# age = "Age", -# value = "result", -# id = "index_id", -# standardize = FALSE -# ) -# -# est_false <- est.incidence( -# pop_data = xs_data_false %>% filter(Country == "Pakistan"), -# curve_params = curves, -# noise_params = noise %>% filter(Country == "Pakistan"), -# antigen_isos = c("HlyE_IgG", "HlyE_IgA") -# ) -# -# expect_equal(est_true, est_false) -# }) diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index d069c667..cfe461c1 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -37,16 +37,45 @@ test_that( ) %>% structure(noise.parameters = noise) - # define the path to the RDS file in the fixtures directory - typhoid_results_path <- test_path("fixtures", "typhoid_results.rds") - # load the RDS file - typhoid_results <- readRDS(typhoid_results_path) + typhoid_results <- readRDS(test_path("fixtures", "typhoid_results.rds")) - # compare with `typhoid_results` from data-raw/typhoid_results.qmd - expect_equal( - object = fit, - expected = typhoid_results - ) + expect_snapshot(x = typhoid_results) } ) + +test_that("`est.incidence()` produces expected results", { + curves <- load_curve_params("https://osf.io/download/rtw5k/") + noise <- load_noise_params("https://osf.io/download//hqy4v/") + xs_data_true <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = TRUE + ) + + est_true <- est.incidence( + pop_data = xs_data_true %>% filter(Country == "Pakistan"), + curve_params = curves, + noise_params = noise %>% filter(Country == "Pakistan"), + antigen_isos = c("HlyE_IgG", "HlyE_IgA") + ) + + xs_data_false <- load_pop_data( + file_path = "https://osf.io/download//n6cp3/", + age = "Age", + value = "result", + id = "index_id", + standardize = FALSE + ) + + est_false <- est.incidence( + pop_data = xs_data_false %>% filter(Country == "Pakistan"), + curve_params = curves, + noise_params = noise %>% filter(Country == "Pakistan"), + antigen_isos = c("HlyE_IgG", "HlyE_IgA") + ) + + expect_equal(est_true, est_false) +}) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index a0ccce3e..0e6b5b72 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -25,12 +25,8 @@ test_that("`summary.pop_data()` does not produce an error when stratified", { test_that("`summary.pop_data()` expected same results", { - # define the path to the RDS file in the fixtures directory - summary_country_path <- test_path("fixtures", "summary_country.rds") - # load the RDS file - sum_country <- readRDS(summary_country_path) + sum_country <- readRDS(test_path("fixtures", "summary_country.rds")) - expect_equal(object = xs_data %>% summary(strata = "Country"), - expected = sum_country) + expect_snapshot(x = xs_data %>% summary(strata = "Country")) }) From d4953111deffd5a60aa23227b7f4e5693906816f Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Thu, 11 Jul 2024 21:46:19 +0300 Subject: [PATCH 27/33] remove merge conflicts --- tests/testthat/test-summary.pop_data.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 02186520..298f712e 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -20,3 +20,4 @@ test_that("`summary.pop_data()` produces stable results when `strata = NULL`", { test_that("`summary.pop_data()` produces stable results with stratification", { expect_snapshot(xs_data %>% summary(strata = "Country")) +}) From debcee20d0b227da63e1fda8284675a579fd5688 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Fri, 12 Jul 2024 11:13:39 +0300 Subject: [PATCH 28/33] add snap file for tests --- tests/testthat/_snaps/summary.pop_data.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/testthat/_snaps/summary.pop_data.md b/tests/testthat/_snaps/summary.pop_data.md index 8669526b..31775ed4 100644 --- a/tests/testthat/_snaps/summary.pop_data.md +++ b/tests/testthat/_snaps/summary.pop_data.md @@ -1,4 +1,3 @@ - # `summary.pop_data()` produces stable results when `strata = NULL` Code @@ -23,7 +22,15 @@ 2 HlyE_IgG 0 1.15 2.70 6.74 219. 0 -# `summary.pop_data()` produces stable results with stratification +# `summary.pop_data()` produces stable results with stratification + + Code + xs_data %>% summary(strata = "Country") + Output + + n = 3336 + + Distribution of age: # A tibble: 3 x 8 Country n min first_quartile median mean third_quartile max @@ -43,5 +50,5 @@ 4 HlyE_IgG Nepal 0 0.897 1.62 3.37 184. 0 5 HlyE_IgA Pakistan 0 1.13 2.12 3.89 133. 0 6 HlyE_IgG Pakistan 0.192 1.04 2.40 5.15 135. 0 - + From 6a83cccfcca133b885ced2722e28e93cf44d5352 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Fri, 12 Jul 2024 16:43:56 -0400 Subject: [PATCH 29/33] error = TRUE --- inst/WORDLIST | 5 +++++ tests/spelling.R | 2 +- vignettes/articles/enteric_fever_example.Rmd | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/inst/WORDLIST b/inst/WORDLIST index 9d8bfcc4..11befee7 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -130,3 +130,8 @@ titers tsutsugamushi unstratified varepsilon +SeroEpidemiology +callout +codecov +geoms +ggproto diff --git a/tests/spelling.R b/tests/spelling.R index 6713838f..e55675da 100644 --- a/tests/spelling.R +++ b/tests/spelling.R @@ -1,3 +1,3 @@ if(requireNamespace('spelling', quietly = TRUE)) - spelling::spell_check_test(vignettes = TRUE, error = FALSE, + spelling::spell_check_test(vignettes = TRUE, error = TRUE, skip_on_cran = TRUE) diff --git a/vignettes/articles/enteric_fever_example.Rmd b/vignettes/articles/enteric_fever_example.Rmd index 7cef26dc..3a213633 100644 --- a/vignettes/articles/enteric_fever_example.Rmd +++ b/vignettes/articles/enteric_fever_example.Rmd @@ -15,9 +15,9 @@ bibliography: references.bib --- ## Introduction -This vignette provides users with an example analysis using the [**serocalculator**](https://github.com/UCD-SERG/serocalculator) package by reproducing the analysis for: [**Estimating typhoid incidence from community-based serosurveys: a multicohort study**](https://www.thelancet.com/journals/lanmic/article/PIIS2666-5247(22)00114-8/fulltext) (@Aiemjoy_2022_Lancet). We review the methods underlying the analysis and then walk through an example of enteric fever incidence in Pakistan. Note that because this is a simplied version of the analysis, the results here will differ slightly from those presented in the publication. +This vignette provides users with an example analysis using the [**serocalculator**](https://github.com/UCD-SERG/serocalculator) package by reproducing the analysis for: [**Estimating typhoid incidence from community-based serosurveys: a multicohort study**](https://www.thelancet.com/journals/lanmic/article/PIIS2666-5247(22)00114-8/fulltext) (@Aiemjoy_2022_Lancet). We review the methods underlying the analysis and then walk through an example of enteric fever incidence in Pakistan. Note that because this is a simplified version of the analysis, the results here will differ slightly from those presented in the publication. -In this example, users will determine the seroincidence of enteric fever in cross-sectional serosurveys conducted as part of the the SeroEpidemiology and Environmental Surveillance (SEES) for enteric fever study in Bangladesh, Nepal, and Pakistan. Longitudinal antibody responses were modeled from 1420 blood culture-confirmed enteric fever cases enrolled from the same countries. +In this example, users will determine the seroincidence of enteric fever in cross-sectional serosurveys conducted as part of the SeroEpidemiology and Environmental Surveillance (SEES) for enteric fever study in Bangladesh, Nepal, and Pakistan. Longitudinal antibody responses were modeled from 1420 blood culture-confirmed enteric fever cases enrolled from the same countries. ```{r, include = FALSE} From 871693e26cf239a45e0fb6ef9a3a37d0bff93a2f Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Fri, 12 Jul 2024 16:56:35 -0400 Subject: [PATCH 30/33] removing sysdata --- {data-raw => R}/nlm_exit_codes.R | 0 R/sysdata.rda | Bin 512 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) rename {data-raw => R}/nlm_exit_codes.R (100%) delete mode 100644 R/sysdata.rda diff --git a/data-raw/nlm_exit_codes.R b/R/nlm_exit_codes.R similarity index 100% rename from data-raw/nlm_exit_codes.R rename to R/nlm_exit_codes.R diff --git a/R/sysdata.rda b/R/sysdata.rda deleted file mode 100644 index a9e7e38937a1547b9467fe7843b7c7c99fb42c3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmV+b0{{I&T4*^jL0KkKS<+PDy#N4?|AhWAKmb5zei#M?5J3O$-|z$g0s%k)+}W*I zhNqPpa3)jLCLX6T0q*E)BRu(!PsJ}COi6gCQ@mrUYjs7U`d$?odY@;IjwR# zCTjHUOW2OsZNQq>;PQBs&p#PfAq0q>dfDeyVvIHMXR9~M?;LbomF2LL7`L>#6&*7n zlmLQJ&X(VoaK&p}p~i_xwdVb;7V5yX^F&JmjrZ{1eczV{5plz&)1b~g=AWZyLL2=lB;x2*qRExH(c;%PCE{ZCSte8(iGDP3?vZ}(MXLj zsF$QvP!k0$Ffh?4)d7a$_rV^N^V~AYK&nwN97=gZOc!DGtWaTtwWz7N*1rLI^PIu<35|VQO zP^6{_;0eY|JVDtiK0+w8bq1;hOYb9RPGkgX41x;k79Oh-agShsi@744C`f54aNdAP C*W`8p From b4546d2e598c3fb5bdd0338188f5e720edcdd1d9 Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Sat, 13 Jul 2024 12:52:14 +0300 Subject: [PATCH 31/33] make corrections to tests --- R/sysdata.rda | Bin 512 -> 0 bytes data-raw/nlm_exit_codes.R | 1 + data-raw/typhoid_results.qmd | 77 -------------------- tests/testthat/fixtures/typhoid_results.rds | Bin 732 -> 0 bytes tests/testthat/test-est.incidence.R | 5 +- 5 files changed, 2 insertions(+), 81 deletions(-) delete mode 100644 R/sysdata.rda delete mode 100644 data-raw/typhoid_results.qmd delete mode 100644 tests/testthat/fixtures/typhoid_results.rds diff --git a/R/sysdata.rda b/R/sysdata.rda deleted file mode 100644 index a9e7e38937a1547b9467fe7843b7c7c99fb42c3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmV+b0{{I&T4*^jL0KkKS<+PDy#N4?|AhWAKmb5zei#M?5J3O$-|z$g0s%k)+}W*I zhNqPpa3)jLCLX6T0q*E)BRu(!PsJ}COi6gCQ@mrUYjs7U`d$?odY@;IjwR# zCTjHUOW2OsZNQq>;PQBs&p#PfAq0q>dfDeyVvIHMXR9~M?;LbomF2LL7`L>#6&*7n zlmLQJ&X(VoaK&p}p~i_xwdVb;7V5yX^F&JmjrZ{1eczV{5plz&)1b~g=AWZyLL2=lB;x2*qRExH(c;%PCE{ZCSte8(iGDP3?vZ}(MXLj zsF$QvP!k0$Ffh?4)d7a$_rV^N^V~AYK&nwN97=gZOc!DGtWaTtwWz7N*1rLI^PIu<35|VQO zP^6{_;0eY|JVDtiK0+w8bq1;hOYb9RPGkgX41x;k79Oh-agShsi@744C`f54aNdAP C*W`8p diff --git a/data-raw/nlm_exit_codes.R b/data-raw/nlm_exit_codes.R index a472d7ce..82711539 100644 --- a/data-raw/nlm_exit_codes.R +++ b/data-raw/nlm_exit_codes.R @@ -5,3 +5,4 @@ nlm_exit_codes <- c( "4" = "4: iteration limit exceeded; increase `iterlim`.", "5" = "5: maximum step size `stepmax` exceeded five consecutive times. Either the function is unbounded below, becomes asymptotic to a finite value from above in some direction or `stepmax` is too small." ) + diff --git a/data-raw/typhoid_results.qmd b/data-raw/typhoid_results.qmd deleted file mode 100644 index f1bdb33b..00000000 --- a/data-raw/typhoid_results.qmd +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: "typhoid_results" -format: html ---- - - - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - -```{r setup} -# library(devtools) -# install_github("UCD-SERG/serocalculator") -library(serocalculator) -library(tidyverse) -``` - -```{r longdata} - -# pop data -xs_data <- load_pop_data( - file_path = "https://osf.io/download//n6cp3/", - age = "Age", - value = "result", - id = "index_id", - standardize = TRUE -) %>% - filter(Country == 'Pakistan') - - -# get curve data -curve <- load_curve_params("https://osf.io/download/rtw5k/") - -``` - -``` {r simdata} -# get noise data -noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% - filter(Country == 'Pakistan') - -``` - - -```{r seroinc} -start <- .05 - -lambda <- start # initial estimate: starting value -log.lambda <- log(lambda) -log.lmin <- log(lambda / 10) -log.lmax <- log(10 * lambda) - -fit <- est.incidence( - pop_data = xs_data, - curve_param = curve, - noise_param = noise, - antigen_isos = c("HlyE_IgG", "HlyE_IgA") - -typhoid_results <- fit %>% - summary.seroincidence( - coverage = .95, - start = start - ) %>% - mutate( - ageCat = NULL, - antigen.iso = paste(collapse = "+", "HlyE_IgG") - ) %>% - structure(noise.parameters = noise) - -usethis::use_data(typhoid_results, internal = TRUE, overwrite = TRUE) - - - -``` diff --git a/tests/testthat/fixtures/typhoid_results.rds b/tests/testthat/fixtures/typhoid_results.rds deleted file mode 100644 index acf78a582b1e5b0bb5c1226af990cad88e90b141..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 732 zcmV<20wet&iwFP!000002CY-wOB7KQpPij`Km5qlAgT8VbAo*7MRwJ6l{OJKQ_$G% z&fFabXYVZc&blo@1Vug?^isV9QvX12Jp^hIWKj7~y%cN@LN5uuL_xUSS??LfsUV?& zGjo3Do;e@){LV~5lBBStC?P2v;i?pwIzQ5Tn%g=#Xy($!C6s)8*M07Jcy;!}i^?V^Xb3ylZx>dJCoy60<#>#Z*4qHt+%=!z8Q z--Dx8bvQR>q5TDE{g1PZnE$qwiws8x%f{G=(vC>#d?l8)FejWSji)Xg$;tc zRqXg|5n-1bSGQYf#OE*V`tK*yhGl^#Em}pp~$ic!YXNMv0(3omfs1KD(fMS}xh$%AQuc&1ks%0(+ zm@plF>XV;Y#KCbPlTMXaK#*@QSqEFxM}8K$<^F!bc)t(;yED9jPmuOkPk1!?Og?`SxG8Tp z_R!2-KP6ck?tlIsy-5DJj@C{s^`*LQ%ywVsA5V48)=2ooea~;Rra$V)-bt=MnEtp? zSWdoXFHhc-zb7}HT=%Va&%iIGJbfj#9{rq>Kjl|8F3qGuN3PZqiHTHv>szr@_VNy7 zJKnh4^0)6kZ%G*%og9H7pG%Jd)6akw9ymMoFSqhXhD92T*f*n^>Vm!UHU6sC>pyqx z5r`iRY(mc61i_XeyG$Hfg$k;wWmh04F2R1uqzq+M)p^qZj)XHPAE0%MFA0% structure(noise.parameters = noise) - # load the RDS file - typhoid_results <- readRDS(test_path("fixtures", "typhoid_results.rds")) - expect_snapshot(x = typhoid_results) } ) From a82fedec415c0024dd582632494678540e69281b Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Sat, 13 Jul 2024 22:16:04 +0300 Subject: [PATCH 32/33] address document errors --- NAMESPACE | 9 +++++++++ R/load_pop_data.R | 10 ++++++++++ man/plot_curve_params_one_ab.Rd | 32 ++++++++++++++++++++++++-------- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index d0b459fa..67dabb29 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,9 +6,18 @@ S3method(autoplot,pop_data) S3method(autoplot,seroincidence) S3method(autoplot,seroincidence.by) S3method(autoplot,summary.seroincidence.by) +S3method(get_age,pop_data) +S3method(get_age_var,pop_data) +S3method(get_id,pop_data) +S3method(get_id_var,pop_data) +S3method(get_value,pop_data) +S3method(get_value_var,pop_data) S3method(print,seroincidence) S3method(print,seroincidence.by) S3method(print,summary.seroincidence.by) +S3method(set_age,pop_data) +S3method(set_id,pop_data) +S3method(set_value,pop_data) S3method(strata,seroincidence.by) S3method(summary,pop_data) S3method(summary,seroincidence) diff --git a/R/load_pop_data.R b/R/load_pop_data.R index 451af4aa..a8362653 100644 --- a/R/load_pop_data.R +++ b/R/load_pop_data.R @@ -50,6 +50,7 @@ get_age <- function(object, ...) { UseMethod("get_age", object) } +#' @export get_age.pop_data <- function(object, ...) { # get age data age_data <- object %>% pull(attr(object, "age_var")) @@ -61,6 +62,7 @@ get_age_var <- function(object, ...) { UseMethod("get_age_var", object) } +#' @export get_age_var.pop_data <- function(object, ...) { # get value attribute age_var <- attributes(object)$age_var @@ -72,6 +74,7 @@ get_value <- function(object, ...) { UseMethod("get_value", object) } +#' @export get_value.pop_data <- function(object, ...) { # get age data value_data <- object %>% pull(attr(object, "value_var")) @@ -83,6 +86,7 @@ get_value_var <- function(object, ...) { UseMethod("get_value_var", object) } +#' @export get_value_var.pop_data <- function(object, ...) { # get value attribute value_var <- attributes(object)$value_var @@ -94,6 +98,7 @@ get_id <- function(object, ...) { UseMethod("get_id", object) } +#' @export get_id.pop_data <- function(object, ...) { # get age data id_data <- object %>% pull(attr(object, "id_var")) @@ -105,6 +110,7 @@ get_id_var <- function(object, ...) { UseMethod("get_id_var", object) } +#' @export get_id_var.pop_data <- function(object, ...) { # get value attribute id_var <- attributes(object)$id_var @@ -112,10 +118,12 @@ get_id_var.pop_data <- function(object, ...) { return(id_var) } + set_age <- function(object, ...) { UseMethod("set_age", object) } +#' @export set_age.pop_data <- function(object, age = "Age", standardize = TRUE, ...) { # check if age column exists if (age %in% colnames(object)) { @@ -163,6 +171,7 @@ set_value <- function(object, ...) { UseMethod("set_value", object) } +#' @export set_value.pop_data <- function(object, value = "result", standardize = TRUE, ...) { # check if value column exists if (value %in% colnames(object)) { @@ -209,6 +218,7 @@ set_id <- function(object, ...) { UseMethod("set_id", object) } +#' @export set_id.pop_data <- function(object, id = "index_id", standardize = TRUE, ...) { # check if id column exists if (id %in% colnames(object)) { diff --git a/man/plot_curve_params_one_ab.Rd b/man/plot_curve_params_one_ab.Rd index 868cb5f3..e5739f2d 100644 --- a/man/plot_curve_params_one_ab.Rd +++ b/man/plot_curve_params_one_ab.Rd @@ -48,14 +48,30 @@ plot_curve_params_one_ab( at the top level of the plot. You must supply \code{mapping} if there is no plot mapping.} \item{\code{data}}{Ignored by \code{stat_function()}, do not use.} - \item{\code{stat}}{The statistical transformation to use on the data for this -layer, either as a \code{ggproto} \code{Geom} subclass or as a string naming the -stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than -\code{"stat_count"})} - \item{\code{position}}{Position adjustment, either as a string naming the adjustment -(e.g. \code{"jitter"} to use \code{position_jitter}), or the result of a call to a -position adjustment function. Use the latter if you need to change the -settings of the adjustment.} + \item{\code{stat}}{The statistical transformation to use on the data for this layer. +When using a \verb{geom_*()} function to construct a layer, the \code{stat} +argument can be used the override the default coupling between geoms and +stats. The \code{stat} argument accepts the following: +\itemize{ +\item A \code{Stat} ggproto subclass, for example \code{StatCount}. +\item A string naming the stat. To give the stat as a string, strip the +function name of the \code{stat_} prefix. For example, to use \code{stat_count()}, +give the stat as \code{"count"}. +\item For more information and other ways to specify the stat, see the +\link[ggplot2:layer_stats]{layer stat} documentation. +}} + \item{\code{position}}{A position adjustment to use on the data for this layer. This +can be used in various ways, including to prevent overplotting and +improving the display. The \code{position} argument accepts the following: +\itemize{ +\item The result of calling a position function, such as \code{position_jitter()}. +This method allows for passing extra arguments to the position. +\item A string naming the position adjustment. To give the position as a +string, strip the function name of the \code{position_} prefix. For example, +to use \code{position_jitter()}, give the position as \code{"jitter"}. +\item For more information and other ways to specify the position, see the +\link[ggplot2:layer_positions]{layer position} documentation. +}} \item{\code{na.rm}}{If \code{FALSE}, the default, missing values are removed with a warning. If \code{TRUE}, missing values are silently removed.} \item{\code{show.legend}}{logical. Should this layer be included in the legends? From 2b03196dc53d429704c277cde4c1166391e72e00 Mon Sep 17 00:00:00 2001 From: Douglas Ezra Morrison Date: Sat, 13 Jul 2024 16:55:27 -0400 Subject: [PATCH 33/33] ignore readme source file and codecov config file --- .Rbuildignore | 2 ++ DESCRIPTION | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 548e44ee..f962eb22 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,3 +21,5 @@ allpopsamples_hlye.csv$ ^serocalculator.*\.tgz$ ^inst/extdata ^CRAN-SUBMISSION$ +^README\.qmd$ +^codecov\.yml$ diff --git a/DESCRIPTION b/DESCRIPTION index 2ff1e920..fe03659a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,7 +47,7 @@ Suggests: LazyData: true Encoding: UTF-8 URL: https://github.com/UCD-SERG/serocalculator, https://ucd-serg.github.io/serocalculator/ -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 NeedsCompilation: no LinkingTo: Rcpp