From 25d5e71a7cab1e93363400646e828bd0a4a3446b Mon Sep 17 00:00:00 2001 From: Chris Orwa Date: Tue, 29 Oct 2024 10:47:05 +0300 Subject: [PATCH] change pipes --- NAMESPACE | 1 - R/add_point_to_graph.R | 2 +- R/as_curve_params.R | 10 ++-- R/as_noise_params.R | 6 +- R/as_pop_data.R | 14 ++--- R/autoplot.curve_params.R | 14 ++--- R/autoplot.pop_data.R | 30 +++++----- R/autoplot.seroincidence.R | 8 +-- R/autoplot.seroincidence.by.R | 10 ++-- R/autoplot.summary.seroincidence.by.R | 10 ++-- R/check_parallel_cores.R | 2 +- R/check_pop_data.R | 14 ++--- R/class_attributes.R | 20 +++---- R/count_strata.R | 10 ++-- R/csdata_wide_to_long.R | 4 +- R/df_to_array.R | 20 +++---- R/est.incidence.R | 48 +++++++-------- R/est.incidence.by.R | 34 +++++------ R/f_dev.r | 28 ++++----- R/get_curve_params_one_antigen.R | 6 +- R/get_xspd_one_antigen.R | 6 +- R/graph.curve.params.R | 30 +++++----- R/graph.decay.curves.R | 6 +- R/graph.loglik.R | 12 ++-- R/load_curve_params.R | 6 +- R/load_noise_params.R | 6 +- R/load_pop_data.R | 4 +- R/log_likelihood.R | 12 ++-- R/prep_curve_params_for_array.R | 16 ++--- R/print.seroincidence.by.R | 2 +- R/print.summary.seroincidence.by.R | 4 +- R/serocalculator-package.R | 2 +- R/set_biomarker_var.R | 2 +- R/sim.cs.R | 28 ++++----- R/sim.cs.multi.R | 6 +- R/simresp.tinf.R | 4 +- R/stratify_data.R | 60 +++++++++---------- R/summary.pop_data.R | 20 +++---- R/summary.seroincidence.R | 22 +++---- R/summary.seroincidence.by.R | 24 ++++---- R/warn_missing_strata.R | 8 +-- data-raw/profile-fdev.R | 10 ++-- data-raw/sees_datacleaning.R | 40 ++++++------- data-raw/typhoid-controls.R | 2 +- data-raw/typhoid_results.R | 10 ++-- man/as_curve_params.Rd | 4 +- man/as_noise_params.Rd | 4 +- man/as_pop_data.Rd | 4 +- man/autoplot.curve_params.Rd | 6 +- man/autoplot.pop_data.Rd | 4 +- man/autoplot.seroincidence.Rd | 8 +-- man/autoplot.seroincidence.by.Rd | 10 ++-- man/autoplot.summary.seroincidence.by.Rd | 8 +-- man/check_pop_data.Rd | 2 +- man/df_to_array.Rd | 6 +- man/est.incidence.Rd | 10 ++-- man/est.incidence.by.Rd | 10 ++-- man/f_dev.Rd | 14 ++--- man/f_dev0.Rd | 14 ++--- man/graph_loglik.Rd | 6 +- man/log_likelihood.Rd | 4 +- man/plot_curve_params_one_ab.Rd | 6 +- man/stratify_data.Rd | 6 +- man/summary.seroincidence.Rd | 8 +-- man/summary.seroincidence.by.Rd | 8 +-- tests/testthat/_snaps/df_to_array.md | 5 +- tests/testthat/_snaps/summary.pop_data.md | 4 +- tests/testthat/test-as_curve_params.R | 14 ++--- tests/testthat/test-as_noise_params.R | 14 ++--- tests/testthat/test-autoplot.pop_data.R | 16 ++--- tests/testthat/test-check_pop_data.R | 16 ++--- tests/testthat/test-class_attributes.R | 20 +++---- tests/testthat/test-df_to_array.R | 8 +-- tests/testthat/test-est.incidence.R | 20 +++---- tests/testthat/test-f_dev.R | 14 ++--- tests/testthat/test-load_pop_data.R | 4 +- tests/testthat/test-log_likelihood.R | 2 +- tests/testthat/test-set_biomarker_var.R | 6 +- tests/testthat/test-stratify_data.R | 20 +++---- tests/testthat/test-summary.pop_data.R | 6 +- tests/testthat/test-warn_missing_strata.R | 8 +-- .../articles/_antibody-response-model.qmd | 8 +-- vignettes/articles/enteric_fever_example.Rmd | 26 ++++---- vignettes/articles/scrubTyphus_example.Rmd | 20 +++---- .../articles/simulate_xsectionalData.Rmd | 34 +++++------ vignettes/methodology.qmd | 8 +-- 86 files changed, 525 insertions(+), 523 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 433fd515..d4eaf321 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -70,7 +70,6 @@ importFrom(ggplot2,aes) importFrom(ggplot2,autoplot) importFrom(ggplot2,ggplot) importFrom(lifecycle,deprecated) -importFrom(magrittr,"%>%") importFrom(mixtools,normalmixEM) importFrom(rlang,.data) importFrom(rlang,.env) diff --git a/R/add_point_to_graph.R b/R/add_point_to_graph.R index 2da2e54a..d28e20cf 100644 --- a/R/add_point_to_graph.R +++ b/R/add_point_to_graph.R @@ -4,7 +4,7 @@ add_point_to_graph <- function( name = "est.incidence", point_data = tibble( - x = fit$estimate %>% exp(), + x = fit$estimate |> exp(), y = log_likelihood(.data$x, ...), label = "est.incidence" ), diff --git a/R/as_curve_params.R b/R/as_curve_params.R index 6dac7101..a20cfad6 100644 --- a/R/as_curve_params.R +++ b/R/as_curve_params.R @@ -9,8 +9,8 @@ #' @examples #' library(magrittr) #' curve_data <- -#' "https://osf.io/download/rtw5k/" %>% -#' readr::read_rds() %>% +#' "https://osf.io/download/rtw5k/" |> +#' readr::read_rds() |> #' as_curve_params() #' #' print(curve_data) @@ -29,7 +29,7 @@ as_curve_params <- function(data, antigen_isos = NULL) { } curve_data <- - data %>% + data |> tibble::as_tibble() # check if object has expected columns: @@ -38,7 +38,7 @@ as_curve_params <- function(data, antigen_isos = NULL) { curve_cols <- c("antigen_iso", "y0", "y1", "t1", "alpha", "r") # get columns from provided data - data_cols <- data %>% names() + data_cols <- data |> names() # get any missing column(s) missing_cols <- setdiff(x = curve_cols, y = data_cols) @@ -70,7 +70,7 @@ as_curve_params <- function(data, antigen_isos = NULL) { # assign antigen attribute attr(curve_data, "antigen_isos") <- antigen_isos - curve_data <- curve_data %>% + curve_data <- curve_data |> set_biomarker_var(biomarker = "antigen_iso", standardize = FALSE) return(curve_data) diff --git a/R/as_noise_params.R b/R/as_noise_params.R index 1a073677..88fed774 100644 --- a/R/as_noise_params.R +++ b/R/as_noise_params.R @@ -10,8 +10,8 @@ #' @examples #' library(magrittr) #' noise_data <- -#' "https://osf.io/download//hqy4v/" %>% -#' readr::read_rds() %>% +#' "https://osf.io/download//hqy4v/" |> +#' readr::read_rds() |> #' as_noise_params() #' #' print(noise_data) @@ -31,7 +31,7 @@ as_noise_params <- function(data, antigen_isos = NULL) { ) } - noise_data <- data %>% tibble::as_tibble() + noise_data <- data |> tibble::as_tibble() # Define noise columns noise_cols <- c("antigen_iso", "y.low", "eps", "nu", "y.high") diff --git a/R/as_pop_data.R b/R/as_pop_data.R index 4ce7bccf..a09440b3 100644 --- a/R/as_pop_data.R +++ b/R/as_pop_data.R @@ -11,8 +11,8 @@ #' @examples #' library(magrittr) #' xs_data <- -#' "https://osf.io/download//n6cp3/" %>% -#' readr::read_rds() %>% +#' "https://osf.io/download//n6cp3/" |> +#' readr::read_rds() |> #' as_pop_data() #' #' print(xs_data) @@ -25,7 +25,7 @@ as_pop_data <- function(data, pop_data <- - data %>% + data |> tibble::as_tibble() class(pop_data) <- @@ -39,10 +39,10 @@ as_pop_data <- function(data, attr(pop_data, "antigen_isos") <- antigen_isos - pop_data <- pop_data %>% - set_age(age = age, standardize = standardize) %>% - set_value(value = value, standardize = standardize) %>% - set_id(id = id, standardize = standardize) %>% + pop_data <- pop_data |> + set_age(age = age, standardize = standardize) |> + set_value(value = value, standardize = standardize) |> + set_id(id = id, standardize = standardize) |> set_biomarker_var(biomarker = "antigen_iso", standardize = standardize) return(pop_data) diff --git a/R/autoplot.curve_params.R b/R/autoplot.curve_params.R index f1040419..2a7afc83 100644 --- a/R/autoplot.curve_params.R +++ b/R/autoplot.curve_params.R @@ -23,9 +23,9 @@ #' library(ggplot2) #' library(magrittr) #' -#' curve = load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% -#' slice(1:100, .by = antigen_iso) %>% # Reduce dataset for this example +#' curve = load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> +#' slice(1:100, .by = antigen_iso) |> # Reduce dataset for this example #' autoplot() #' #' curve @@ -35,13 +35,13 @@ autoplot.curve_params <- function( antigen_isos = unique(object$antigen_iso), ncol = min(3, length(antigen_isos)), ...) { - split_data <- object %>% - filter(.data$antigen_iso %in% antigen_isos) %>% - droplevels() %>% + split_data <- object |> + filter(.data$antigen_iso %in% antigen_isos) |> + droplevels() |> split(~antigen_iso) labels <- names(split_data) - figs <- split_data %>% + figs <- split_data |> lapply(FUN = plot_curve_params_one_ab, ...) for (i in seq_along(figs)) { diff --git a/R/autoplot.pop_data.R b/R/autoplot.pop_data.R index 786207de..ee3cdb1b 100644 --- a/R/autoplot.pop_data.R +++ b/R/autoplot.pop_data.R @@ -24,8 +24,8 @@ #' standardize = TRUE #' ) #' -#' xs_data %>% autoplot(strata = "Country", type = "density") -#' xs_data %>% autoplot(strata = "Country", type = "age-scatter") +#' xs_data |> autoplot(strata = "Country", type = "density") +#' xs_data |> autoplot(strata = "Country", type = "age-scatter") #' @export autoplot.pop_data <- function( object, @@ -65,13 +65,13 @@ autoplot.pop_data <- function( age_scatter <- function( object, strata = NULL, - age_var = object %>% get_age_var(), - value_var = object %>% get_value_var()) { + age_var = object |> get_age_var(), + value_var = object |> get_value_var()) { # create default plotting if (is.null(strata)) { plot1 <- - object %>% + object |> ggplot2::ggplot() + ggplot2::aes( x = .data[[age_var]], @@ -79,7 +79,7 @@ age_scatter <- function( ) } else { plot1 <- - object %>% + object |> ggplot2::ggplot() + ggplot2::aes( col = .data[[strata]], @@ -120,9 +120,9 @@ density_plot <- function( object, strata = NULL, log = FALSE, - value_var = object %>% get_value_var()) { + value_var = object |> get_value_var()) { plot1 <- - object %>% + object |> ggplot2::ggplot() + ggplot2::aes(x = .data[[value_var]]) + ggplot2::theme_linedraw() + @@ -146,19 +146,19 @@ density_plot <- function( if (log) { min_nonzero_val <- - object %>% - get_value() %>% - purrr::keep(~ . > 0) %>% + object |> + get_value() |> + purrr::keep(~ . > 0) |> min() max_val <- - object %>% - get_value() %>% + object |> + get_value() |> max() breaks1 <- c(0, 10^seq( - min_nonzero_val %>% log10() %>% floor(), - max_val %>% log10() %>% ceiling() + min_nonzero_val |> log10() |> floor(), + max_val |> log10() |> ceiling() )) plot1 <- plot1 + diff --git a/R/autoplot.seroincidence.R b/R/autoplot.seroincidence.R index c7da36ce..cb60918f 100644 --- a/R/autoplot.seroincidence.R +++ b/R/autoplot.seroincidence.R @@ -13,16 +13,16 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est1 <- est.incidence( -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_param = curve, -#' noise_param = noise %>% filter(Country == "Pakistan"), +#' noise_param = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' build_graph = TRUE #' ) diff --git a/R/autoplot.seroincidence.by.R b/R/autoplot.seroincidence.by.R index d0005d43..6214197a 100644 --- a/R/autoplot.seroincidence.by.R +++ b/R/autoplot.seroincidence.by.R @@ -11,20 +11,20 @@ #' library(dplyr) #' library(ggplot2) #' -#' xs_data <- "https://osf.io/download//n6cp3/" %>% +#' xs_data <- "https://osf.io/download//n6cp3/" |> #' load_pop_data() #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est2 <- est.incidence.by( #' strata = c("catchment"), -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curve, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' #num_cores = 8, #Allow for parallel processing to decrease run time #' build_graph = TRUE diff --git a/R/autoplot.summary.seroincidence.by.R b/R/autoplot.summary.seroincidence.by.R index da656db5..b38b9ef4 100644 --- a/R/autoplot.summary.seroincidence.by.R +++ b/R/autoplot.summary.seroincidence.by.R @@ -16,17 +16,17 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est2 <- est.incidence.by( #' strata = c("catchment"), -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curve, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' #num_cores = 8 #Allow for parallel processing to decrease run time #' ) @@ -42,7 +42,7 @@ autoplot.summary.seroincidence.by <- function( shape = 1, width = 0.001, ...) { - object %>% + object |> ggplot2::ggplot( ggplot2::aes( x = get(xvar), diff --git a/R/check_parallel_cores.R b/R/check_parallel_cores.R index 05af5cd8..92d2ae01 100644 --- a/R/check_parallel_cores.R +++ b/R/check_parallel_cores.R @@ -3,7 +3,7 @@ check_parallel_cores <- function(num_cores) { if (num_cores > (parallel::detectCores() - 1)) { num_cores <- - num_cores %>% + num_cores |> min(parallel::detectCores() - 1) warning( diff --git a/R/check_pop_data.R b/R/check_pop_data.R index 11d72c4b..681853a8 100644 --- a/R/check_pop_data.R +++ b/R/check_pop_data.R @@ -6,7 +6,7 @@ #' @export #' @examples #' library(dplyr) -#' xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>% +#' xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") |> #' as_pop_data() #' check_pop_data(xs_data, verbose = TRUE) #' @@ -23,24 +23,24 @@ check_pop_data <- function(pop_data, verbose = FALSE) { } missing_age <- is.element( - pop_data %>% get_age_var(), - pop_data %>% names() + pop_data |> get_age_var(), + pop_data |> names() ) if (!missing_age) { "Argument {.arg pop_data} is missing column - {.var {pop_data %>% get_age_var()}}(age, in years)" %>% + {.var {pop_data |> get_age_var()}}(age, in years)" |> cli::cli_abort(class = "missing-var") } missing_value <- is.element( - pop_data %>% get_value_var(), - pop_data %>% names() + pop_data |> get_value_var(), + pop_data |> names() ) if (!missing_value) { "Argument {.arg pop_data} is missing column - {.var {pop_data %>% get_value_var()}} (antibody measurement)" %>% + {.var {pop_data |> get_value_var()}} (antibody measurement)" |> cli::cli_abort(class = "missing-var") } diff --git a/R/class_attributes.R b/R/class_attributes.R index 19812672..df10fbec 100644 --- a/R/class_attributes.R +++ b/R/class_attributes.R @@ -4,8 +4,8 @@ get_age_var <- function(object, ...) { } get_age <- function(object, ...) { - age_var <- object %>% get_age_var() - age_data <- object %>% pull(age_var) + age_var <- object |> get_age_var() + age_data <- object |> pull(age_var) return(age_data) } @@ -15,8 +15,8 @@ get_value_var <- function(object, ...) { } get_value <- function(object, ...) { - value_var_name <- object %>% get_value_var() - value_data <- object %>% pull(value_var_name) + value_var_name <- object |> get_value_var() + value_data <- object |> pull(value_var_name) return(value_data) } @@ -26,8 +26,8 @@ get_id_var <- function(object, ...) { } get_id <- function(object, ...) { - id_var_name <- object %>% get_id_var() - id_data <- object %>% pull(id_var_name) + id_var_name <- object |> get_id_var() + id_data <- object |> pull(id_var_name) return(id_data) } @@ -45,7 +45,7 @@ get_biomarker_names_var <- function(object, ...) { get_biomarker_names <- function(object, ...) { # get biomarker name data biomarker_names_var <- get_biomarker_names_var(object) - biomarker_data <- object %>% pull(biomarker_names_var) + biomarker_data <- object |> pull(biomarker_names_var) return(biomarker_data) } @@ -88,7 +88,7 @@ set_age <- function(object, } if (standardize) { - object <- object %>% + object <- object |> rename(c("age" = attr(object, "age_var"))) # set age attribute @@ -135,7 +135,7 @@ set_value <- function(object, } if (standardize) { - object <- object %>% + object <- object |> rename(c("value" = attr(object, "value_var"))) # set id attribute @@ -180,7 +180,7 @@ set_id <- function(object, } if (standardize) { - object <- object %>% + object <- object |> rename(c("id" = attr(object, "id_var"))) # set id attribute diff --git a/R/count_strata.R b/R/count_strata.R index a2eae9d0..93904596 100644 --- a/R/count_strata.R +++ b/R/count_strata.R @@ -1,10 +1,10 @@ count_strata <- function(data, strata_varnames) { to_return <- - data %>% + data |> count(across(any_of(c(strata_varnames, "antigen_iso")))) uneven_counts <- - to_return %>% + to_return |> dplyr::filter( .by = all_of(strata_varnames), n_distinct(n) > 1 @@ -15,7 +15,7 @@ count_strata <- function(data, strata_varnames) { } to_return <- - to_return %>% + to_return |> dplyr::summarize( .by = all_of(strata_varnames), n = min(n) @@ -23,8 +23,8 @@ count_strata <- function(data, strata_varnames) { if (!("Stratum" %in% strata_varnames)) { to_return <- - to_return %>% - mutate(Stratum = paste("Stratum", row_number())) %>% + to_return |> + mutate(Stratum = paste("Stratum", row_number())) |> dplyr::relocate("Stratum", .before = everything()) } diff --git a/R/csdata_wide_to_long.R b/R/csdata_wide_to_long.R index 78717d21..5e19437f 100644 --- a/R/csdata_wide_to_long.R +++ b/R/csdata_wide_to_long.R @@ -1,8 +1,8 @@ csdata_wide_to_long <- function( csdata, antigen_isos = c("HlyE_IgG", "HlyE_IgA")) { - csdata %>% - as_tibble() %>% + csdata |> + as_tibble() |> pivot_longer( cols = antigen_isos, names_to = "antigen_iso", diff --git a/R/df_to_array.R b/R/df_to_array.R index 98e5ff4b..933e7968 100644 --- a/R/df_to_array.R +++ b/R/df_to_array.R @@ -31,13 +31,13 @@ df.to.array <- function( # nolint: object_name_linter #' library(dplyr) #' library(tidyr) #' -#' df <- iris %>% +#' df <- iris |> #' tidyr::pivot_longer( #' names_to = "parameter", #' cols = c("Sepal.Length", "Sepal.Width", "Petal.Width", "Petal.Length") -#' ) %>% +#' ) |> #' mutate(parameter = factor(parameter, levels = unique(parameter))) -#' arr <- df %>% +#' arr <- df |> #' serocalculator:::df_to_array( #' dim_var_names = c("parameter", "Species")) #' ftable(arr[,,1:5]) @@ -47,16 +47,16 @@ df_to_array <- function( dim_var_names, value_var_name = "value") { stopifnot(all(dim_var_names %in% names(df))) - stopifnot(value_var_name %>% length() == 1) + stopifnot(value_var_name |> length() == 1) stopifnot(value_var_name %in% names(df)) if (is.grouped_df(df)) { stop("ungroup the data frame first before running") } all_factors <- - df %>% - select(all_of(dim_var_names)) %>% - sapply(FUN = is.factor) %>% + df |> + select(all_of(dim_var_names)) |> + sapply(FUN = is.factor) |> all() if (!all_factors) { @@ -67,7 +67,7 @@ df_to_array <- function( ) } - df <- df %>% + df <- df |> mutate( across( all_of(dim_var_names), @@ -82,7 +82,7 @@ df_to_array <- function( paste(c(dim_var_names, "obs"), collapse = " + ") ) - df %>% - mutate(.by = all_of(dim_var_names), obs = row_number()) %>% + df |> + mutate(.by = all_of(dim_var_names), obs = row_number()) |> xtabs(formula = formula(xtabs_formula)) } diff --git a/R/est.incidence.R b/R/est.incidence.R index a0c291e5..f30a1600 100644 --- a/R/est.incidence.R +++ b/R/est.incidence.R @@ -19,16 +19,16 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curves <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curves <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est1 <- est.incidence( -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curves, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' iterlim = 5 # limit iterations for the purpose of this example #' ) @@ -38,7 +38,7 @@ est.incidence <- function( pop_data, curve_params, noise_params, - antigen_isos = pop_data$antigen_iso %>% unique(), + antigen_isos = pop_data$antigen_iso |> unique(), lambda_start = 0.1, stepmin = 1e-8, stepmax = 3, @@ -48,7 +48,7 @@ est.incidence <- function( ...) { if (verbose > 1) { message("inputs to `est.incidence()`:") - print(environment() %>% as.list()) + print(environment() |> as.list()) } .errorCheck( @@ -57,27 +57,27 @@ est.incidence <- function( curve_params = curve_params ) - pop_data <- pop_data %>% - dplyr::filter(.data$antigen_iso %in% antigen_isos) %>% + pop_data <- pop_data |> + dplyr::filter(.data$antigen_iso %in% antigen_isos) |> dplyr::select( - pop_data %>% get_value_var(), - pop_data %>% get_age_var(), + pop_data |> get_value_var(), + pop_data |> get_age_var(), "antigen_iso" - ) %>% + ) |> filter(if_all(everything(), ~!is.na(.x))) - curve_params <- curve_params %>% - ungroup() %>% + curve_params <- curve_params |> + ungroup() |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1 - ) %>% - dplyr::filter(.data$antigen_iso %in% antigen_isos) %>% - dplyr::select("y1", "alpha", "d", "antigen_iso") %>% + ) |> + dplyr::filter(.data$antigen_iso %in% antigen_isos) |> + dplyr::select("y1", "alpha", "d", "antigen_iso") |> droplevels() - noise_params <- noise_params %>% - dplyr::filter(.data$antigen_iso %in% antigen_isos) %>% + noise_params <- noise_params |> + dplyr::filter(.data$antigen_iso %in% antigen_isos) |> droplevels() # incidence can not be calculated if there are zero observations. @@ -93,9 +93,9 @@ est.incidence <- function( stop("too many rows of noise parameters.") } - pop_data <- pop_data %>% split(~antigen_iso) - curve_params <- curve_params %>% split(~antigen_iso) - noise_params <- noise_params %>% split(~antigen_iso) + pop_data <- pop_data |> split(~antigen_iso) + curve_params <- curve_params |> split(~antigen_iso) + noise_params <- noise_params |> split(~antigen_iso) # First, check if we find numeric results... res <- .nll( @@ -162,7 +162,7 @@ est.incidence <- function( print.level = ifelse(verbose, 2, 0), ... ) - } %>% + } |> system.time() code_text <- nlm_exit_codes[fit$code] @@ -182,7 +182,7 @@ est.incidence <- function( if (build_graph) { graph <- - graph %>% + graph |> add_point_to_graph( fit = fit, pop_data = pop_data, @@ -201,7 +201,7 @@ est.incidence <- function( } } - fit <- fit %>% + fit <- fit |> structure( class = union("seroincidence", class(fit)), lambda_start = lambda_start, diff --git a/R/est.incidence.by.R b/R/est.incidence.by.R index 6395f5b3..7092eace 100644 --- a/R/est.incidence.by.R +++ b/R/est.incidence.by.R @@ -37,17 +37,17 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est2 <- est.incidence.by( #' strata = c("catchment"), -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curve, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' #num_cores = 8 # Allow for parallel processing to decrease run time #' iterlim = 5 # limit iterations for the purpose of this example @@ -62,8 +62,8 @@ est.incidence.by <- function( strata, curve_strata_varnames = strata, noise_strata_varnames = strata, - antigen_isos = pop_data %>% - pull("antigen_iso") %>% + antigen_isos = pop_data |> + pull("antigen_iso") |> unique(), lambda_start = 0.1, build_graph = FALSE, @@ -112,15 +112,15 @@ est.incidence.by <- function( # Split data per stratum stratumDataList <- stratify_data( antigen_isos = antigen_isos, - data = pop_data %>% filter(.data$antigen_iso %in% antigen_isos), - curve_params = curve_params %>% filter(.data$antigen_iso %in% antigen_isos), - noise_params = noise_params %>% filter(.data$antigen_iso %in% antigen_isos), + data = pop_data |> filter(.data$antigen_iso %in% antigen_isos), + curve_params = curve_params |> filter(.data$antigen_iso %in% antigen_isos), + noise_params = noise_params |> filter(.data$antigen_iso %in% antigen_isos), strata_varnames = strata, curve_strata_varnames = curve_strata_varnames, noise_strata_varnames = noise_strata_varnames ) - strata_table <- stratumDataList %>% attr("strata") + strata_table <- stratumDataList |> attr("strata") if (verbose) { message("Data has been stratified.") @@ -139,7 +139,7 @@ est.incidence.by <- function( if (num_cores > 1L) { requireNamespace("parallel", quietly = FALSE) - num_cores <- num_cores %>% check_parallel_cores() + num_cores <- num_cores |> check_parallel_cores() if (verbose) { message("Setting up parallel processing with `num_cores` = ", num_cores, ".") @@ -148,8 +148,8 @@ est.incidence.by <- function( libPaths <- .libPaths() cl <- - num_cores %>% - parallel::makeCluster() %>% + num_cores |> + parallel::makeCluster() |> suppressMessages() on.exit({ parallel::stopCluster(cl) @@ -183,7 +183,7 @@ est.incidence.by <- function( ) } ) - } %>% system.time() -> time + } |> system.time() -> time if (verbose) { message("Elapsed time for parallelized code: ") @@ -201,7 +201,7 @@ est.incidence.by <- function( for (cur_stratum in names(stratumDataList)) { cur_stratum_vars <- - strata_table %>% + strata_table |> dplyr::filter(.data$Stratum == cur_stratum) if (verbose) { @@ -225,7 +225,7 @@ est.incidence.by <- function( ) ) } - } %>% system.time() -> time + } |> system.time() -> time if (verbose) { message("Elapsed time for loop over strata: ") @@ -238,7 +238,7 @@ est.incidence.by <- function( antigen_isos = antigen_isos, Strata = strata_table, graphs_included = build_graph, - class = "seroincidence.by" %>% union(class(fits)) + class = "seroincidence.by" |> union(class(fits)) ) return(incidenceData) diff --git a/R/f_dev.r b/R/f_dev.r index ae9de20d..913c49ef 100644 --- a/R/f_dev.r +++ b/R/f_dev.r @@ -30,7 +30,7 @@ fdev <- function(lambda, csdata, lnpars, cond) #' #' # load in longitudinal parameters #' curve_params = load_curve_params("https://osf.io/download/rtw5k") -#' xs_data <- "https://osf.io/download//n6cp3/" %>% +#' xs_data <- "https://osf.io/download//n6cp3/" |> #' load_pop_data() #' #' #Load noise params @@ -44,25 +44,25 @@ fdev <- function(lambda, csdata, lnpars, cond) #' cur_antibody = "HlyE_IgA" #' #' cur_data <- -#' xs_data %>% +#' xs_data |> #' dplyr::filter( #' .data$catchment == "dhaka", -#' .data$antigen_iso == cur_antibody) %>% +#' .data$antigen_iso == cur_antibody) |> #' dplyr::slice_head(n = 100) #' #' cur_curve_params <- -#' curve_params %>% -#' dplyr::filter(.data$antigen_iso == cur_antibody) %>% +#' curve_params |> +#' dplyr::filter(.data$antigen_iso == cur_antibody) |> #' dplyr::slice_head(n = 100) #' #' cur_noise_params <- -#' noise_params %>% +#' noise_params |> #' dplyr::filter(.data$antigen_iso == cur_antibody) #' #' if(!is.element('d', names(cur_curve_params))) #' { #' cur_curve_params <- -#' cur_curve_params %>% +#' cur_curve_params |> #' dplyr::mutate( #' alpha = .data$alpha * 365.25, #' d = .data$r - 1) @@ -129,7 +129,7 @@ f_dev0 <- function( #' #' # load in longitudinal parameters #' curve_params = load_curve_params("https://osf.io/download/rtw5k") -#' xs_data <- "https://osf.io/download//n6cp3/" %>% +#' xs_data <- "https://osf.io/download//n6cp3/" |> #' load_pop_data() #' #' #Load noise params @@ -143,25 +143,25 @@ f_dev0 <- function( #' cur_antibody = "HlyE_IgA" #' #' cur_data = -#' xs_data %>% +#' xs_data |> #' dplyr::filter( #' .data$catchment == "dhaka", -#' .data$antigen_iso == cur_antibody) %>% +#' .data$antigen_iso == cur_antibody) |> #' dplyr::slice_head(n = 100) #' #' cur_curve_params = -#' curve_params %>% -#' dplyr::filter(.data$antigen_iso == cur_antibody) %>% +#' curve_params |> +#' dplyr::filter(.data$antigen_iso == cur_antibody) |> #' dplyr::slice_head(n = 100) #' #' cur_noise_params = -#' noise_params %>% +#' noise_params |> #' dplyr::filter(.data$antigen_iso == cur_antibody) #' #' if(!is.element('d', names(cur_curve_params))) #' { #' cur_curve_params = -#' cur_curve_params %>% +#' cur_curve_params |> #' dplyr::mutate( #' alpha = .data$alpha * 365.25, #' d = .data$r - 1) diff --git a/R/get_curve_params_one_antigen.R b/R/get_curve_params_one_antigen.R index 276b197e..ff1df8a7 100644 --- a/R/get_curve_params_one_antigen.R +++ b/R/get_curve_params_one_antigen.R @@ -1,9 +1,9 @@ get_curve_params_one_antigen <- function(params, antigen) { - params %>% - dplyr::filter(.data[["antigen_iso"]] == .env[["antigen"]]) %>% + params |> + dplyr::filter(.data[["antigen_iso"]] == .env[["antigen"]]) |> mutate( alpha = .data[["alpha"]] * 365.25, d = .data[["r"]] - 1 - ) %>% + ) |> select("y1", "alpha", "d") } diff --git a/R/get_xspd_one_antigen.R b/R/get_xspd_one_antigen.R index 229ddd60..a83f44be 100644 --- a/R/get_xspd_one_antigen.R +++ b/R/get_xspd_one_antigen.R @@ -1,6 +1,6 @@ get_xspd_one_antigen <- function(data, antigen) { - data %>% - dplyr::filter(.data$antigen_iso %in% .env$antigen) %>% - select("value", "age") %>% + data |> + dplyr::filter(.data$antigen_iso %in% .env$antigen) |> + select("value", "age") |> drop_na() } diff --git a/R/graph.curve.params.R b/R/graph.curve.params.R index 216e2572..adf65b96 100644 --- a/R/graph.curve.params.R +++ b/R/graph.curve.params.R @@ -23,7 +23,7 @@ graph.curve.params <- function( ) } - curve_params <- curve_params %>% + curve_params <- curve_params |> dplyr::filter(.data$antigen_iso %in% antigen_isos) day2yr <- 365.25 @@ -53,19 +53,19 @@ graph.curve.params <- function( d <- curve_params - # %>% + # |> # mutate(alpha = .data$alpha / day2yr) dT <- - data.frame(t = tx2) %>% - mutate(ID = 1:n()) %>% + data.frame(t = tx2) |> + mutate(ID = 1:n()) |> pivot_wider( names_from = .data$ID, values_from = .data$t, names_prefix = "time" - ) %>% + ) |> dplyr::slice( rep(1:dplyr::n(), each = nrow(d) @@ -74,13 +74,13 @@ graph.curve.params <- function( serocourse.all <- - cbind(d, dT) %>% + cbind(d, dT) |> tidyr::pivot_longer( cols = dplyr::starts_with("time"), values_to = "t" - ) %>% - select(-"name") %>% - rowwise() %>% + ) |> + select(-"name") |> + rowwise() |> mutate(res = ab( .data$t, .data$y0, @@ -88,11 +88,11 @@ graph.curve.params <- function( .data$t1, .data$alpha, .data$r - )) %>% + )) |> ungroup() if (verbose) message("starting to compute quantiles") - serocourse.sum <- serocourse.all %>% + serocourse.sum <- serocourse.all |> summarise( .by = c("antigen_iso", "t"), res.med = quantile(.data$res, 0.5), @@ -102,7 +102,7 @@ graph.curve.params <- function( res.p25 = quantile(.data$res, 0.25), res.p10 = quantile(.data$res, 0.10), res.p90 = quantile(.data$res, 0.90) - ) %>% + ) |> pivot_longer( names_to = "quantile", cols = c( @@ -122,7 +122,7 @@ graph.curve.params <- function( ggplot2::ggplot() + ggplot2::geom_line( - data = serocourse.sum %>% + data = serocourse.sum |> filter(.data$quantile == "med"), ggplot2::aes( x = .data$t, @@ -131,7 +131,7 @@ graph.curve.params <- function( linewidth = 1 ) + ggplot2::geom_line( - data = serocourse.sum %>% filter(quantile == "p10"), + data = serocourse.sum |> filter(quantile == "p10"), ggplot2::aes( x = .data$t, y = .data$res @@ -139,7 +139,7 @@ graph.curve.params <- function( linewidth = .5 ) + ggplot2::geom_line( - data = serocourse.sum %>% + data = serocourse.sum |> filter(quantile == "p90"), ggplot2::aes( x = .data$t, diff --git a/R/graph.decay.curves.R b/R/graph.decay.curves.R index a9248be8..77064982 100644 --- a/R/graph.decay.curves.R +++ b/R/graph.decay.curves.R @@ -31,10 +31,10 @@ #' * If the user directly specifies the `rows_to_graph` argument, #' then `n_curves` has no effect. #' @examples -#' library(dplyr) # loads the `%>%` operator and `dplyr::filter()` +#' library(dplyr) # loads the `|>` operator and `dplyr::filter()` #' -#' load_curve_params("https://osf.io/download/rtw5k/") %>% -#' dplyr::filter(antigen_iso == "HlyE_IgG") %>% +#' load_curve_params("https://osf.io/download/rtw5k/") |> +#' dplyr::filter(antigen_iso == "HlyE_IgG") |> #' serocalculator:::plot_curve_params_one_ab() #' plot_curve_params_one_ab <- function( diff --git a/R/graph.loglik.R b/R/graph.loglik.R index 7e97d8d4..f4fc9504 100644 --- a/R/graph.loglik.R +++ b/R/graph.loglik.R @@ -22,8 +22,8 @@ #' #' #' # Load curve parameters and subset for the purposes of this example -#' dmcmc <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' dmcmc <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) #' #' # Load noise parameters @@ -50,7 +50,7 @@ graph_loglik <- function( pop_data, curve_params, noise_params, - antigen_isos = pop_data %>% get_biomarker_levels(), + antigen_isos = pop_data |> get_biomarker_levels(), x = 10^seq(-3, 0, by = .1), highlight_points = NULL, highlight_point_names = "highlight_points", @@ -64,7 +64,7 @@ graph_loglik <- function( !is.element("d", names(curve_params)) if (needs_rescale) { curve_params <- - curve_params %>% + curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1 @@ -73,7 +73,7 @@ graph_loglik <- function( plot_data <- tibble( - x = x %>% sort(), + x = x |> sort(), y = log_likelihood( pop_data = pop_data, curve_params = curve_params, @@ -85,7 +85,7 @@ graph_loglik <- function( ) if (is.null(previous_plot)) { - plot1 <- plot_data %>% + plot1 <- plot_data |> ggplot2::ggplot(ggplot2::aes(x = .data$x, y = .data$y)) + # ggplot2::geom_point() + ggplot2::geom_line(aes(color = curve_label)) + diff --git a/R/load_curve_params.R b/R/load_curve_params.R index 2874f43b..09ee4b88 100644 --- a/R/load_curve_params.R +++ b/R/load_curve_params.R @@ -11,13 +11,13 @@ #' print(curve) #' load_curve_params <- function(file_path, antigen_isos = NULL) { - if (file_path %>% substr(1, 4) == "http") { + if (file_path |> substr(1, 4) == "http") { file_path <- url(file_path) } curve_params <- - file_path %>% - readRDS() %>% + file_path |> + readRDS() |> as_curve_params() return(curve_params) diff --git a/R/load_noise_params.R b/R/load_noise_params.R index b27938ba..876b1e0b 100644 --- a/R/load_noise_params.R +++ b/R/load_noise_params.R @@ -15,13 +15,13 @@ #' print(noise) #' load_noise_params <- function(file_path, antigen_isos = NULL) { - if (file_path %>% substr(1, 4) == "http") { + if (file_path |> substr(1, 4) == "http") { file_path <- url(file_path) } noise <- - file_path %>% - readRDS() %>% + file_path |> + readRDS() |> as_noise_params() return(noise) diff --git a/R/load_pop_data.R b/R/load_pop_data.R index c1d711ea..19c8e2c1 100644 --- a/R/load_pop_data.R +++ b/R/load_pop_data.R @@ -11,8 +11,8 @@ #' print(xs_data) load_pop_data <- function(file_path, ...) { pop_data <- - file_path %>% - readr::read_rds() %>% + file_path |> + readr::read_rds() |> as_pop_data(...) return(pop_data) diff --git a/R/log_likelihood.R b/R/log_likelihood.R index 2022a83c..7f62ffc8 100644 --- a/R/log_likelihood.R +++ b/R/log_likelihood.R @@ -60,7 +60,7 @@ llik <- function(...) { #' # load in longitudinal parameters #' dmcmc <- load_curve_params("https://osf.io/download/rtw5k") #' -#' xs_data <- "https://osf.io/download//n6cp3/" %>% +#' xs_data <- "https://osf.io/download//n6cp3/" |> #' load_pop_data() #' #' # Load noise params @@ -79,7 +79,7 @@ llik <- function(...) { #' noise_params = cond, #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' lambda = 0.1 -#' ) %>% print() +#' ) |> print() #' log_likelihood <- function( lambda, @@ -103,20 +103,20 @@ log_likelihood <- function( cur_noise_params <- noise_params[[cur_antibody]] } else { cur_data <- - pop_data %>% + pop_data |> dplyr::filter(.data$antigen_iso == cur_antibody) cur_curve_params <- - curve_params %>% + curve_params |> dplyr::filter(.data$antigen_iso == cur_antibody) cur_noise_params <- - noise_params %>% + noise_params |> dplyr::filter(.data$antigen_iso == cur_antibody) if (!is.element("d", names(cur_curve_params))) { cur_curve_params <- - cur_curve_params %>% + cur_curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1 diff --git a/R/prep_curve_params_for_array.R b/R/prep_curve_params_for_array.R index 63921fe0..f74b4f92 100644 --- a/R/prep_curve_params_for_array.R +++ b/R/prep_curve_params_for_array.R @@ -1,21 +1,21 @@ # note: this function outputs "value" on the log scale; # this gets undone in `par.pred.n()` prep_curve_params_for_array <- function(data) { - data %>% - mutate(y1 = .data$y1 - .data$y0) %>% - mutate(d = .data$r - 1) %>% # DM: issue here? + data |> + mutate(y1 = .data$y1 - .data$y0) |> + mutate(d = .data$r - 1) |> # DM: issue here? tidyr::pivot_longer( names_to = "parameter", cols = c("y0", "y1", "t1", "alpha", "d") - ) %>% + ) |> mutate( parameter = - .data$parameter %>% + .data$parameter |> factor( levels = c("y0", "y1", "t1", "alpha", "d") ) - ) %>% - select(-any_of(c("Country", "ageCat"))) %>% - mutate(value = log(.data$value)) %>% + ) |> + select(-any_of(c("Country", "ageCat"))) |> + mutate(value = log(.data$value)) |> droplevels() } diff --git a/R/print.seroincidence.by.R b/R/print.seroincidence.by.R index d27cb03c..aad3e782 100644 --- a/R/print.seroincidence.by.R +++ b/R/print.seroincidence.by.R @@ -23,7 +23,7 @@ print.seroincidence.by <- function(x, ...) { cat("`seroincidence.by` object estimated given the following setup:\n") cat(paste("a) Antigen isotypes :", paste(attr(x, "antigen_isos"), collapse = ", ")), "\n") - cat(paste("b) Strata :", paste(attr(x, "Strata") %>% attr("strata_vars"), collapse = ", ")), "\n") + cat(paste("b) Strata :", paste(attr(x, "Strata") |> attr("strata_vars"), collapse = ", ")), "\n") cat("\n") cat("This object is a list of `seroincidence` objects, with added meta-data attributes:") diff --git a/R/print.summary.seroincidence.by.R b/R/print.summary.seroincidence.by.R index f91abbdf..b3ff9455 100644 --- a/R/print.summary.seroincidence.by.R +++ b/R/print.summary.seroincidence.by.R @@ -25,8 +25,8 @@ #' @export print.summary.seroincidence.by <- function(x, ...) { cat("Seroincidence estimated given the following setup:\n") - cat(paste("a) Antigen isotypes :", paste(x %>% attr("antigen_isos"), collapse = ", ")), "\n") - cat(paste("b) Strata :", paste(x %>% attr("Strata"), collapse = ", ")), "\n") + cat(paste("a) Antigen isotypes :", paste(x |> attr("antigen_isos"), collapse = ", ")), "\n") + cat(paste("b) Strata :", paste(x |> attr("Strata"), collapse = ", ")), "\n") cat("\n Seroincidence estimates:\n") print(as_tibble(x)) invisible(x) diff --git a/R/serocalculator-package.R b/R/serocalculator-package.R index b1966566..24f15143 100644 --- a/R/serocalculator-package.R +++ b/R/serocalculator-package.R @@ -159,7 +159,7 @@ #' @importFrom ggplot2 autoplot #' @importFrom ggplot2 ggplot #' @importFrom lifecycle deprecated -#' @importFrom magrittr %>% +#' @importFrom magrittr |> #' @importFrom mixtools normalmixEM #' @importFrom Rcpp sourceCpp #' @importFrom rlang .data diff --git a/R/set_biomarker_var.R b/R/set_biomarker_var.R index 3aead4d2..1a64d6ce 100644 --- a/R/set_biomarker_var.R +++ b/R/set_biomarker_var.R @@ -10,7 +10,7 @@ set_biomarker_var <- function(object, } if (standardize) { - object <- object %>% + object <- object |> rename(c("antigen_iso" = attr(object, "biomarker_var"))) # update attribute diff --git a/R/sim.cs.R b/R/sim.cs.R index 774e59f5..4e2ded8c 100644 --- a/R/sim.cs.R +++ b/R/sim.cs.R @@ -84,16 +84,16 @@ sim.cs <- function( ...) { if (verbose > 1) { message("inputs to `sim.cs()`:") - print(environment() %>% as.list()) + print(environment() |> as.list()) } # @param predpar an [array()] containing MCMC samples from the Bayesian distribution of longitudinal decay curve model parameters. NOTE: most users should leave `predpar` at its default value and provide `curve_params` instead. predpar <- - curve_params %>% - filter(.data$antigen_iso %in% antigen_isos) %>% - droplevels() %>% - prep_curve_params_for_array() %>% + curve_params |> + filter(.data$antigen_iso %in% antigen_isos) |> + droplevels() |> + prep_curve_params_for_array() |> df_to_array(dim_var_names = c("antigen_iso", "parameter")) stopifnot(length(lambda) == 1) @@ -101,7 +101,7 @@ sim.cs <- function( day2yr <- 365.25 lambda <- lambda / day2yr age.rng <- age.rng * day2yr - npar <- dimnames(predpar)$parameter %>% length() + npar <- dimnames(predpar)$parameter |> length() baseline_limits <- noise_limits @@ -134,8 +134,8 @@ sim.cs <- function( colnames(ysim) <- c("age", antigen_isos) to_return <- - ysim %>% - as_tibble() %>% + ysim |> + as_tibble() |> mutate( id = as.character(1:n()), age = round(.data$age / day2yr, 2) @@ -144,23 +144,23 @@ sim.cs <- function( if (format == "long") { if (verbose) message("outputting long format data") to_return <- - to_return %>% + to_return |> pivot_longer( cols = antigen_isos, values_to = c("value"), names_to = c("antigen_iso") - ) %>% + ) |> structure( class = c("pop_data", class(to_return)), format = "long" - ) %>% - set_value(value = "value") %>% - set_age(age = "age") %>% + ) |> + set_value(value = "value") |> + set_age(age = "age") |> set_id(id = "id") } else { if (verbose) message("outputting wide format data") to_return <- - to_return %>% + to_return |> structure( class = c("pop_data_wide", class(to_return)), format = "wide" diff --git a/R/sim.cs.multi.R b/R/sim.cs.multi.R index 7c4518da..cdfcc42b 100644 --- a/R/sim.cs.multi.R +++ b/R/sim.cs.multi.R @@ -23,11 +23,11 @@ sim.cs.multi <- function( ...) { if (verbose) { message("inputs to `sim.cs.multi()`:") - print(environment() %>% as.list()) + print(environment() |> as.list()) } if (num_cores > 1L) { - num_cores <- num_cores %>% check_parallel_cores() + num_cores <- num_cores |> check_parallel_cores() if (verbose) { message("Setting up parallel processing with `num_cores` = ", num_cores, ".") @@ -60,7 +60,7 @@ sim.cs.multi <- function( renew.params = renew.params, add.noise = add.noise, ... - ) %>% + ) |> mutate(lambda.sim = l, cluster = n) } doParallel::stopImplicitCluster() diff --git a/R/simresp.tinf.R b/R/simresp.tinf.R index f96a333c..d5438b63 100644 --- a/R/simresp.tinf.R +++ b/R/simresp.tinf.R @@ -145,8 +145,8 @@ simresp.tinf <- function( b <- rbind(b, b.now) ymat <- rbind(ymat, y.now) - b.end <- b %>% tail(1) - y.end <- ymat %>% tail(1) + b.end <- b |> tail(1) + y.end <- ymat |> tail(1) if (renew.params) { if (n.mc == 0) { diff --git a/R/stratify_data.R b/R/stratify_data.R index 3681d794..2a10b6d2 100644 --- a/R/stratify_data.R +++ b/R/stratify_data.R @@ -12,8 +12,8 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") @@ -34,39 +34,39 @@ stratify_data <- function(data, strata_varnames = "", curve_strata_varnames = NULL, noise_strata_varnames = NULL, - antigen_isos = data %>% attr("antigen_isos")) { + antigen_isos = data |> attr("antigen_isos")) { no_strata = is.null(strata_varnames) || all(strata_varnames == "") curve_params = - curve_params %>% + curve_params |> filter(.data[["antigen_iso"]] %in% antigen_isos) noise_params = - noise_params %>% + noise_params |> filter(.data[["antigen_iso"]] %in% antigen_isos) if (no_strata) { all_data <- list( - pop_data = data %>% select(all_of( + pop_data = data |> select(all_of( c( - data %>% get_value_var(), - data %>% get_age_var(), + data |> get_value_var(), + data |> get_age_var(), "antigen_iso" ) )), curve_params = - curve_params %>% + curve_params |> select(all_of(curve_param_names)), noise_params = - noise_params %>% + noise_params |> select(all_of(noise_param_names)) - ) %>% + ) |> structure(class = union("biomarker_data_and_params", "list")) stratumDataList <- list(# est.incidence.by() expects a list. - `all data` = all_data) %>% + `all data` = all_data) |> structure(antigen_isos = antigen_isos, strata = tibble(Stratum = NA)) @@ -75,25 +75,25 @@ stratify_data <- function(data, # Make stratum variable (if needed) - strata <- data %>% count_strata(strata_varnames) + strata <- data |> count_strata(strata_varnames) strata_vars_curve_params <- warn.missing.strata( data = curve_params, - strata = strata %>% select(all_of(curve_strata_varnames)), + strata = strata |> select(all_of(curve_strata_varnames)), dataname = "curve_params" ) strata_vars_noise_params <- warn.missing.strata( data = noise_params, - strata = strata %>% select(all_of(noise_strata_varnames)), + strata = strata |> select(all_of(noise_strata_varnames)), dataname = "noise_params" ) - # xs_dataStrata <- data %>% .makeStrata(strata_varnames) - # curve_paramsStrata = curve_params %>% .makeStrata(strata_varnames) - # noise_params_Strata = noise_params %>% .makeStrata(strata_varnames) + # xs_dataStrata <- data |> .makeStrata(strata_varnames) + # curve_paramsStrata = curve_params |> .makeStrata(strata_varnames) + # noise_params_Strata = noise_params |> .makeStrata(strata_varnames) # levelsStrata <- levels(xs_dataStrata$Stratum) stratumDataList <- list() @@ -101,17 +101,17 @@ stratify_data <- function(data, for (cur_stratum in strata$Stratum) { cur_stratum_vals <- - strata %>% dplyr::filter(.data$Stratum == cur_stratum) + strata |> dplyr::filter(.data$Stratum == cur_stratum) data_and_params_cur_stratum <- list( pop_data = - data %>% - semi_join(cur_stratum_vals, by = strata_varnames) %>% + data |> + semi_join(cur_stratum_vals, by = strata_varnames) |> select(all_of( c( - data %>% get_value_var(), - data %>% get_age_var(), + data |> get_value_var(), + data |> get_age_var(), "antigen_iso" ) )) @@ -119,27 +119,27 @@ stratify_data <- function(data, if (length(strata_vars_curve_params) == 0) { data_and_params_cur_stratum$curve_params <- - curve_params %>% select(all_of(curve_param_names)) + curve_params |> select(all_of(curve_param_names)) } else { data_and_params_cur_stratum$curve_params <- - curve_params %>% - semi_join(cur_stratum_vals, by = strata_vars_curve_params) %>% + curve_params |> + semi_join(cur_stratum_vals, by = strata_vars_curve_params) |> select(all_of(curve_param_names)) } if (length(strata_vars_noise_params) == 0) { data_and_params_cur_stratum$noise_params <- - noise_params %>% + noise_params |> select(all_of(noise_param_names)) } else { data_and_params_cur_stratum$noise_params <- - noise_params %>% - semi_join(cur_stratum_vals, by = strata_vars_noise_params) %>% + noise_params |> + semi_join(cur_stratum_vals, by = strata_vars_noise_params) |> select(all_of(noise_param_names)) } stratumDataList[[cur_stratum]] <- - data_and_params_cur_stratum %>% + data_and_params_cur_stratum |> structure(class = union( "biomarker_data_and_params", class(data_and_params_cur_stratum) diff --git a/R/summary.pop_data.R b/R/summary.pop_data.R index bdb718c5..3b7facea 100644 --- a/R/summary.pop_data.R +++ b/R/summary.pop_data.R @@ -21,19 +21,19 @@ #' 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() + age_column <- object |> get_age_var() + value_column <- object |> get_value_var() + id_column <- object |> get_id_var() # create a list of the columns cols <- c(age_column, id_column, strata) ages <- - object %>% + object |> distinct(across(all_of(cols))) age_summary <- - ages %>% + ages |> summarise( .by = all_of(strata), n = n(), @@ -46,7 +46,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { ) ab_summary <- - object %>% + object |> dplyr::summarize( .by = all_of(c("antigen_iso", strata)), across( @@ -57,7 +57,7 @@ summary.pop_data <- function(object, strata = NULL, ...) { 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() + `# NAs` = ~ is.na(.x) |> sum() ), .names = "{.fn}" )) @@ -78,17 +78,17 @@ summary.pop_data <- function(object, strata = NULL, ...) { #' @export print.summary.pop_data = function(x, ...) { - n_obs = x$age_summary %>% pull("n") %>% sum() + n_obs = x$age_summary |> pull("n") |> sum() cat("\nn =", n_obs, "\n") cat("\nDistribution of age: \n\n") - x$age_summary %>% print() + x$age_summary |> print() cat("\nDistributions of antigen-isotype measurements:\n\n") - x$ab_summary %>% print() + x$ab_summary |> print() cat("\n") diff --git a/R/summary.seroincidence.R b/R/summary.seroincidence.R index 67e1a306..890b162d 100644 --- a/R/summary.seroincidence.R +++ b/R/summary.seroincidence.R @@ -26,16 +26,16 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curves <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curves <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est1 <- est.incidence( -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curves, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA") #' ) #' @@ -44,8 +44,8 @@ summary.seroincidence <- function( object, coverage = .95, ...) { - start <- object %>% attr("lambda_start") - antigen_isos <- object %>% attr("antigen_isos") + start <- object |> attr("lambda_start") + antigen_isos <- object |> attr("antigen_isos") alpha <- 1 - coverage h.alpha <- alpha / 2 @@ -58,7 +58,7 @@ summary.seroincidence <- function( } log.lambda <- object$estimate - var.log.lambda <- 1 / object$hessian %>% as.vector() + var.log.lambda <- 1 / object$hessian |> as.vector() se.log.lambda <- sqrt(var.log.lambda) to_return <- tibble::tibble( @@ -71,13 +71,13 @@ summary.seroincidence <- function( coverage = coverage, log.lik = -object$minimum, iterations = object$iterations, - antigen.isos = antigen_isos %>% paste(collapse = "+"), - nlm.convergence.code = object$code %>% factor(levels = 1:5, ordered = TRUE) - # %>% factor(levels = 1:5, labels = nlm_exit_codes) + antigen.isos = antigen_isos |> paste(collapse = "+"), + nlm.convergence.code = object$code |> factor(levels = 1:5, ordered = TRUE) + # |> factor(levels = 1:5, labels = nlm_exit_codes) ) class(to_return) <- - "summary.seroincidence" %>% + "summary.seroincidence" |> union(class(to_return)) return(to_return) diff --git a/R/summary.seroincidence.by.R b/R/summary.seroincidence.by.R index e550ab74..c55c7a2b 100644 --- a/R/summary.seroincidence.by.R +++ b/R/summary.seroincidence.by.R @@ -30,17 +30,17 @@ #' #' xs_data <- load_pop_data("https://osf.io/download//n6cp3/") #' -#' curve <- load_curve_params("https://osf.io/download/rtw5k/") %>% -#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% +#' curve <- load_curve_params("https://osf.io/download/rtw5k/") |> +#' filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> #' slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example #' #' noise <- load_noise_params("https://osf.io/download//hqy4v/") #' #' est2 <- est.incidence.by( #' strata = c("catchment"), -#' pop_data = xs_data %>% filter(Country == "Pakistan"), +#' pop_data = xs_data |> filter(Country == "Pakistan"), #' curve_params = curve, -#' noise_params = noise %>% filter(Country == "Pakistan"), +#' noise_params = noise |> filter(Country == "Pakistan"), #' antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #' #num_cores = 8 # Allow for parallel processing to decrease run time #' ) @@ -74,20 +74,20 @@ summary.seroincidence.by <- function( } results <- - object %>% + object |> lapply( FUN = summary.seroincidence, coverage = confidence_level - ) %>% + ) |> bind_rows(.id = "Stratum") results <- inner_join( - object %>% attr("Strata"), + object |> attr("Strata"), results, by = "Stratum", relationship = "one-to-one" - ) %>% + ) |> relocate("Stratum", .before = everything()) @@ -96,7 +96,7 @@ summary.seroincidence.by <- function( } if (showConvergence) { - results <- results %>% + results <- results |> relocate("nlm.convergence.code", .after = everything()) } else { results$nlm.convergence.code <- NULL @@ -105,13 +105,13 @@ summary.seroincidence.by <- function( output <- - results %>% + results |> structure( antigen_isos = attr(object, "antigen_isos"), - Strata = attr(object, "Strata") %>% attr("strata_vars"), + Strata = attr(object, "Strata") |> attr("strata_vars"), Quantiles = quantiles, class = - "summary.seroincidence.by" %>% + "summary.seroincidence.by" |> union(class(results)) ) diff --git a/R/warn_missing_strata.R b/R/warn_missing_strata.R index 6946e314..1c5cc71a 100644 --- a/R/warn_missing_strata.R +++ b/R/warn_missing_strata.R @@ -35,9 +35,9 @@ warn.missing.strata <- function( "`", dataname, "` is missing some strata variables: `", - missing_strata_vars %>% paste(collapse = "`, `"), + missing_strata_vars |> paste(collapse = "`, `"), "`\n`", dataname, "` will only be stratified by: `", - present_strata_vars %>% paste(collapse = "` , `"), + present_strata_vars |> paste(collapse = "` , `"), "`" ) } else { @@ -57,14 +57,14 @@ warn.missing.strata <- function( } if (length(present_strata_vars) > 0) { - strata2 <- data %>% count_strata(present_strata_vars) + strata2 <- data |> count_strata(present_strata_vars) missing_strata <- anti_join( strata, strata2, by = present_strata_vars - ) %>% + ) |> distinct(across(all_of(present_strata_vars))) if (nrow(missing_strata) > 0) { diff --git a/data-raw/profile-fdev.R b/data-raw/profile-fdev.R index 2b8cfb16..01daceb7 100644 --- a/data-raw/profile-fdev.R +++ b/data-raw/profile-fdev.R @@ -5,7 +5,7 @@ library(tibble) # load in longitudinal parameters curve_params = load_curve_params("https://osf.io/download/rtw5k") -xs_data <- "https://osf.io/download//n6cp3/" %>% load_pop_data() +xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() #Load noise params noise_params <- tibble( @@ -18,23 +18,23 @@ noise_params <- tibble( cur_antibody = "HlyE_IgA" cur_data = - xs_data %>% + xs_data |> dplyr::filter( .data$catchment == "dhaka", .data$antigen_iso == cur_antibody) cur_curve_params = - curve_params %>% + curve_params |> dplyr::filter(.data$antigen_iso == cur_antibody) cur_noise_params = - noise_params %>% + noise_params |> dplyr::filter(.data$antigen_iso == cur_antibody) if(!is.element('d', names(cur_curve_params))) { cur_curve_params = - cur_curve_params %>% + cur_curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1) diff --git a/data-raw/sees_datacleaning.R b/data-raw/sees_datacleaning.R index 0f2b3133..471ee850 100644 --- a/data-raw/sees_datacleaning.R +++ b/data-raw/sees_datacleaning.R @@ -5,16 +5,16 @@ library(readr) d0 <- read.csv( "inst/extdata/SEES_2022-10-24_redacted_2023-10-12.csv", header = T -) %>% - # filter(antigen != "CdtB" | antigen != "YncE") %>% +) |> + # filter(antigen != "CdtB" | antigen != "YncE") |> filter( studyarm != "highE_hh", studyarm != "lowE_hh", studyarm != "ae control" - ) %>% + ) |> mutate( antigen_iso = - paste(elisa_antigen, "_", elisa_antbdy_iso, sep = "") %>% + paste(elisa_antigen, "_", elisa_antbdy_iso, sep = "") |> factor(), ageCat = cut( Age, @@ -22,28 +22,28 @@ d0 <- read.csv( right = FALSE, labels = c("<5", "5-15", "16+") ), TimePeriod = - TimePeriod %>% + TimePeriod |> factor(levels = c("Baseline", "28 days", "3 months", "6 months", "12 months", "18 months", "First visit")), Arm2 = - Arm %>% - fct_collapse(Cases = c("Prospective Cases", "Retrospective Cases")) %>% + Arm |> + fct_collapse(Cases = c("Prospective Cases", "Retrospective Cases")) |> factor( levels = c("Cases", "Population-based"), labels = c("Cases", "Population sample") ), - sex = sex %>% as.factor() %>% fct_collapse(NULL = c("97")) - ) %>% - mutate(Gender = factor(sex, labels = c("Male", "Female"))) %>% - filter(Age <= 25) %>% - filter(catchment != "matiari") %>% - filter(catchment != "mirzapur") %>% - mutate(cluster = areaunit3) %>% - droplevels() %>% - filter(Arm2 == "Population sample" & TimePeriod == "Baseline") %>% - select(Country, cluster, catchment, Age, ageCat, antigen_iso, result) %>% - mutate(cluster = factor(cluster)) %>% - filter(antigen_iso %in% c("HlyE_IgG", "HlyE_IgA")) %>% - as_tibble() %>% + sex = sex |> as.factor() |> fct_collapse(NULL = c("97")) + ) |> + mutate(Gender = factor(sex, labels = c("Male", "Female"))) |> + filter(Age <= 25) |> + filter(catchment != "matiari") |> + filter(catchment != "mirzapur") |> + mutate(cluster = areaunit3) |> + droplevels() |> + filter(Arm2 == "Population sample" & TimePeriod == "Baseline") |> + select(Country, cluster, catchment, Age, ageCat, antigen_iso, result) |> + mutate(cluster = factor(cluster)) |> + filter(antigen_iso %in% c("HlyE_IgG", "HlyE_IgA")) |> + as_tibble() |> select(-cluster) sees_crossSectional_baseline_allCountries <- d0 diff --git a/data-raw/typhoid-controls.R b/data-raw/typhoid-controls.R index f490c573..e57ad51c 100644 --- a/data-raw/typhoid-controls.R +++ b/data-raw/typhoid-controls.R @@ -1,7 +1,7 @@ library(readr) tc <- read_csv("inst/extdata/typhoidcontrols.csv") -tc %>% +tc |> summarize( .by = c(, antigen_iso), nu = quantile( diff --git a/data-raw/typhoid_results.R b/data-raw/typhoid_results.R index 56838c0c..8146c572 100644 --- a/data-raw/typhoid_results.R +++ b/data-raw/typhoid_results.R @@ -5,11 +5,11 @@ xs_data <- load_pop_data( value = "result", id = "index_id", standardize = TRUE -) %>% +) |> filter(Country == "Pakistan") # get noise data -noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% +noise <- load_noise_params("https://osf.io/download//hqy4v/") |> filter(Country == "Pakistan") # get curve data @@ -26,15 +26,15 @@ fit <- est.incidence( antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) -typhoid_results <- fit %>% +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/man/as_curve_params.Rd b/man/as_curve_params.Rd index 5bdb2cd7..020a15a0 100644 --- a/man/as_curve_params.Rd +++ b/man/as_curve_params.Rd @@ -22,8 +22,8 @@ Load antibody decay curve parameter \examples{ library(magrittr) curve_data <- - "https://osf.io/download/rtw5k/" \%>\% - readr::read_rds() \%>\% + "https://osf.io/download/rtw5k/" |> + readr::read_rds() |> as_curve_params() print(curve_data) diff --git a/man/as_noise_params.Rd b/man/as_noise_params.Rd index 39a29306..3c9b1aab 100644 --- a/man/as_noise_params.Rd +++ b/man/as_noise_params.Rd @@ -22,8 +22,8 @@ Load noise parameters \examples{ library(magrittr) noise_data <- - "https://osf.io/download//hqy4v/" \%>\% - readr::read_rds() \%>\% + "https://osf.io/download//hqy4v/" |> + readr::read_rds() |> as_noise_params() print(noise_data) diff --git a/man/as_pop_data.Rd b/man/as_pop_data.Rd index 9e548d90..a849782a 100644 --- a/man/as_pop_data.Rd +++ b/man/as_pop_data.Rd @@ -35,8 +35,8 @@ Load a cross-sectional antibody survey data set \examples{ library(magrittr) xs_data <- - "https://osf.io/download//n6cp3/" \%>\% - readr::read_rds() \%>\% + "https://osf.io/download//n6cp3/" |> + readr::read_rds() |> as_pop_data() print(xs_data) diff --git a/man/autoplot.curve_params.Rd b/man/autoplot.curve_params.Rd index 933c45f6..364b537e 100644 --- a/man/autoplot.curve_params.Rd +++ b/man/autoplot.curve_params.Rd @@ -66,9 +66,9 @@ library(dplyr) library(ggplot2) library(magrittr) -curve = load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% - slice(1:100, .by = antigen_iso) \%>\% # Reduce dataset for this example +curve = load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> + slice(1:100, .by = antigen_iso) |> # Reduce dataset for this example autoplot() curve diff --git a/man/autoplot.pop_data.Rd b/man/autoplot.pop_data.Rd index c6e0908b..8254fca0 100644 --- a/man/autoplot.pop_data.Rd +++ b/man/autoplot.pop_data.Rd @@ -37,6 +37,6 @@ xs_data <- load_pop_data( standardize = TRUE ) -xs_data \%>\% autoplot(strata = "Country", type = "density") -xs_data \%>\% autoplot(strata = "Country", type = "age-scatter") +xs_data |> autoplot(strata = "Country", type = "density") +xs_data |> autoplot(strata = "Country", type = "age-scatter") } diff --git a/man/autoplot.seroincidence.Rd b/man/autoplot.seroincidence.Rd index a5800d12..d84d6713 100644 --- a/man/autoplot.seroincidence.Rd +++ b/man/autoplot.seroincidence.Rd @@ -26,16 +26,16 @@ library(ggplot2) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est1 <- est.incidence( - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_param = curve, - noise_param = noise \%>\% filter(Country == "Pakistan"), + noise_param = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), build_graph = TRUE ) diff --git a/man/autoplot.seroincidence.by.Rd b/man/autoplot.seroincidence.by.Rd index afb996f8..18516bcc 100644 --- a/man/autoplot.seroincidence.by.Rd +++ b/man/autoplot.seroincidence.by.Rd @@ -28,20 +28,20 @@ Plots log-likelihood curves by stratum, for \code{seroincidence.by} objects library(dplyr) library(ggplot2) -xs_data <- "https://osf.io/download//n6cp3/" \%>\% +xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est2 <- est.incidence.by( strata = c("catchment"), - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curve, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #num_cores = 8, #Allow for parallel processing to decrease run time build_graph = TRUE diff --git a/man/autoplot.summary.seroincidence.by.Rd b/man/autoplot.summary.seroincidence.by.Rd index fd470fd8..dd48e536 100644 --- a/man/autoplot.summary.seroincidence.by.Rd +++ b/man/autoplot.summary.seroincidence.by.Rd @@ -32,17 +32,17 @@ library(ggplot2) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est2 <- est.incidence.by( strata = c("catchment"), - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curve, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #num_cores = 8 #Allow for parallel processing to decrease run time ) diff --git a/man/check_pop_data.Rd b/man/check_pop_data.Rd index 072347fa..52e736ee 100644 --- a/man/check_pop_data.Rd +++ b/man/check_pop_data.Rd @@ -19,7 +19,7 @@ Check the formatting of a cross-sectional antibody survey dataset. } \examples{ library(dplyr) -xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") \%>\% +xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") |> as_pop_data() check_pop_data(xs_data, verbose = TRUE) diff --git a/man/df_to_array.Rd b/man/df_to_array.Rd index c915245f..3c278a56 100644 --- a/man/df_to_array.Rd +++ b/man/df_to_array.Rd @@ -27,13 +27,13 @@ Convert a data.frame (or tibble) into a multidimensional array library(dplyr) library(tidyr) -df <- iris \%>\% +df <- iris |> tidyr::pivot_longer( names_to = "parameter", cols = c("Sepal.Length", "Sepal.Width", "Petal.Width", "Petal.Length") - ) \%>\% + ) |> mutate(parameter = factor(parameter, levels = unique(parameter))) -arr <- df \%>\% +arr <- df |> serocalculator:::df_to_array( dim_var_names = c("parameter", "Species")) ftable(arr[,,1:5]) diff --git a/man/est.incidence.Rd b/man/est.incidence.Rd index ce207ed6..751a6b19 100644 --- a/man/est.incidence.Rd +++ b/man/est.incidence.Rd @@ -8,7 +8,7 @@ est.incidence( pop_data, curve_params, noise_params, - antigen_isos = pop_data$antigen_iso \%>\% unique(), + antigen_isos = unique(pop_data$antigen_iso), lambda_start = 0.1, stepmin = 1e-08, stepmax = 3, @@ -101,16 +101,16 @@ library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curves <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curves <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est1 <- est.incidence( - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curves, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), iterlim = 5 # limit iterations for the purpose of this example ) diff --git a/man/est.incidence.by.Rd b/man/est.incidence.by.Rd index 3111521c..6d7d3a87 100644 --- a/man/est.incidence.by.Rd +++ b/man/est.incidence.by.Rd @@ -11,7 +11,7 @@ est.incidence.by( strata, curve_strata_varnames = strata, noise_strata_varnames = strata, - antigen_isos = pop_data \%>\% pull("antigen_iso") \%>\% unique(), + antigen_isos = unique(pull(pop_data, "antigen_iso")), lambda_start = 0.1, build_graph = FALSE, num_cores = 1L, @@ -123,17 +123,17 @@ library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est2 <- est.incidence.by( strata = c("catchment"), - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curve, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #num_cores = 8 # Allow for parallel processing to decrease run time iterlim = 5 # limit iterations for the purpose of this example diff --git a/man/f_dev.Rd b/man/f_dev.Rd index 354d1461..46bcc638 100644 --- a/man/f_dev.Rd +++ b/man/f_dev.Rd @@ -26,7 +26,7 @@ library(tibble) # load in longitudinal parameters curve_params = load_curve_params("https://osf.io/download/rtw5k") -xs_data <- "https://osf.io/download//n6cp3/" \%>\% +xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() #Load noise params @@ -40,25 +40,25 @@ noise_params <- tibble( cur_antibody = "HlyE_IgA" cur_data = - xs_data \%>\% + xs_data |> dplyr::filter( .data$catchment == "dhaka", - .data$antigen_iso == cur_antibody) \%>\% + .data$antigen_iso == cur_antibody) |> dplyr::slice_head(n = 100) cur_curve_params = - curve_params \%>\% - dplyr::filter(.data$antigen_iso == cur_antibody) \%>\% + curve_params |> + dplyr::filter(.data$antigen_iso == cur_antibody) |> dplyr::slice_head(n = 100) cur_noise_params = - noise_params \%>\% + noise_params |> dplyr::filter(.data$antigen_iso == cur_antibody) if(!is.element('d', names(cur_curve_params))) { cur_curve_params = - cur_curve_params \%>\% + cur_curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1) diff --git a/man/f_dev0.Rd b/man/f_dev0.Rd index 0b3129f7..6268214f 100644 --- a/man/f_dev0.Rd +++ b/man/f_dev0.Rd @@ -31,7 +31,7 @@ library(tibble) # load in longitudinal parameters curve_params = load_curve_params("https://osf.io/download/rtw5k") -xs_data <- "https://osf.io/download//n6cp3/" \%>\% +xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() #Load noise params @@ -45,25 +45,25 @@ noise_params <- tibble( cur_antibody = "HlyE_IgA" cur_data <- - xs_data \%>\% + xs_data |> dplyr::filter( .data$catchment == "dhaka", - .data$antigen_iso == cur_antibody) \%>\% + .data$antigen_iso == cur_antibody) |> dplyr::slice_head(n = 100) cur_curve_params <- - curve_params \%>\% - dplyr::filter(.data$antigen_iso == cur_antibody) \%>\% + curve_params |> + dplyr::filter(.data$antigen_iso == cur_antibody) |> dplyr::slice_head(n = 100) cur_noise_params <- - noise_params \%>\% + noise_params |> dplyr::filter(.data$antigen_iso == cur_antibody) if(!is.element('d', names(cur_curve_params))) { cur_curve_params <- - cur_curve_params \%>\% + cur_curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1) diff --git a/man/graph_loglik.Rd b/man/graph_loglik.Rd index efd15a33..d53abcfc 100644 --- a/man/graph_loglik.Rd +++ b/man/graph_loglik.Rd @@ -8,7 +8,7 @@ graph_loglik( pop_data, curve_params, noise_params, - antigen_isos = pop_data \%>\% get_biomarker_levels(), + antigen_isos = get_biomarker_levels(pop_data), x = 10^seq(-3, 0, by = 0.1), highlight_points = NULL, highlight_point_names = "highlight_points", @@ -88,8 +88,8 @@ xs_data <- load_pop_data("https://osf.io/download//n6cp3/") # Load curve parameters and subset for the purposes of this example -dmcmc <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +dmcmc <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Load noise parameters diff --git a/man/log_likelihood.Rd b/man/log_likelihood.Rd index 7a9267e9..1d8bd71b 100644 --- a/man/log_likelihood.Rd +++ b/man/log_likelihood.Rd @@ -69,7 +69,7 @@ library(tibble) # load in longitudinal parameters dmcmc <- load_curve_params("https://osf.io/download/rtw5k") -xs_data <- "https://osf.io/download//n6cp3/" \%>\% +xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() # Load noise params @@ -88,6 +88,6 @@ ll_AG <- log_likelihood( noise_params = cond, antigen_isos = c("HlyE_IgG", "HlyE_IgA"), lambda = 0.1 -) \%>\% print() +) |> print() } diff --git a/man/plot_curve_params_one_ab.Rd b/man/plot_curve_params_one_ab.Rd index 9b312a07..54b3960e 100644 --- a/man/plot_curve_params_one_ab.Rd +++ b/man/plot_curve_params_one_ab.Rd @@ -113,10 +113,10 @@ then \code{n_curves} has no effect. } } \examples{ -library(dplyr) # loads the `\%>\%` operator and `dplyr::filter()` +library(dplyr) # loads the `|>` operator and `dplyr::filter()` -load_curve_params("https://osf.io/download/rtw5k/") \%>\% - dplyr::filter(antigen_iso == "HlyE_IgG") \%>\% +load_curve_params("https://osf.io/download/rtw5k/") |> + dplyr::filter(antigen_iso == "HlyE_IgG") |> serocalculator:::plot_curve_params_one_ab() } diff --git a/man/stratify_data.Rd b/man/stratify_data.Rd index fba7c6f0..6c02c78c 100644 --- a/man/stratify_data.Rd +++ b/man/stratify_data.Rd @@ -11,7 +11,7 @@ stratify_data( strata_varnames = "", curve_strata_varnames = NULL, noise_strata_varnames = NULL, - antigen_isos = data \%>\% attr("antigen_isos") + antigen_isos = attr(data, "antigen_isos") ) } \arguments{ @@ -63,8 +63,8 @@ library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") diff --git a/man/summary.seroincidence.Rd b/man/summary.seroincidence.Rd index 3955a4cc..08e7dcc5 100644 --- a/man/summary.seroincidence.Rd +++ b/man/summary.seroincidence.Rd @@ -44,16 +44,16 @@ library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curves <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curves <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est1 <- est.incidence( - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curves, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) diff --git a/man/summary.seroincidence.by.Rd b/man/summary.seroincidence.by.Rd index b6db08be..86336861 100644 --- a/man/summary.seroincidence.by.Rd +++ b/man/summary.seroincidence.by.Rd @@ -50,17 +50,17 @@ library(dplyr) xs_data <- load_pop_data("https://osf.io/download//n6cp3/") -curve <- load_curve_params("https://osf.io/download/rtw5k/") \%>\% - filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) \%>\% +curve <- load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso \%in\% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- load_noise_params("https://osf.io/download//hqy4v/") est2 <- est.incidence.by( strata = c("catchment"), - pop_data = xs_data \%>\% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_params = curve, - noise_params = noise \%>\% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA"), #num_cores = 8 # Allow for parallel processing to decrease run time ) diff --git a/tests/testthat/_snaps/df_to_array.md b/tests/testthat/_snaps/df_to_array.md index b2c92f13..9826916b 100644 --- a/tests/testthat/_snaps/df_to_array.md +++ b/tests/testthat/_snaps/df_to_array.md @@ -107,5 +107,8 @@ AAABAAQACQAAAAVjbGFzcwAAABAAAAACAAQACQAAAAV4dGFicwAEAAkAAAAFdGFibGUAAAQC AAAAAQAEAAkAAAAEY2FsbAAAAAYAAAABAAQACQAAAAV4dGFicwAABAIAAAABAAQACQAAAAdm b3JtdWxhAAAABgAAB/8AAAACAAAAAQAEAAkAAAANeHRhYnNfZm9ybXVsYQAAAP4AAAQCAAAA - AQAEAAkAAAAEZGF0YQAAAAEABAAJAAAAAS4AAAD+AAAA/g== + AQAEAAkAAAAEZGF0YQAAAAYAAAABAAQACQAAAAZtdXRhdGUAAAAGAAAAAQAEAAkAAAACZGYA + AAQCAAAAAQAEAAkAAAADLmJ5AAAABgAAAAEABAAJAAAABmFsbF9vZgAAAAIAAAABAAQACQAA + AA1kaW1fdmFyX25hbWVzAAAA/gAABAIAAAABAAQACQAAAANvYnMAAAAGAAAAAQAEAAkAAAAK + cm93X251bWJlcgAAAP4AAAD+AAAA/gAAAP4= diff --git a/tests/testthat/_snaps/summary.pop_data.md b/tests/testthat/_snaps/summary.pop_data.md index 31775ed4..40fe163c 100644 --- a/tests/testthat/_snaps/summary.pop_data.md +++ b/tests/testthat/_snaps/summary.pop_data.md @@ -1,7 +1,7 @@ # `summary.pop_data()` produces stable results when `strata = NULL` Code - xs_data %>% summary(strata = NULL) + summary(xs_data, strata = NULL) Output n = 3336 @@ -25,7 +25,7 @@ # `summary.pop_data()` produces stable results with stratification Code - xs_data %>% summary(strata = "Country") + summary(xs_data, strata = "Country") Output n = 3336 diff --git a/tests/testthat/test-as_curve_params.R b/tests/testthat/test-as_curve_params.R index 6e5e6a83..4c31304c 100644 --- a/tests/testthat/test-as_curve_params.R +++ b/tests/testthat/test-as_curve_params.R @@ -3,8 +3,8 @@ test_that("`as_curve_params()` produces an error library(magrittr) expect_error( object = curve_data <- - "https://osf.io/download//n6cp3/" %>% # pop data - readr::read_rds() %>% + "https://osf.io/download//n6cp3/" |> # pop data + readr::read_rds() |> as_curve_params(), class = "not curve_params" ) @@ -15,22 +15,22 @@ test_that("`as_curve_params()` produces an error { library(magrittr) expect_error(object = - "https://osf.io/download//n6cp3/" %>% # pop data + "https://osf.io/download//n6cp3/" |> # pop data as_curve_params(), class = "not data.frame") }) test_that("`as_curve_params()` produces expected results", { library(dplyr) - test_data <- "https://osf.io/download/rtw5k/" %>% # curve data - readr::read_rds() %>% - slice_head(n = 100) %>% + test_data <- "https://osf.io/download/rtw5k/" |> # curve data + readr::read_rds() |> + slice_head(n = 100) |> as_curve_params() expect_snapshot(test_data) expect_snapshot_value(x = test_data, style = "serialize") - test_data %>% ssdtools:::expect_snapshot_data(name = "curve-data") + test_data |> ssdtools:::expect_snapshot_data(name = "curve-data") }) diff --git a/tests/testthat/test-as_noise_params.R b/tests/testthat/test-as_noise_params.R index 4172bf0f..cc225d15 100644 --- a/tests/testthat/test-as_noise_params.R +++ b/tests/testthat/test-as_noise_params.R @@ -3,8 +3,8 @@ test_that("`as_noise_params()` produces an error library(magrittr) expect_error( object = noise_data <- - "https://osf.io/download//n6cp3/" %>% # pop data - readr::read_rds() %>% + "https://osf.io/download//n6cp3/" |> # pop data + readr::read_rds() |> as_noise_params(), class = "not noise_params" ) @@ -12,8 +12,8 @@ test_that("`as_noise_params()` produces an error test_that("`as_noise_params()` produces expected results", { library(dplyr) - test_data <- "https://osf.io/download//hqy4v/" %>% # noise data - readr::read_rds() %>% + test_data <- "https://osf.io/download//hqy4v/" |> # noise data + readr::read_rds() |> as_noise_params() expect_snapshot(test_data) @@ -29,8 +29,8 @@ test_that("`as_noise_params()` produces error when library(dplyr) expect_error( - object = "https://osf.io/download//hqy4v/" %>% # noise data - readr::read_rds() %>% + object = "https://osf.io/download//hqy4v/" |> # noise data + readr::read_rds() |> as_noise_params(antigen_iso = "HlyE_IgB"), class = "missing-antigen" ) @@ -41,7 +41,7 @@ test_that("`as_noise_params()` produces error when library(dplyr) expect_error( - object = "a string sample" %>% # random string + object = "a string sample" |> # random string as_noise_params(), class = "not data.frame" ) diff --git a/tests/testthat/test-autoplot.pop_data.R b/tests/testthat/test-autoplot.pop_data.R index 1c3c649a..66a0f8b4 100644 --- a/tests/testthat/test-autoplot.pop_data.R +++ b/tests/testthat/test-autoplot.pop_data.R @@ -8,7 +8,7 @@ test_that("`autoplot.pop_data()` raise value = "result", standardize = TRUE ) - expect_error(object = xs_data %>% + expect_error(object = xs_data |> autoplot(strata = "Country", type = "den")) }) @@ -22,7 +22,7 @@ test_that("`autoplot.pop_data()` raise value = "result", standardize = TRUE ) - expect_error(object = xs_data %>% + expect_error(object = xs_data |> autoplot(strata = "strat1", type = "density")) }) @@ -36,8 +36,8 @@ test_that("`autoplot.pop_data()` produces id = "index_id", value = "result", standardize = TRUE - ) %>% - autoplot(strata = "Country", type = "density") %>% + ) |> + autoplot(strata = "Country", type = "density") |> vdiffr::expect_doppelganger(title = "density") }) @@ -51,8 +51,8 @@ test_that("`autoplot.pop_data()` produces stable results for id = "index_id", value = "result", standardize = TRUE - ) %>% - autoplot(strata = "Country", type = "age-scatter") %>% + ) |> + autoplot(strata = "Country", type = "age-scatter") |> vdiffr::expect_doppelganger(title = "age_scatter_strat_country") }) @@ -65,7 +65,7 @@ test_that("`autoplot.pop_data()` produces stable results id = "index_id", value = "result", standardize = TRUE - ) %>% - autoplot(strata = NULL, type = "age-scatter") %>% + ) |> + autoplot(strata = NULL, type = "age-scatter") |> vdiffr::expect_doppelganger(title = "age_scatter_no_strat") }) diff --git a/tests/testthat/test-check_pop_data.R b/tests/testthat/test-check_pop_data.R index f2a1752c..a8a9ccc6 100644 --- a/tests/testthat/test-check_pop_data.R +++ b/tests/testthat/test-check_pop_data.R @@ -1,22 +1,22 @@ test_that("`check_pop_data()` works", { library(dplyr) - xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>% + xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") |> as_pop_data() - xs_data %>% check_pop_data() |> + xs_data |> check_pop_data() |> expect_no_condition() - xs_data %>% check_pop_data(verbose = TRUE) |> + xs_data |> check_pop_data(verbose = TRUE) |> expect_message("data format is as expected.") - xs_data_no_age = xs_data %>% select(-age) - xs_data_no_age %>% check_pop_data() |> + xs_data_no_age = xs_data |> select(-age) + xs_data_no_age |> check_pop_data() |> expect_error(class = "missing-var") - xs_data_no_value = xs_data %>% select(-value) - xs_data_no_value %>% check_pop_data() |> + xs_data_no_value = xs_data |> select(-value) + xs_data_no_value |> check_pop_data() |> expect_error(class = "missing-var") - "string" %>% check_pop_data() |> + "string" |> check_pop_data() |> expect_error(class = "not a data.frame") }) diff --git a/tests/testthat/test-class_attributes.R b/tests/testthat/test-class_attributes.R index a94efd7b..2e039bc4 100644 --- a/tests/testthat/test-class_attributes.R +++ b/tests/testthat/test-class_attributes.R @@ -1,7 +1,7 @@ test_that("`get_biomarker_levels()` works", { - xs_data <- "https://osf.io/download//n6cp3/" %>% + xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() - biomarker_levels <- xs_data %>% get_biomarker_levels() + biomarker_levels <- xs_data |> get_biomarker_levels() expected_levels <- structure(1:2, levels = c("HlyE_IgA", "HlyE_IgG"), class = "factor") @@ -9,20 +9,20 @@ test_that("`get_biomarker_levels()` works", { }) test_that("`get_id()` works", { - xs_data <- "https://osf.io/download//n6cp3/" %>% + xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() - xs_data %>% - get_id() %>% - sort() %>% + xs_data |> + get_id() |> + sort() |> expect_snapshot_value(style = "deparse") }) test_that("`get_biomarker_names_var() works", { biomarker_names_var <- - "https://osf.io/download//n6cp3/" %>% - load_pop_data() %>% + "https://osf.io/download//n6cp3/" |> + load_pop_data() |> get_biomarker_names_var() expect_equal(object = biomarker_names_var, expected = "antigen_iso") @@ -30,7 +30,7 @@ test_that("`get_biomarker_names_var() works", { test_that("`set_age()` detects partial matches", { - "https://osf.io/download//n6cp3/" %>% - load_pop_data(age = "age$") %>% + "https://osf.io/download//n6cp3/" |> + load_pop_data(age = "age$") |> expect_warning(class = "missing variable") }) diff --git a/tests/testthat/test-df_to_array.R b/tests/testthat/test-df_to_array.R index 39b760aa..954ea42e 100644 --- a/tests/testthat/test-df_to_array.R +++ b/tests/testthat/test-df_to_array.R @@ -1,7 +1,7 @@ test_that("df_to_array() produces consistent results", { library(dplyr) library(tidyr) - df <- iris %>% + df <- iris |> tidyr::pivot_longer( names_to = "parameter", cols = c( @@ -10,9 +10,9 @@ test_that("df_to_array() produces consistent results", { "Petal.Width", "Petal.Length" ) - ) %>% + ) |> mutate(parameter = factor(parameter, levels = unique(parameter))) - arr <- df %>% + arr <- df |> serocalculator:::df_to_array(dim_var_names = c("parameter", "Species")) - arr %>% expect_snapshot_value(style = "serialize") + arr |> expect_snapshot_value(style = "serialize") }) diff --git a/tests/testthat/test-est.incidence.R b/tests/testthat/test-est.incidence.R index 59f479e8..8b2d1cad 100644 --- a/tests/testthat/test-est.incidence.R +++ b/tests/testthat/test-est.incidence.R @@ -9,12 +9,12 @@ test_that( value = "result", id = "index_id", standardize = TRUE - ) %>% - filter(Country == "Pakistan") %>% + ) |> + filter(Country == "Pakistan") |> slice_head(n = 100) # get noise data - noise <- load_noise_params("https://osf.io/download//hqy4v/") %>% + noise <- load_noise_params("https://osf.io/download//hqy4v/") |> filter(Country == "Pakistan") # get curve data @@ -28,7 +28,7 @@ test_that( curve_param = curve, noise_param = noise, antigen_isos = c("HlyE_IgG", "HlyE_IgA") - ) %>% + ) |> summary.seroincidence( coverage = .95, start = start @@ -47,15 +47,15 @@ test_that("`est.incidence()` produces expected results", { value = "result", id = "index_id", standardize = TRUE - ) %>% - filter(Country == "Pakistan") %>% + ) |> + filter(Country == "Pakistan") |> slice_head(n = 100) est_true <- est.incidence( pop_data = xs_data_true, curve_params = curves, - noise_params = noise %>% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) @@ -65,15 +65,15 @@ test_that("`est.incidence()` produces expected results", { value = "result", id = "index_id", standardize = FALSE - ) %>% - filter(Country == "Pakistan") %>% + ) |> + filter(Country == "Pakistan") |> slice_head(n = 100) est_false <- est.incidence( pop_data = xs_data_false, curve_params = curves, - noise_params = noise %>% filter(Country == "Pakistan"), + noise_params = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) diff --git a/tests/testthat/test-f_dev.R b/tests/testthat/test-f_dev.R index f176e348..a6ec232b 100644 --- a/tests/testthat/test-f_dev.R +++ b/tests/testthat/test-f_dev.R @@ -5,7 +5,7 @@ test_that("`f_dev0()` and `f_dev()` produce stable results", { # load in longitudinal parameters curve_params = load_curve_params("https://osf.io/download/rtw5k") - xs_data <- "https://osf.io/download//n6cp3/" %>% load_pop_data() + xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() #Load noise params noise_params <- tibble( @@ -18,25 +18,25 @@ test_that("`f_dev0()` and `f_dev()` produce stable results", { cur_antibody = "HlyE_IgA" cur_data = - xs_data %>% + xs_data |> dplyr::filter( .data$catchment == "dhaka", - .data$antigen_iso == cur_antibody) %>% + .data$antigen_iso == cur_antibody) |> slice_head(n = 100) cur_curve_params = - curve_params %>% - dplyr::filter(.data$antigen_iso == cur_antibody) %>% + curve_params |> + dplyr::filter(.data$antigen_iso == cur_antibody) |> slice_head(n = 100) cur_noise_params = - noise_params %>% + noise_params |> dplyr::filter(.data$antigen_iso == cur_antibody) if(!is.element('d', names(cur_curve_params))) { cur_curve_params = - cur_curve_params %>% + cur_curve_params |> dplyr::mutate( alpha = .data$alpha * 365.25, d = .data$r - 1) diff --git a/tests/testthat/test-load_pop_data.R b/tests/testthat/test-load_pop_data.R index 0639a936..54d178a2 100644 --- a/tests/testthat/test-load_pop_data.R +++ b/tests/testthat/test-load_pop_data.R @@ -18,6 +18,6 @@ test_that("`load_pop_data()` produces expected results", { true_col_names <- c("id", "Country", "cluster", "catchment", "age", "ageCat", "antigen_iso", "value") false_col_names <- c("index_id", "Country", "cluster", "catchment", "Age", "ageCat", "antigen_iso", "result") - expect_equal(xs_data_true %>% names(), true_col_names) - expect_equal(xs_data_false %>% names(), false_col_names) + expect_equal(xs_data_true |> names(), true_col_names) + expect_equal(xs_data_false |> names(), false_col_names) }) diff --git a/tests/testthat/test-log_likelihood.R b/tests/testthat/test-log_likelihood.R index 0a4e3d72..fcdf6d85 100644 --- a/tests/testthat/test-log_likelihood.R +++ b/tests/testthat/test-log_likelihood.R @@ -5,7 +5,7 @@ test_that("`log_likelihood()` gives consistent results", { # load in longitudinal parameters dmcmc <- load_curve_params("https://osf.io/download/rtw5k") - xs_data <- "https://osf.io/download//n6cp3/" %>% + xs_data <- "https://osf.io/download//n6cp3/" |> load_pop_data() # Load noise params diff --git a/tests/testthat/test-set_biomarker_var.R b/tests/testthat/test-set_biomarker_var.R index 31feb13b..7700b481 100644 --- a/tests/testthat/test-set_biomarker_var.R +++ b/tests/testthat/test-set_biomarker_var.R @@ -1,6 +1,6 @@ test_that("`set_biomarker_var()` halts on misspecified column", { - xs_data <- "https://osf.io/download//n6cp3/" %>% - readr::read_rds() %>% - set_biomarker_var("biomarker") %>% + xs_data <- "https://osf.io/download//n6cp3/" |> + readr::read_rds() |> + set_biomarker_var("biomarker") |> expect_error(class = "missing variable") }) diff --git a/tests/testthat/test-stratify_data.R b/tests/testthat/test-stratify_data.R index 546a623b..abf7253e 100644 --- a/tests/testthat/test-stratify_data.R +++ b/tests/testthat/test-stratify_data.R @@ -4,17 +4,17 @@ test_that("stratify_data() produces consistent results", { library(readr) xs_data <- - read_rds("https://osf.io/download//n6cp3/") %>% - as_pop_data() %>% + read_rds("https://osf.io/download//n6cp3/") |> + as_pop_data() |> filter(Country == "Pakistan") curve <- - load_curve_params("https://osf.io/download/rtw5k/") %>% - filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% + load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- - load_noise_params("https://osf.io/download//hqy4v/") %>% + load_noise_params("https://osf.io/download//hqy4v/") |> filter(Country == "Pakistan") stratified_data = @@ -36,17 +36,17 @@ test_that("stratify_data() warns about missing data", { library(readr) xs_data <- - read_rds("https://osf.io/download//n6cp3/") %>% - as_pop_data() %>% + read_rds("https://osf.io/download//n6cp3/") |> + as_pop_data() |> filter(Country == "Nepal") curve <- - load_curve_params("https://osf.io/download/rtw5k/") %>% - filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) %>% + load_curve_params("https://osf.io/download/rtw5k/") |> + filter(antigen_iso %in% c("HlyE_IgA", "HlyE_IgG")) |> slice(1:100, .by = antigen_iso) # Reduce dataset for the purposes of this example noise <- - load_noise_params("https://osf.io/download//hqy4v/") %>% + load_noise_params("https://osf.io/download//hqy4v/") |> filter(Country == "Nepal") stratify_data( diff --git a/tests/testthat/test-summary.pop_data.R b/tests/testthat/test-summary.pop_data.R index 298f712e..2c6a2238 100644 --- a/tests/testthat/test-summary.pop_data.R +++ b/tests/testthat/test-summary.pop_data.R @@ -8,16 +8,16 @@ xs_data <- load_pop_data( test_that("`summary.pop_data()` produces an error when wrong stratification is provided", { expect_error( - object = xs_data %>% summary(strata = "province"), + object = xs_data |> summary(strata = "province"), regexp = "Element `province` doesn't exist.", fixed = TRUE ) }) test_that("`summary.pop_data()` produces stable results when `strata = NULL`", { - expect_snapshot(xs_data %>% summary(strata = NULL)) + expect_snapshot(xs_data |> summary(strata = NULL)) }) test_that("`summary.pop_data()` produces stable results with stratification", { - expect_snapshot(xs_data %>% summary(strata = "Country")) + expect_snapshot(xs_data |> summary(strata = "Country")) }) diff --git a/tests/testthat/test-warn_missing_strata.R b/tests/testthat/test-warn_missing_strata.R index 06c2f6f0..47e0c306 100644 --- a/tests/testthat/test-warn_missing_strata.R +++ b/tests/testthat/test-warn_missing_strata.R @@ -1,9 +1,9 @@ test_that("`test_missing_strata()` works", { expected_strata <- data.frame(Species = "banana", type = "orchid") - warn.missing.strata(iris, expected_strata, dataname = "iris") %>% - capture.output() %>% # not sure this works as intended - suppressMessages() %>% - expect_error() %>% + warn.missing.strata(iris, expected_strata, dataname = "iris") |> + capture.output() |> # not sure this works as intended + suppressMessages() |> + expect_error() |> expect_warning() }) diff --git a/vignettes/articles/_antibody-response-model.qmd b/vignettes/articles/_antibody-response-model.qmd index d867a851..ca4151d1 100644 --- a/vignettes/articles/_antibody-response-model.qmd +++ b/vignettes/articles/_antibody-response-model.qmd @@ -109,12 +109,12 @@ library(serocalculator) library(dplyr) # Import longitudinal antibody parameters from OSF curves <- - "https://osf.io/download/rtw5k/" %>% - load_curve_params() %>% + "https://osf.io/download/rtw5k/" |> + load_curve_params() |> filter(iter < 50) curve1 = - curves %>% + curves |> filter( # iter %in% 1:10, iter == 5, @@ -122,7 +122,7 @@ curve1 = library(ggplot2) -curve1 %>% +curve1 |> serocalculator:::plot_curve_params_one_ab( log_y = FALSE ) + diff --git a/vignettes/articles/enteric_fever_example.Rmd b/vignettes/articles/enteric_fever_example.Rmd index 057735bd..7aa9b4dd 100644 --- a/vignettes/articles/enteric_fever_example.Rmd +++ b/vignettes/articles/enteric_fever_example.Rmd @@ -83,7 +83,7 @@ Column Name | Description ```{r curve, message=FALSE} # Import longitudinal antibody parameters from OSF curves <- - "https://osf.io/download/rtw5k/" %>% + "https://osf.io/download/rtw5k/" |> load_curve_params() ``` @@ -93,8 +93,8 @@ We can graph the decay curves with an `autoplot()` method: ```{r, fig.width=7, fig.height=4} # Visualize curve parameters -curves %>% filter(antigen_iso == "HlyE_IgA" | - antigen_iso == "HlyE_IgG") %>% +curves |> filter(antigen_iso == "HlyE_IgA" | + antigen_iso == "HlyE_IgG") |> autoplot() ``` @@ -117,7 +117,7 @@ Column Name | Description ```{r data, message = FALSE} #Import cross-sectional data from OSF and rename required variables -xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>% +xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") |> as_pop_data() ``` @@ -127,7 +127,7 @@ xs_data <- readr::read_rds("https://osf.io/download//n6cp3/") %>% 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() ``` @@ -142,7 +142,7 @@ We examine our cross-sectional antibody data by visualizing the distribution of #color palette country_pal <- c("#EA6552", "#8F4B86", "#0099B4FF") -xs_data %>% autoplot(strata = "Country", type = "density") + +xs_data |> autoplot(strata = "Country", type = "density") + scale_fill_manual(values = country_pal) ``` @@ -152,8 +152,8 @@ We see that across countries, our data is highly skewed with the majority of res ```{r logplot, message = FALSE} # Create log transformed plots -xs_data %>% - mutate(Country = fct_relevel(Country, "Bangladesh", "Pakistan", "Nepal")) %>% +xs_data |> + mutate(Country = fct_relevel(Country, "Bangladesh", "Pakistan", "Nepal")) |> autoplot(strata = "Country", type = "density") + scale_fill_manual(values = country_pal) + scale_x_log10(labels = scales::label_comma()) @@ -167,7 +167,7 @@ Let's also take a look at how antibody responses change by age. ```{r plot-age, message=FALSE, warning = FALSE} #Plot antibody responses by age -ggplot(data = xs_data %>% +ggplot(data = xs_data |> mutate(Country = fct_relevel( Country, "Bangladesh", "Pakistan", "Nepal" )), @@ -207,7 +207,7 @@ Column Name | Description ``` {r noise, message=FALSE} # Import noise parameters from OSF -noise <- url("https://osf.io/download//hqy4v/") %>% readRDS() +noise <- url("https://osf.io/download//hqy4v/") |> readRDS() ``` ## Estimate Seroincidence @@ -220,9 +220,9 @@ Using the function `est.incidence`, we filter to sites in Pakistan and define th # Using est.incidence (no strata) est1 <- est.incidence( - pop_data = xs_data %>% filter(Country == "Pakistan"), + pop_data = xs_data |> filter(Country == "Pakistan"), curve_param = curves, - noise_param = noise %>% filter(Country == "Pakistan"), + noise_param = noise |> filter(Country == "Pakistan"), antigen_isos = c("HlyE_IgG", "HlyE_IgA") ) @@ -267,7 +267,7 @@ Finally, let's visualize our seroincidence estimates by country and age category # Plot seroincidence estimates ## Save summary(est_country_age) as a dataframe and sort by incidence rate -est_country_agedf <- summary(est_country_age) %>% +est_country_agedf <- summary(est_country_age) |> mutate( Country = fct_relevel(Country, "Bangladesh", "Pakistan", "Nepal"), ageCat = factor(ageCat) diff --git a/vignettes/articles/scrubTyphus_example.Rmd b/vignettes/articles/scrubTyphus_example.Rmd index 9199e4a3..832e4402 100644 --- a/vignettes/articles/scrubTyphus_example.Rmd +++ b/vignettes/articles/scrubTyphus_example.Rmd @@ -75,7 +75,7 @@ We will first load the longitudinal curve parameters to set the antibody decay p # Import longitudinal antibody parameters from OSF curves <- - "https://osf.io/download/u5gxh/" %>% + "https://osf.io/download/u5gxh/" |> load_curve_params() ``` @@ -84,7 +84,7 @@ curves <- We can graph the decay curves with an `autoplot()` method: ```{r} -curves %>% autoplot() +curves |> autoplot() ``` @@ -108,7 +108,7 @@ xs_data <- load_pop_data( We can check that `xs_data` has the correct formatting using the `check_pop_data()` function: ```{r, message = TRUE} -xs_data %>% check_pop_data(verbose = TRUE) +xs_data |> check_pop_data(verbose = TRUE) ``` #### Summarize antibody data @@ -116,7 +116,7 @@ xs_data %>% check_pop_data(verbose = TRUE) We can compute numerical summaries of our cross-sectional antibody data with a `summary()` method for `pop_data` objects: ```{r} -xs_data %>% summary(strata = "country") +xs_data |> summary(strata = "country") ``` @@ -151,10 +151,10 @@ Column Name | Description ```{r message=FALSE, warning=FALSE} # biologic noise -b_noise <- xs_data %>% - group_by(antigen_iso) %>% - filter(!is.na(value)) %>% - filter(age < 40) %>% # restrict to young ages to capture recent exposures +b_noise <- xs_data |> + group_by(antigen_iso) |> + filter(!is.na(value)) |> + filter(age < 40) |> # restrict to young ages to capture recent exposures do({ set.seed(54321) # Fit the mixture model @@ -183,7 +183,7 @@ noise <- data.frame( eps = c(0.2, 0.2), # M noise (eps) y.low = c(0.2, 0.2), # low cutoff (llod) y.high = c(200, 200) -) %>% # high cutoff (y.high) +) |> # high cutoff (y.high) mutate(across(where(is.numeric), round, digits = 2)) ``` @@ -239,7 +239,7 @@ Let's visualize our seroincidence estimates by strata. # Plot seroincidence estimates # Save summary(est) as a dataframe -estdf <- summary(est) %>% +estdf <- summary(est) |> mutate(ageQ = "Overall") # Save summary(est2) as a dataframe diff --git a/vignettes/articles/simulate_xsectionalData.Rmd b/vignettes/articles/simulate_xsectionalData.Rmd index d14dc2d4..4457df9f 100644 --- a/vignettes/articles/simulate_xsectionalData.Rmd +++ b/vignettes/articles/simulate_xsectionalData.Rmd @@ -71,8 +71,8 @@ library(tidyverse) library(ggbeeswarm) # for plotting library(dplyr) dmcmc <- - "https://osf.io/download/rtw5k" %>% - load_curve_params() %>% + "https://osf.io/download/rtw5k" |> + load_curve_params() |> dplyr::filter(iter < 500) # reduce number of mcmc samples for speed ``` @@ -83,13 +83,13 @@ of model parameters using a `autoplot.curve_params()` method for the `autoplot()` function: ```{r} -dmcmc %>% autoplot(n_curves = 50) +dmcmc |> autoplot(n_curves = 50) ``` We can use a logarithmic scale for the x-axis if desired: ```{r} -dmcmc %>% autoplot(log_x = TRUE, n_curves = 50) +dmcmc |> autoplot(log_x = TRUE, n_curves = 50) ``` We can graph the median, 10%, and 90% quantiles of the model using the `graph.curve.params()` function: @@ -98,8 +98,8 @@ We can graph the median, 10%, and 90% quantiles of the model using the `graph.cu # Specify the antibody-isotype responses to include in analyses antibodies <- c("HlyE_IgA", "HlyE_IgG") -dmcmc %>% - graph.curve.params(antigen_isos = antibodies) %>% +dmcmc |> + graph.curve.params(antigen_isos = antibodies) |> print() ``` @@ -189,7 +189,7 @@ ll_a <- noise_params = cond, antigen_isos = "HlyE_IgA", lambda = 0.1 - ) %>% + ) |> print() ll_g <- @@ -199,7 +199,7 @@ ll_g <- noise_params = cond, antigen_isos = "HlyE_IgG", lambda = 0.1 - ) %>% + ) |> print() ll_ag <- @@ -209,7 +209,7 @@ ll_ag <- noise_params = cond, antigen_isos = c("HlyE_IgG", "HlyE_IgA"), lambda = 0.1 - ) %>% + ) |> print() print(ll_a + ll_g) @@ -326,7 +326,7 @@ print(sim_df) We can plot the distributions of the simulated responses: ```{r} -sim_df %>% ggplot() + +sim_df |> ggplot() + aes( x = as.factor(cluster), y = value @@ -366,8 +366,8 @@ We can explore the summary table interactively using `DT::datatable()` ```{r} library(DT) -summary(ests) %>% - DT::datatable() %>% +summary(ests) |> + DT::datatable() |> DT::formatRound( columns = c( "incidence.rate", @@ -403,9 +403,9 @@ autoplot(ests[1:5], log_x = TRUE) Make sure to check the `nlm()` exit codes (codes 3-5 indicate possible non-convergence): ```{r "check-codes"} -summary(ests) %>% - as_tibble() %>% # removes extra meta-data - select(Stratum, nlm.convergence.code) %>% +summary(ests) |> + as_tibble() |> # removes extra meta-data + select(Stratum, nlm.convergence.code) |> filter(nlm.convergence.code > 2) ``` @@ -419,7 +419,7 @@ We can extract the indices of problematic strata, if there are any: ```{r} problem_strata <- - which(summary(ests)$nlm.convergence.code > 2) %>% + which(summary(ests)$nlm.convergence.code > 2) |> print() ``` @@ -439,7 +439,7 @@ Finally, we can look at our simulation results: ```{r, "graph"} library(ggplot2) -summary(ests) %>% +summary(ests) |> autoplot(xvar = "lambda.sim") + ggplot2::geom_abline( ggplot2::aes(intercept = 0, slope = 1) diff --git a/vignettes/methodology.qmd b/vignettes/methodology.qmd index 2ce9ad5b..a27cfdfc 100644 --- a/vignettes/methodology.qmd +++ b/vignettes/methodology.qmd @@ -189,16 +189,16 @@ library(serocalculator) library(dplyr) # Import longitudinal antibody parameters from OSF curves <- - "https://osf.io/download/rtw5k/" %>% - load_curve_params() %>% + "https://osf.io/download/rtw5k/" |> + load_curve_params() |> filter(iter < 50) # Import cross-sectional data from OSF and rename required variables: xs_data <- - "https://osf.io/download//n6cp3/" %>% + "https://osf.io/download//n6cp3/" |> load_pop_data() -noise <- url("https://osf.io/download//hqy4v/") %>% readRDS() +noise <- url("https://osf.io/download//hqy4v/") |> readRDS() ``` ```{r}