Skip to content

Commit

Permalink
fix: add input check for age_mean_f column (#123)
Browse files Browse the repository at this point in the history
add input check for `age_mean_f` in `serodata` in the following functions
- `prepare_serodata`
- `prepare_bin_data`
  • Loading branch information
ntorresd committed Oct 11, 2023
1 parent ba190dc commit cd1834c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 10 additions & 5 deletions R/seroprevalence_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' \code{antibody} \tab antibody \cr \tab \cr
#' }
#' @param alpha probability of a type I error. For further details refer to \link[Hmisc]{binconf}.
#' @param add_age_mean_f TBD
#' @return serodata with additional columns necessary for the analysis. These columns are:
#' \tabular{ll}{
#' \code{age_mean_f} \tab Floor value of the average between age_min and age_max \cr \tab \cr
Expand All @@ -33,11 +32,13 @@
#' serodata <- prepare_serodata(chagas2012)
#' @export
prepare_serodata <- function(serodata = serodata,
alpha = 0.05,
add_age_mean_f = TRUE) {
if(add_age_mean_f){
alpha = 0.05) {
if(!any(colnames(serodata) == "age_mean_f")){
serodata <- serodata %>%
dplyr::mutate(age_mean_f = floor((age_min + age_max) / 2), sample_size = sum(total))
}
if(!any(colnames(serodata) == "birth_year")){
serodata <- serodata %>%
dplyr::mutate(age_mean_f = floor((age_min + age_max) / 2), sample_size = sum(total)) %>%
dplyr::mutate(birth_year = .data$tsur - .data$age_mean_f)
}
serodata <- serodata %>%
Expand Down Expand Up @@ -74,6 +75,10 @@ prepare_serodata <- function(serodata = serodata,
#' prepare_bin_data(serodata)
#' @export
prepare_bin_data <- function(serodata) {
if(!any(colnames(serodata) == "age_mean_f")){
serodata <- serodata %>%
dplyr::mutate(age_mean_f = floor((age_min + age_max) / 2), sample_size = sum(total))
}
serodata$cut_ages <-
cut(as.numeric(serodata$age_mean_f),
seq(1, 101, by = 5),
Expand Down
4 changes: 1 addition & 3 deletions man/prepare_serodata.Rd

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

0 comments on commit cd1834c

Please sign in to comment.