diff --git a/DESCRIPTION b/DESCRIPTION index 4ec6071..4969410 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: simaerep Title: Find Clinical Trial Sites Under-Reporting Adverse Events -Version: 0.4.3 +Version: 0.4.4 Authors@R: c( person(given = "Bjoern", family = "Koneswarakantha", @@ -44,6 +44,6 @@ Suggests: vdiffr, lintr Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.3 Language: en-US Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 4433ce6..12b80b4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -46,7 +46,6 @@ importFrom(cowplot,get_legend) importFrom(cowplot,ggdraw) importFrom(cowplot,plot_grid) importFrom(dplyr,across) -importFrom(dplyr,all_equal) importFrom(dplyr,any_of) importFrom(dplyr,arrange) importFrom(dplyr,between) @@ -102,6 +101,7 @@ importFrom(purrr,possibly) importFrom(purrr,safely) importFrom(rlang,":=") importFrom(rlang,.data) +importFrom(rlang,.env) importFrom(rlang,enexpr) importFrom(rlang,env_has) importFrom(stats,ecdf) diff --git a/NEWS.md b/NEWS.md index 85249c9..19c05cf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# simaerep 0.4.4 +- allow flexible AE rates in data simulations +- add vignette comparing simaerep to gsm performance +- fix dplyr warnings + # simaerep 0.4.3 - delete performance unit tests (poisson faster than bootstrap) to accommodate CRAN request diff --git a/R/0_imports.R b/R/0_imports.R index af83d86..6a3cf13 100644 --- a/R/0_imports.R +++ b/R/0_imports.R @@ -1,12 +1,3 @@ -# satisfy lintr -# lintr falsely flags possibly_ecdf as unused variable -# using rlang::.data here causes error with furrr in sim_test_data_portfolio -# patnum, n_ae, visit - -if (getRversion() >= "2.15.1") { - utils::globalVariables(c("possibly_ecdf", "patnum", "n_ae", "visit")) -} - #' @importFrom progressr progressor #' @importFrom cowplot get_legend plot_grid ggdraw draw_label plot_grid plot_grid #' @importFrom cowplot ggdraw draw_label @@ -19,13 +10,13 @@ if (getRversion() >= "2.15.1") { #' @importFrom furrr future_map future_pmap furrr_options #' @importFrom progressr with_progress #' @importFrom stringr str_count str_pad str_length -#' @importFrom rlang := .data enexpr env_has +#' @importFrom rlang := .data enexpr env_has .env #' @importFrom dplyr select mutate filter summarise group_by summarise_all summarise_at #' @importFrom dplyr mutate_all mutate_at ungroup vars bind_cols bind_rows pull #' @importFrom dplyr n_distinct distinct arrange right_join left_join inner_join #' @importFrom dplyr rename sample_n between row_number dense_rank desc case_when #' @importFrom dplyr group_by_at n is_grouped_df everything one_of lag any_of across -#' @importFrom dplyr lead all_equal +#' @importFrom dplyr lead #' @importFrom tidyr tibble unnest nest fill #' @importFrom knitr kable #' @importFrom tibble tibble diff --git a/R/S3_orivisit.R b/R/S3_orivisit.R index a92575f..9fb0b0b 100644 --- a/R/S3_orivisit.R +++ b/R/S3_orivisit.R @@ -120,7 +120,7 @@ as.data.frame.orivisit <- function(x, ..., env = parent.frame()) { dim <- dim(df) df_summary <- summarise_df_visit(df) - if (! all_equal(df_summary, x$df_summary)) stop.orivisit() + if (! all.equal(df_summary, x$df_summary, tolerance = 1e-4)) stop.orivisit() if (! all(dim == x$dim)) stop.orivisit() return(df) diff --git a/R/lint.R b/R/lint.R index d46482d..889ddf9 100644 --- a/R/lint.R +++ b/R/lint.R @@ -16,7 +16,8 @@ lint_package <- function(path = ".", ...) { linters = lintr::linters_with_defaults( line_length_linter = lintr::line_length_linter(120), trailing_whitespace_linter = NULL, - cyclocomp_linter = lintr::cyclocomp_linter(25) + cyclocomp_linter = lintr::cyclocomp_linter(25), + indentation_linter = NULL ), exclusions = list("inst/logo/logo.R", "tests/spelling.R", "vignettes"), ...) diff --git a/R/simaerep.R b/R/simaerep.R index 7159176..a2d1271 100644 --- a/R/simaerep.R +++ b/R/simaerep.R @@ -43,13 +43,13 @@ check_df_visit <- function(df_visit) { cols_na <- df_visit %>% summarise_at( - vars( - .data$study_id, - .data$site_number, - .data$patnum, - .data$n_ae, - .data$visit - ), + vars(c( + "study_id", + "site_number", + "patnum", + "n_ae", + "visit" + )), anyNA ) %>% unlist() @@ -60,10 +60,10 @@ check_df_visit <- function(df_visit) { df_visit %>% summarise_at( - vars( - .data$n_ae, - .data$visit - ), + vars(c( + "n_ae", + "visit" + )), ~ is.numeric(.) ) %>% unlist() %>% @@ -129,13 +129,13 @@ exp_implicit_missing_visits <- function(df_visit) { group_by(.data$study_id) %>% mutate(min_study_visit = min(.data$visit), max_study_visit = max(.data$visit)) %>% - select( - .data$study_id, - .data$site_number, - .data$patnum, - .data$min_study_visit, - .data$max_study_visit - ) %>% + select(c( + "study_id", + "site_number", + "patnum", + "min_study_visit", + "max_study_visit" + )) %>% distinct() %>% mutate( visit = map2( @@ -144,14 +144,14 @@ exp_implicit_missing_visits <- function(df_visit) { function(x, y) seq(x, y, 1) ) ) %>% - unnest(.data$visit) %>% - select( - .data$study_id, - .data$site_number, - .data$patnum, - .data$min_study_visit, - .data$visit - ) + unnest("visit") %>% + select(c( + "study_id", + "site_number", + "patnum", + "min_study_visit", + "visit" + )) df_visit_out <- df_visit %>% group_by(.data$study_id, .data$site_number, .data$patnum) %>% @@ -164,7 +164,7 @@ exp_implicit_missing_visits <- function(df_visit) { ) %>% group_by(.data$study_id, .data$site_number, .data$patnum) %>% arrange(.data$visit) %>% - fill(.data$n_ae, .direction = "down") %>% + fill("n_ae", .direction = "down") %>% mutate( min_visit_pat = min(.data$min_visit_pat, na.rm = TRUE), max_visit_pat = max(.data$max_visit_pat, na.rm = TRUE) @@ -177,13 +177,13 @@ exp_implicit_missing_visits <- function(df_visit) { .data$visit <= .data$max_visit_pat ) %>% mutate(n_ae = ifelse(is.na(.data$n_ae), 0, .data$n_ae)) %>% - select( - .data$study_id, - .data$site_number, - .data$patnum, - .data$n_ae, - .data$visit - ) %>% + select(c( + "study_id", + "site_number", + "patnum", + "n_ae", + "visit" + )) %>% arrange(.data$study_id, .data$site_number, .data$patnum, .data$visit) if (nrow(df_visit_out) > nrow(df_visit)) { @@ -291,15 +291,15 @@ get_visit_med75 <- function(df_pat, .data$visit_med75 ) ) %>% - select(- .data$study_qup8_max_visit) + select(- "study_qup8_max_visit") } df_site <- df_site %>% - select(.data$study_id, - .data$site_number, - .data$n_pat, - .data$n_pat_with_med75, - .data$visit_med75) + select(c("study_id", + "site_number", + "n_pat", + "n_pat_with_med75", + "visit_med75")) return(df_site) } @@ -486,7 +486,7 @@ eval_sites_deprecated <- function(df_sim_sites, pval_p_vs_fp_ratio = ifelse(.data$pval_p_vs_fp_ratio < 1, 1, .data$pval_p_vs_fp_ratio), pval_prob_ur = 1 - 1 / .data$pval_p_vs_fp_ratio ) %>% - select(- .data$min_pval) + select(- "min_pval") } if ("prob_low" %in% names(df_out)) { @@ -575,20 +575,20 @@ get_ecd_values <- function(df_sim_studies, df_sim_sites, val_str) { df_ecd <- df_sim_studies %>% rename(val = !!as.symbol(val_str)) %>% - select(.data$study_id, .data$val) %>% - nest(data = c(.data$val)) %>% + select("study_id", "val") %>% + nest(data = "val") %>% mutate(.ecdf = map(.data$data, ~ possibly_ecdf(.$val))) %>% - select(- .data$data) + select(- "data") df_out <- df_sim_sites %>% rename(val = !!as.symbol(val_str)) %>% left_join(df_ecd, "study_id") %>% mutate(ecd_val = map2_dbl(.data$`.ecdf`, .data$val, apply_ecdf)) %>% rename( - !!as.symbol(val_str) := .data$val, - !!as.symbol(paste0(val_str, "_ecd")) := .data$ecd_val #nolint + !!as.symbol(val_str) := "val", + !!as.symbol(paste0(val_str, "_ecd")) := "ecd_val" #nolint ) %>% - select(- .data$`.ecdf`) + select(- ".ecdf") return(ungroup(df_out)) } @@ -628,11 +628,11 @@ pat_pool <- function(df_visit, df_site) { df_visit %>% left_join(df_site, by = c("study_id", "site_number")) %>% filter(.data$visit <= .data$max_visit_med75_study) %>% - select(.data$study_id, - .data$patnum, - .data$visit, - .data$n_ae) %>% - nest(pat_pool = c(.data$patnum, .data$visit, .data$n_ae)) + select(c("study_id", + "patnum", + "visit", + "n_ae")) %>% + nest(pat_pool = c("patnum", "visit", "n_ae")) } @@ -829,8 +829,7 @@ prep_for_sim <- function(df_site, df_visit) { n_ae_site = map(.data$n_ae_site, "n_ae"), n_ae_study = map(.data$n_ae_study, "n_ae") ) %>% - select(- .data$patients, - - .data$pat_pool) + select(- c("patients", "pat_pool")) return(df_sim_prep) @@ -908,15 +907,15 @@ sim_after_prep <- function(df_sim_prep, ~ ifelse(.data$n_pat_with_med75_study == 0, NA, .) ) ) %>% - select(- .data$n_ae_site, - .data$n_ae_study) %>% - select(.data$study_id, - .data$site_number, - .data$n_pat, - .data$n_pat_with_med75, - .data$visit_med75, - .data$mean_ae_site_med75, - .data$mean_ae_study_med75, - .data$n_pat_with_med75_study, + select(- c("n_ae_site", "n_ae_study")) %>% + select(c("study_id", + "site_number", + "n_pat", + "n_pat_with_med75", + "visit_med75", + "mean_ae_site_med75", + "mean_ae_study_med75", + "n_pat_with_med75_study"), dplyr::everything()) %>% ungroup() @@ -976,11 +975,11 @@ sim_after_prep <- function(df_sim_prep, get_pat_pool_config <- function(df_visit, df_site, min_n_pat_with_med75 = 1) { # site_config are the number of sites with their individual visit_med75 and n_pat_with_med75 - df_site_config <- select(df_site, - .data$study_id, - .data$site_number, - .data$visit_med75, - .data$n_pat_with_med75) %>% + df_site_config <- select(df_site, c( + "study_id", + "site_number", + "visit_med75", + "n_pat_with_med75")) %>% filter(.data$n_pat_with_med75 >= min_n_pat_with_med75) # pat_pool gives the patient pool for study from which we sample @@ -994,12 +993,12 @@ get_pat_pool_config <- function(df_visit, df_site, min_n_pat_with_med75 = 1) { pat_pool = map2(.data$pat_pool, .data$visit_med75, function(x, y) filter(x, visit == y)), n_pat_study = map2_dbl(.data$pat_pool, .data$n_pat_with_med75, function(x, y) nrow(x) - y) ) %>% - select(.data$study_id, - .data$site_number, - .data$visit_med75, - .data$n_pat_with_med75, - .data$n_pat_study, - .data$pat_pool) + select(c("study_id", + "site_number", + "visit_med75", + "n_pat_with_med75", + "n_pat_study", + "pat_pool")) return(ungroup(df_site_config)) } @@ -1113,7 +1112,7 @@ sim_studies <- function(df_visit, function(x, y) sample_n(x, y, replace = TRUE)), n_ae_study = map(.data$n_ae_study, "n_ae") ) %>% - select(- .data$pat_pool) + select(- "pat_pool") if (poisson_test) { df_config <- df_config %>% @@ -1132,10 +1131,10 @@ sim_studies <- function(df_visit, if (!keep_ae) { df_config <- df_config %>% - select(- .data$n_ae_site, - .data$n_ae_study) + select(- c("n_ae_site", "n_ae_study")) } else { df_config <- df_config %>% - mutate_at(vars(n_ae_site, n_ae_study), ~ map_chr(., paste, collapse = ",")) + mutate_at(vars(c("n_ae_site", "n_ae_study")), ~ map_chr(., paste, collapse = ",")) } return(ungroup(df_config)) @@ -1143,7 +1142,7 @@ sim_studies <- function(df_visit, df_sim <- tibble(r = seq.int(1, r, 1)) %>% mutate(n_ae_set = .f_map(.data$r, sim)) %>% - unnest(.data$n_ae_set) + unnest("n_ae_set") return(ungroup(df_sim)) } @@ -1220,10 +1219,10 @@ site_aggr <- function(df_visit, df_mean_ae_med75 <- df_mean_ae_dev %>% filter(.data$visit == .data$visit_med75) %>% - rename(mean_ae_site_med75 = .data$mean_ae_site) %>% - select(.data$study_id, - .data$site_number, - .data$mean_ae_site_med75) + rename(mean_ae_site_med75 = "mean_ae_site") %>% + select(c("study_id", + "site_number", + "mean_ae_site_med75")) # Add mean cumulative AE to site aggregate ---------------------- diff --git a/R/simaerep_plot.R b/R/simaerep_plot.R index 8f796ca..9c35e90 100644 --- a/R/simaerep_plot.R +++ b/R/simaerep_plot.R @@ -86,9 +86,9 @@ plot_dots <- function(df, } p <- df %>% - ggplot(aes_string("x", "y", color = "color")) + + ggplot(aes(x, y, color = .data$color)) + geom_point(size = size_dots) + - geom_text(aes_string(label = "n_ae"), + geom_text(aes(label = n_ae), color = "black" ) + geom_rect(aes( @@ -167,10 +167,10 @@ plot_sim_example <- function(substract_ae_per_pat = 0, site = LETTERS[1:3], patients = c(list(seq(1, 50, 1)), list(seq(1, 40, 1)), list(seq(1, 10, 1))) ) %>% - tidyr::unnest(.data$patients) %>% + tidyr::unnest("patients") %>% mutate(n_ae = as.integer(runif(min = 0, max = 10, n = nrow(.)))) %>% mutate( - n_ae = ifelse(.data$site == "C", .data$n_ae - substract_ae_per_pat, .data$n_ae), + n_ae = ifelse(.data$site == "C", .data$n_ae - .env$substract_ae_per_pat, .data$n_ae), n_ae = ifelse(.data$n_ae < 0, 0, .data$n_ae) ) @@ -226,7 +226,7 @@ plot_sim_example <- function(substract_ae_per_pat = 0, group_by(.data$x) %>% mutate(y = row_number()) %>% filter(.data$rep <= 1000) %>% - ggplot(aes_string("x", "y", fill = "color")) + + ggplot(aes(x, y, fill = .data$color)) + geom_raster() + scale_fill_identity() + theme_minimal() + @@ -331,7 +331,7 @@ plot_sim_examples <- function(substract_ae_per_pat = c(0, 1, 3), ...) { title_add = map(.data$title_add, make_title, angle = 90), p = pmap( list( - substract_ae_per_pat = .data$substract_ae_per_pat, + substract_ae_per_pat = substract_ae_per_pat, title = .data$title, legend = .data$legend ), @@ -348,7 +348,7 @@ plot_sim_examples <- function(substract_ae_per_pat = c(0, 1, 3), ...) { site = LETTERS[1:3], patients = c(list(seq(1, 50, 1)), list(seq(1, 40, 1)), list(seq(1, 10, 1))) ) %>% - tidyr::unnest(.data$patients) %>% + tidyr::unnest("patients") %>% mutate(n_ae = as.integer(runif(min = 0, max = 10, n = nrow(.)))) p_legend <- plot_dots(study) + @@ -445,11 +445,11 @@ plot_study <- function(df_visit, alert_level_study = NA) } else { df_visit <- df_visit %>% - left_join(select(df_al, - .data$study_id, - .data$site_number, - .data$alert_level_site, - .data$alert_level_study)) + left_join(select(df_al, c( + "study_id", + "site_number", + "alert_level_site", + "alert_level_study"))) } # fill in pvalues when missing -------------------------------------------- @@ -462,13 +462,13 @@ plot_study <- function(df_visit, # make sure ids are character columns df_visit <- df_visit %>% - mutate_at(vars(.data$study_id, .data$patnum, .data$site_number), as.character) + mutate_at(vars(c("study_id", "patnum", "site_number")), as.character) df_eval <- df_eval %>% - mutate_at(vars(.data$study_id, .data$site_number), as.character) + mutate_at(vars(c("study_id", "site_number")), as.character) df_site <- df_site %>% - mutate_at(vars(.data$study_id, .data$site_number), as.character) + mutate_at(vars(c("study_id", "site_number")), as.character) # filter studies ----------------------------------------------------------- @@ -539,11 +539,11 @@ plot_study <- function(df_visit, ungroup() df_ae_dev_patient <- df_visit %>% - select(.data$study_id, - .data$site_number, - .data$patnum, - .data$visit, - .data$n_ae) %>% + select(c("study_id", + "site_number", + "patnum", + "visit", + "n_ae")) %>% mutate(max_visit_per_pat = max(.data$visit)) %>% filter(.data$site_number %in% sites_ordered) %>% ungroup() %>% @@ -566,7 +566,7 @@ plot_study <- function(df_visit, ) df_mean_ae_dev_site <- df_mean_ae_dev_site %>% - select(- .data$visit_med75) %>% + select(- "visit_med75") %>% left_join(df_eval, by = c("study_id", "site_number")) # we have to split site ae dev up because alert sites get plotted @@ -579,45 +579,45 @@ plot_study <- function(df_visit, filter(.data$prob_cut != levels(.data$prob_cut)[1]) df_alert <- df_visit %>% - select(.data$study_id, - .data$site_number, - .data$alert_level_site, - .data$alert_level_study) %>% + select(c("study_id", + "site_number", + "alert_level_site", + "alert_level_study")) %>% distinct() df_label <- df_mean_ae_dev_site %>% filter(.data$visit == .data$visit_med75, .data$site_number %in% sites_ordered) %>% - select(.data$study_id, - .data$site_number, - .data$visit, - .data$mean_ae) %>% + select(c("study_id", + "site_number", + "visit", + "mean_ae")) %>% left_join(df_site, by = c("study_id", "site_number")) %>% - select(.data$study_id, - .data$site_number, - .data$visit, - .data$mean_ae, - .data$n_pat, - .data$n_pat_with_med75) %>% + select(c("study_id", + "site_number", + "visit", + "mean_ae", + "n_pat", + "n_pat_with_med75")) %>% left_join( - select(df_eval, - - .data$n_pat, - - .data$n_pat_with_med75) + select(df_eval, - c( + "n_pat", + "n_pat_with_med75")) , by = c("study_id", "site_number") ) %>% left_join(df_alert, by = c("study_id", "site_number")) %>% - select( - .data$study_id, - .data$site_number, - .data$visit, - .data$mean_ae, - .data$n_pat, - .data$n_pat_with_med75, - .data$prob_low_prob_ur, - .data$prob_cut, - .data$color_prob_cut, - .data$pval_prob_ur, - .data$alert_level_site - ) %>% + select(c( + "study_id", + "site_number", + "visit", + "mean_ae", + "n_pat", + "n_pat_with_med75", + "prob_low_prob_ur", + "prob_cut", + "color_prob_cut", + "pval_prob_ur", + "alert_level_site" + )) %>% mutate( site_number = fct_relevel(.data$site_number, sites_ordered), color_alert_level = case_when( @@ -643,22 +643,22 @@ plot_study <- function(df_visit, ) p_study <- df_mean_ae_dev_site_no_alert %>% - ggplot(aes_string("visit", "mean_ae"), na.rm = TRUE) + - geom_line(aes_string( - group = "site_number", - color = "color_prob_cut" + ggplot(aes(visit, mean_ae), na.rm = TRUE) + + geom_line(aes( + group = .data$site_number, + color = color_prob_cut )) + - geom_line(aes_string( - group = "site_number", - color = "color_prob_cut" - ), - data = df_mean_ae_dev_site_alert, - size = 1 + geom_line(aes( + group = .data$site_number, + color = color_prob_cut + ), + data = df_mean_ae_dev_site_alert, + linewidth = 1 ) + - geom_line(aes_string(group = "study_id"), + geom_line(aes(group = .data$study_id), data = df_mean_ae_dev_study, color = "gold3", - size = 1, + linewidth = 1, alpha = 0.5 ) + geom_point( @@ -704,23 +704,23 @@ plot_study <- function(df_visit, ) p_site <- df_ae_dev_patient %>% - ggplot(aes_string("visit", "n_ae"), na.rm = TRUE) + - geom_line(aes_string(group = "patnum"), + ggplot(aes(visit, n_ae), na.rm = TRUE) + + geom_line(aes(group = patnum), color = "grey", alpha = 0.5 ) + - geom_line(aes_string( - y = "mean_ae", - color = "color_prob_cut", - alpha = 0.5 - ), - data = df_mean_ae_dev_site, - size = 1 + geom_line(aes( + y = mean_ae, + color = color_prob_cut, + alpha = 0.5 + ), + data = df_mean_ae_dev_site, + linewidth = 1 ) + geom_line(aes(y = mean_ae), data = df_mean_ae_dev_study, color = "gold3", - size = 1, + linewidth = 1, alpha = 0.5) + geom_text(aes(label = paste0(n_pat_with_med75, "/", n_pat)), data = df_label, @@ -733,8 +733,8 @@ plot_study <- function(df_visit, x = 0.8 * max_visit, y = 0.9 * max_ae, na.rm = TRUE) + - geom_label(aes_string(label = "alert_level_site", - color = "color_alert_level"), + geom_label(aes(label = .data$alert_level_site, + color = .data$color_alert_level), data = df_label, x = 0.5 * max_visit, y = 0.9 * max_ae, @@ -827,14 +827,14 @@ plot_visit_med75 <- function(df_visit, df_mean_ae_dev <- get_site_mean_ae_dev(df_visit, df_pat, df_site_max_med75) df_plot <- df_site_min_med75 %>% - rename(visit_med75_min = .data$visit_med75) %>% + rename(visit_med75_min = "visit_med75") %>% left_join( select( - df_site_max_med75, - .data$study_id, - .data$site_number, - visit_med75_max = .data$visit_med75 - ), + df_site_max_med75, c( + "study_id", + "site_number", + visit_med75_max = "visit_med75" + )), by = c( "study_id", "site_number" @@ -843,7 +843,7 @@ plot_visit_med75 <- function(df_visit, mutate(rnk_sites = rank(desc(.data$n_pat), ties.method = "first")) %>% filter(.data$rnk_sites <= n_sites) %>% left_join(df_visit, by = c("study_id", "site_number")) %>% - left_join(select(df_mean_ae_dev, - .data$visit_med75), + left_join(select(df_mean_ae_dev, - "visit_med75"), by = c("study_id", "site_number", "visit") ) %>% group_by(.data$study_id, .data$site_number, .data$patnum) %>% @@ -854,12 +854,12 @@ plot_visit_med75 <- function(df_visit, ungroup() df_label <- df_plot %>% - select( - .data$study_id, - .data$site_number, - .data$n_pat, - .data$n_pat_with_med75 - ) %>% + select(c( + "study_id", + "site_number", + "n_pat", + "n_pat_with_med75" + )) %>% distinct() %>% mutate(label = paste0(.data$n_pat_with_med75, "/", .data$n_pat)) @@ -875,30 +875,30 @@ plot_visit_med75 <- function(df_visit, filter(.data$site_number %in% unique(df_plot$site_number)) p <- df_plot %>% - ggplot(aes_string("visit", "n_ae")) + + ggplot(aes(visit, n_ae)) + geom_line( - aes_string(group = "patnum"), + aes(group = patnum), data = filter(df_plot, .data$has_med75 == "yes"), color = "grey" ) + geom_line( - aes_string(y = "mean_ae_site", group = "site_number"), + aes(y = .data$mean_ae_site, group = .data$site_number), data = df_mean_ae_dev, color = "slateblue3", alpha = 0.5, - size = 2 + linewidth = 2 ) + - geom_line(aes_string(group = "patnum"), + geom_line(aes(group = patnum), filter(df_plot, .data$has_med75 == "no"), color = "black", linetype = 2 ) + - geom_vline(aes_string(xintercept = "visit_med75_max"), + geom_vline(aes(xintercept = .data$visit_med75_max), linetype = 1, color = "slateblue3" ) + geom_vline( - aes_string(xintercept = "visit_med75_min"), + aes(xintercept = .data$visit_med75_min), linetype = 3, color = "slateblue3" ) + @@ -907,7 +907,7 @@ plot_visit_med75 <- function(df_visit, linetype = 2, color = "slateblue3" ) + - geom_text(aes_string(label = "label"), + geom_text(aes(label = label), df_label, x = 0.15 * visit_max, y = 0.75 * ae_max, diff --git a/R/simulate_test_data.R b/R/simulate_test_data.R index b4f39ef..e6dfcfc 100644 --- a/R/simulate_test_data.R +++ b/R/simulate_test_data.R @@ -12,6 +12,7 @@ #' @param max_visit_sd standard deviation of maximum number of visits of each #' patient, Default: 4 #' @param ae_per_visit_mean mean ae per visit per patient, Default: 0.5 +#' @param ae_rates vector with visit-specific ae rates, Default: Null #' @return tibble with columns site_number, patnum, is_ur, max_visit_mean, #' max_visit_sd, ae_per_visit_mean, visit, n_ae #' @details maximum visit number will be sampled from normal distribution with @@ -25,6 +26,8 @@ #' df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5, #' frac_site_with_ur = 0.2, ur_rate = 0.5) #' df_visit[which(df_visit$patnum == "P000001"),] +#' ae_rates <- c(0.7, rep(0.5, 8), rep(0.3, 5)) +#' sim_test_data_study(n_pat = 100, n_sites = 5, ae_rates = ae_rates) #' @rdname sim_test_data_study #' @export sim_test_data_study <- function(n_pat = 1000, @@ -33,8 +36,71 @@ sim_test_data_study <- function(n_pat = 1000, ur_rate = 0, max_visit_mean = 20, max_visit_sd = 4, - ae_per_visit_mean = 0.5 + ae_per_visit_mean = 0.5, + ae_rates = NULL ) { + + # construct patient ae sample function + # supports constant and non-constant ae rates + + f_sim_pat <- function(vs_max, vs_sd, is_ur) { + + if (! any(c(is.null(ae_rates), is.na(ae_rates)))) { + + if (is_ur) { + ae_rates <- ae_rates * (1-ur_rate) # nolint + } + + f_sample_ae <- function(max_visit) { + + # extrapolate missing ae rates by extending last rate + fill <- rep(ae_rates[length(ae_rates)], max_visit) + fill[seq_along(ae_rates)] <- ae_rates + ae_rates <- fill + + aes <- integer(0) + + for (i in seq(1, max_visit)) { + ae <- rpois(1, ae_rates[i]) + aes <- c(aes, ae) + } + + return(aes) + + } + + ae_per_visit_mean <- mean(ae_rates) + + } else { + + if (is_ur) { + ae_per_visit_mean <- ae_per_visit_mean * (1-ur_rate) # nolint + } + + f_sample_ae <- function(max_visit) { + + rpois(max_visit, ae_per_visit_mean) + + } + + } + + aes <- sim_test_data_patient( + .f_sample_max_visit = function(x) rnorm(1, mean = vs_max, sd = vs_sd), + .f_sample_ae_per_visit = f_sample_ae + ) + + tibble( + ae_per_visit_mean = ae_per_visit_mean, + visit = seq(1, length(aes)), + n_ae = aes, + ) + + } + + + + tibble(patnum = seq(1, n_pat)) %>% mutate(patnum = str_pad(patnum, width = 6, side = "left", pad = "0"), patnum = paste0("P", patnum), @@ -45,19 +111,13 @@ sim_test_data_study <- function(n_pat = 1000, site_number = paste0("S", .data$site_number), max_visit_mean = max_visit_mean, max_visit_sd = max_visit_sd, - ae_per_visit_mean = ifelse(.data$is_ur, ae_per_visit_mean * (1 - ur_rate), ae_per_visit_mean), - aes = pmap(list(vm = max_visit_mean, - vs = max_visit_sd, - am = ae_per_visit_mean), - function(vm, vs, am) { - sim_test_data_patient( - .f_sample_max_visit = function() rnorm(1, mean = vm, sd = vs), - .f_sample_ae_per_visit = function(max_visit) rpois(max_visit, am) - ) - } - ), - aes = map(aes, ~ tibble(visit = seq(1, length(.)), n_ae = .))) %>% - unnest(aes) + aes = pmap(list(.data$max_visit_mean, + .data$max_visit_sd, + .data$is_ur), + f_sim_pat + ) + ) %>% + unnest("aes") } @@ -284,26 +344,26 @@ sim_ur_scenarios <- function(df_portf, ur_rate <- ur_rate[ur_rate > 0] df_grid_gr0 <- df_site %>% - select(.data$study_id, .data$site_number, .data$n_pat_with_med75, .data$visit_med75) %>% + select(c("study_id", "site_number", "n_pat_with_med75", "visit_med75")) %>% left_join(df_mean_pat, by = c(study_id = "study_id", visit_med75 = "visit")) %>% mutate(extra_ur_sites = list(0:extra_ur_sites)) %>% - unnest(.data$extra_ur_sites) %>% + unnest("extra_ur_sites") %>% mutate( frac_pat_with_ur = (.data$n_pat_with_med75 + .data$extra_ur_sites * .data$mean_n_pat) / .data$sum_n_pat, ur_rate = list(ur_rate) ) %>% - unnest(.data$ur_rate) %>% - select( - .data$study_id, - .data$site_number, - .data$extra_ur_sites, - .data$frac_pat_with_ur, - .data$ur_rate - ) + unnest("ur_rate") %>% + select(c( + "study_id", + "site_number", + "extra_ur_sites", + "frac_pat_with_ur", + "ur_rate" + )) df_grid_0 <- df_grid_gr0 %>% - select(.data$study_id, .data$site_number) %>% + select(c("study_id", "site_number")) %>% distinct() %>% mutate(extra_ur_sites = 0, frac_pat_with_ur = 0, @@ -323,10 +383,10 @@ sim_ur_scenarios <- function(df_portf, sim_scenario ) ) %>% - select(- .data$n_ae_site, - .data$n_ae_study) %>% + select(- c("n_ae_site", "n_ae_study")) %>% mutate(n_ae_site = map(.data$scenarios, "n_ae_site"), n_ae_study = map(.data$scenarios, "n_ae_study")) %>% - select(- .data$scenarios) + select(- "scenarios") if (progress) { message("getting under-reporting stats") @@ -346,7 +406,7 @@ sim_ur_scenarios <- function(df_portf, group_by(.data$study_id_gr, .data$site_number_gr) %>% nest() %>% ungroup() %>% - select(- .data$study_id_gr, - .data$site_number_gr) + select(- c("study_id_gr", "site_number_gr")) with_progress_cnd( ls_df_sim_sites <- purrr_bar( @@ -389,6 +449,7 @@ sim_ur_scenarios <- function(df_portf, #' @title Simulate Portfolio Test Data #' @description Simulate visit level data from a portfolio configuration. #' @param df_config dataframe as returned by \code{\link{get_config}} +#' @param df_ae_rates dataframe with ae rates. Default: NULL #' @param parallel logical activate parallel processing, see details, Default: FALSE #' @param progress logical, Default: TRUE #'@return dataframe with the following columns: \describe{ @@ -452,7 +513,7 @@ sim_ur_scenarios <- function(df_portf, #' \code{\link{get_portf_perf}} #' @rdname sim_test_data_portfolio #' @export -sim_test_data_portfolio <- function(df_config, parallel = FALSE, progress = TRUE) { +sim_test_data_portfolio <- function(df_config, df_ae_rates = NULL, parallel = FALSE, progress = TRUE) { # checks -------------------------- df_config <- ungroup(df_config) @@ -478,6 +539,24 @@ sim_test_data_portfolio <- function(df_config, parallel = FALSE, progress = TRUE ) ) + # prep ae_rates ----------------- + + if (is.null(df_ae_rates)) { + df_config$ae_rates <- NA + } else { + df_ae_rates <- df_ae_rates %>% + select(c("study_id", "ae_rate")) %>% + group_by(.data$study_id) %>% + nest() %>% + mutate( + ae_rates = map(.data$data, "ae_rate") + ) %>% + select(- "data") + + df_config <- df_config %>% + inner_join(df_ae_rates, by = "study_id") + } + # exec -------------------------- if (parallel) { @@ -496,24 +575,26 @@ sim_test_data_portfolio <- function(df_config, parallel = FALSE, progress = TRUE .data$ae_per_visit_mean, .data$max_visit_sd, .data$max_visit_mean, - .data$n_pat + .data$n_pat, + .data$ae_rates ), .purrr = .purrr, .f = function(ae_per_visit_mean, max_visit_sd, max_visit_mean, - n_pat) { + n_pat, + ae_rates) { sim_test_data_study( n_pat = n_pat, n_sites = 1, max_visit_mean = max_visit_mean, max_visit_sd = max_visit_sd, - ae_per_visit_mean = ae_per_visit_mean + ae_per_visit_mean = ae_per_visit_mean, + ae_rates = ae_rates ) %>% - select( - # using rlang::.data here causes error with furrr - patnum, visit, n_ae - ) + select(c( + "patnum", "visit", "n_ae" + )) }, .progress = progress, .purrr_args = .purrr_args, @@ -524,8 +605,8 @@ sim_test_data_portfolio <- function(df_config, parallel = FALSE, progress = TRUE ) df_portf <- df_config_sim %>% - unnest(.data$sim) %>% - select(- .data$n_pat) %>% + unnest("sim") %>% + select(- c("n_pat", "ae_rates")) %>% group_by(.data$study_id) %>% mutate( # patnums need to be made site exclusive @@ -612,7 +693,7 @@ get_config <- function(df_site, pad_width = 4) { stopifnot(c("study_id", "site_number", "patnum", "max_visit", "max_ae") %in% colnames(df_site)) - stopifnot(nrow(df_site) == nrow(distinct(select(df_site, .data$study_id, .data$site_number, .data$patnum)))) + stopifnot(nrow(df_site) == nrow(distinct(select(df_site, c("study_id", "site_number", "patnum"))))) df_site %>% summarise_all(~ ! anyNA(.)) %>% @@ -734,7 +815,7 @@ get_portf_perf <- function(df_scen, stat = "prob_low_prob_ur", fpr = c(0.001, 0. 0, .data$n_sites_total) ) %>% - select(.data$extra_ur_sites, .data$ur_rate, .data$ratio_sites_with_na) %>% + select(c("extra_ur_sites", "ur_rate", "ratio_sites_with_na")) %>% knitr::kable() %>% paste(collapse = "\n") @@ -743,7 +824,7 @@ get_portf_perf <- function(df_scen, stat = "prob_low_prob_ur", fpr = c(0.001, 0. } - stat_at_0 <- df_scen %>% #nolint + stat_at_0 <- df_scen %>% # nolint filter(.data$ur_rate == 0, .data$frac_pat_with_ur == 0) %>% pull(.data[[stat]]) @@ -760,7 +841,7 @@ get_portf_perf <- function(df_scen, stat = "prob_low_prob_ur", fpr = c(0.001, 0. df_prep <- df_scen %>% mutate(data = list(df_thresh)) %>% - unnest(.data$data) %>% + unnest("data") %>% mutate(stat = .data[[stat]]) %>% group_by(.data$fpr, .data$thresh, .data$extra_ur_sites, .data$ur_rate) %>% summarise( @@ -771,7 +852,7 @@ get_portf_perf <- function(df_scen, stat = "prob_low_prob_ur", fpr = c(0.001, 0. df_prep_0 <- df_prep %>% filter(.data$ur_rate == 0) %>% mutate(extra_ur_sites = list(unique(df_prep$extra_ur_sites))) %>% - unnest(.data$extra_ur_sites) + unnest("extra_ur_sites") df_prep_gr0 <- df_prep %>% filter(.data$ur_rate > 0) diff --git a/README.md b/README.md index 88f8d32..d3a2eed 100644 --- a/README.md +++ b/README.md @@ -151,11 +151,6 @@ df_visit %>% aerep <- simaerep(df_visit) plot(aerep, study = "A") -#> Warning: `all_equal()` was deprecated in dplyr 1.1.0. -#> ℹ Please use `all.equal()` instead. -#> ℹ And manually order the rows/cols as needed -#> ℹ The deprecated feature was likely used in the simaerep package. -#> Please report the issue to the authors. ``` diff --git a/_pkgdown.yml b/_pkgdown.yml index 082351f..ecae09f 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -36,6 +36,7 @@ articles: - usability_limits - check_poisson - visits_or_days + - gsm_perf reference: - title: S3 Interface diff --git a/docs/404.html b/docs/404.html index 72bd360..f31c8d5 100644 --- a/docs/404.html +++ b/docs/404.html @@ -45,7 +45,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -91,6 +91,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -140,7 +143,7 @@

    Page not found (404)

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 62a479e..34fc4a9 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -108,7 +111,7 @@

    License

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/LICENSE.html b/docs/LICENSE.html index a0dfa6c..806fcf5 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -112,7 +115,7 @@

    MIT License

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/check_poisson.html b/docs/articles/check_poisson.html index 029acbf..7c8042d 100644 --- a/docs/articles/check_poisson.html +++ b/docs/articles/check_poisson.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -198,55 +201,55 @@

    Test Data and Standard Processingdf_sim_sites <- sim_sites(df_site, df_visit) df_visit -
    ## # A tibble: 59,221 × 9
    -##    patnum  site_number is_ur max_visit_mean max_vi…¹ ae_pe…² visit  n_ae study…³
    -##    <chr>   <chr>       <lgl>          <dbl>    <dbl>   <dbl> <int> <int> <chr>  
    -##  1 P000001 S0001       TRUE              20        4    0.25     1     0 ae_per…
    -##  2 P000001 S0001       TRUE              20        4    0.25     2     1 ae_per…
    -##  3 P000001 S0001       TRUE              20        4    0.25     3     2 ae_per…
    -##  4 P000001 S0001       TRUE              20        4    0.25     4     2 ae_per…
    -##  5 P000001 S0001       TRUE              20        4    0.25     5     2 ae_per…
    -##  6 P000001 S0001       TRUE              20        4    0.25     6     2 ae_per…
    -##  7 P000001 S0001       TRUE              20        4    0.25     7     2 ae_per…
    -##  8 P000001 S0001       TRUE              20        4    0.25     8     4 ae_per…
    -##  9 P000001 S0001       TRUE              20        4    0.25     9     4 ae_per…
    -## 10 P000001 S0001       TRUE              20        4    0.25    10     4 ae_per…
    -## # … with 59,211 more rows, and abbreviated variable names ¹​max_visit_sd,
    -## #   ²​ae_per_visit_mean, ³​study_id
    +
    ## # A tibble: 58,367 × 9
    +##    patnum  site_number is_ur max_visit_mean max_visit_sd ae_per_visit_mean visit
    +##    <chr>   <chr>       <lgl>          <dbl>        <dbl>             <dbl> <int>
    +##  1 P000001 S0001       TRUE              20            4              0.25     1
    +##  2 P000001 S0001       TRUE              20            4              0.25     2
    +##  3 P000001 S0001       TRUE              20            4              0.25     3
    +##  4 P000001 S0001       TRUE              20            4              0.25     4
    +##  5 P000001 S0001       TRUE              20            4              0.25     5
    +##  6 P000001 S0001       TRUE              20            4              0.25     6
    +##  7 P000001 S0001       TRUE              20            4              0.25     7
    +##  8 P000001 S0001       TRUE              20            4              0.25     8
    +##  9 P000001 S0001       TRUE              20            4              0.25     9
    +## 10 P000001 S0001       TRUE              20            4              0.25    10
    +## # ℹ 58,357 more rows
    +## # ℹ 2 more variables: n_ae <int>, study_id <chr>
     df_site
    ## # A tibble: 300 × 6
    -##    study_id           site_number n_pat n_pat_with_med75 visit_med75 mean_ae_s…¹
    -##    <chr>              <chr>       <int>            <int>       <dbl>       <dbl>
    -##  1 ae_per_visit: 0.05 S0001          10                8          16       0    
    -##  2 ae_per_visit: 0.05 S0002          10                9          16       0.333
    -##  3 ae_per_visit: 0.05 S0003          10               10          15       0.3  
    -##  4 ae_per_visit: 0.05 S0004          10                9          16       0.111
    -##  5 ae_per_visit: 0.05 S0005          10                9          18       0.556
    -##  6 ae_per_visit: 0.05 S0006          10                8          17       0    
    -##  7 ae_per_visit: 0.05 S0007          10               10          16       0.6  
    -##  8 ae_per_visit: 0.05 S0008          10               10          15       0.5  
    -##  9 ae_per_visit: 0.05 S0009          10                9          17       0.111
    -## 10 ae_per_visit: 0.05 S0010          10               10          16       0.5  
    -## # … with 290 more rows, and abbreviated variable name ¹​mean_ae_site_med75
    +## study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +## <chr> <chr> <int> <int> <dbl> <dbl> +## 1 ae_per_vis… S0001 10 9 16 0.556 +## 2 ae_per_vis… S0002 10 10 14 0.3 +## 3 ae_per_vis… S0003 10 8 15 0.375 +## 4 ae_per_vis… S0004 10 8 14 0.375 +## 5 ae_per_vis… S0005 10 9 17 0.333 +## 6 ae_per_vis… S0006 10 7 15 0.143 +## 7 ae_per_vis… S0007 10 8 16 0.375 +## 8 ae_per_vis… S0008 10 7 19 0.714 +## 9 ae_per_vis… S0009 10 9 15 0.333 +## 10 ae_per_vis… S0010 10 7 15 0.714 +## # ℹ 290 more rows
     df_sim_sites
    ## # A tibble: 300 × 10
    -##    study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷    pval prob_…⁸
    -##    <chr>   <chr>   <int>   <int>   <dbl>   <dbl>   <dbl>   <int>   <dbl>   <dbl>
    -##  1 ae_per… S0001      10       8      16   0       0.699     860 0.00834   0.004
    -##  2 ae_per… S0002      10       9      16   0.333   0.696     859 0.307     0.132
    -##  3 ae_per… S0003      10      10      15   0.3     0.643     898 0.230     0.106
    -##  4 ae_per… S0004      10       9      16   0.111   0.698     859 0.0252    0.016
    -##  5 ae_per… S0005      10       9      18   0.556   0.791     704 0.570     0.28 
    -##  6 ae_per… S0006      10       8      17   0       0.742     787 0.00559   0.007
    -##  7 ae_per… S0007      10      10      16   0.6     0.693     858 1         0.44 
    -##  8 ae_per… S0008      10      10      15   0.5     0.640     898 0.840     0.358
    -##  9 ae_per… S0009      10       9      17   0.111   0.742     786 0.0178    0.013
    -## 10 ae_per… S0010      10      10      16   0.5     0.695     858 0.699     0.304
    -## # … with 290 more rows, and abbreviated variable names ¹​study_id, ²​site_number,
    -## #   ³​n_pat_with_med75, ⁴​visit_med75, ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75,
    -## #   ⁷​n_pat_with_med75_study, ⁸​prob_low
    +## study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +## <chr> <chr> <int> <int> <dbl> <dbl> +## 1 ae_per_vis… S0001 10 9 16 0.556 +## 2 ae_per_vis… S0002 10 10 14 0.3 +## 3 ae_per_vis… S0003 10 8 15 0.375 +## 4 ae_per_vis… S0004 10 8 14 0.375 +## 5 ae_per_vis… S0005 10 9 17 0.333 +## 6 ae_per_vis… S0006 10 7 15 0.143 +## 7 ae_per_vis… S0007 10 8 16 0.375 +## 8 ae_per_vis… S0008 10 7 19 0.714 +## 9 ae_per_vis… S0009 10 9 15 0.333 +## 10 ae_per_vis… S0010 10 7 15 0.714 +## # ℹ 290 more rows +## # ℹ 4 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +## # pval <dbl>, prob_low <dbl>

    Simulate Studies @@ -257,17 +260,9 @@

    Simulate Studies
     set.seed(1)
     
    -future::plan(multiprocess)

    -
    ## Warning: Strategy 'multiprocess' is deprecated in future (>= 1.20.0)
    -## [2020-10-30]. Instead, explicitly specify either 'multisession' (recommended) or
    -## 'multicore'. In the current R session, 'multiprocess' equals 'multisession'.
    -
    ## Warning in supportsMulticoreAndRStudio(...): [ONE-TIME WARNING] Forked
    -## processing ('multicore') is not supported when running R from RStudio
    -## because it is considered unstable. For more details, how to control forked
    -## processing or not, and how to silence this warning in future R sessions,
    -## see ?parallelly::supportsMulticore
    -
    -df_sim_studies <- sim_studies(df_visit, df_site,
    +plan(multisession, workers = 6)
    +
    +df_sim_studies <- sim_studies(df_visit, df_site,
                                   r = 100,
                                   parallel = TRUE,
                                   poisson_test = TRUE,
    @@ -276,20 +271,20 @@ 

    Simulate Studies df_sim_studies

    ## # A tibble: 30,000 × 8
    -##        r study_id           site_number visit_me…¹ n_pat…² n_pat…³  pval prob_…⁴
    -##    <dbl> <chr>              <chr>            <dbl>   <int>   <dbl> <dbl>   <dbl>
    -##  1     1 ae_per_visit: 0.05 S0001               16       8     860 0.389   0.208
    -##  2     1 ae_per_visit: 0.05 S0002               16       9     859 0.841   0.362
    -##  3     1 ae_per_visit: 0.05 S0003               15      10     898 1       1    
    -##  4     1 ae_per_visit: 0.05 S0004               16       9     859 0.672   0.363
    -##  5     1 ae_per_visit: 0.05 S0005               18       9     704 1       1    
    -##  6     1 ae_per_visit: 0.05 S0006               17       8     787 0.543   0.26 
    -##  7     1 ae_per_visit: 0.05 S0007               16      10     858 1       0.48 
    -##  8     1 ae_per_visit: 0.05 S0008               15      10     898 0.105   0.047
    -##  9     1 ae_per_visit: 0.05 S0009               17       9     786 1       0.562
    -## 10     1 ae_per_visit: 0.05 S0010               16      10     858 1       0.576
    -## # … with 29,990 more rows, and abbreviated variable names ¹​visit_med75,
    -## #   ²​n_pat_with_med75, ³​n_pat_study, ⁴​prob_low
    +## r study_id site_number visit_med75 n_pat_with_med75 n_pat_study pval +## <dbl> <chr> <chr> <dbl> <int> <dbl> <dbl> +## 1 1 ae_per_vis… S0001 16 9 819 1 +## 2 1 ae_per_vis… S0002 14 10 911 1 +## 3 1 ae_per_vis… S0003 15 8 872 0.0511 +## 4 1 ae_per_vis… S0004 14 8 913 0.827 +## 5 1 ae_per_vis… S0005 17 9 750 1 +## 6 1 ae_per_vis… S0006 15 7 873 1 +## 7 1 ae_per_vis… S0007 16 8 820 0.391 +## 8 1 ae_per_vis… S0008 19 7 564 1 +## 9 1 ae_per_vis… S0009 15 9 871 1 +## 10 1 ae_per_vis… S0010 15 7 873 1 +## # ℹ 29,990 more rows +## # ℹ 1 more variable: prob_low <dbl>

    Check p-value Probabilities @@ -302,28 +297,27 @@

    Check p-value Probabilities
    +
     df_check_pval <- get_ecd_values(df_sim_studies, df_sim_sites, val_str = "pval")
     
     df_check_pval
    ## # A tibble: 300 × 11
    -##    study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷    pval prob_…⁸
    -##    <chr>   <chr>   <int>   <int>   <dbl>   <dbl>   <dbl>   <int>   <dbl>   <dbl>
    -##  1 ae_per… S0001      10       8      16   0       0.699     860 0.00834   0.004
    -##  2 ae_per… S0002      10       9      16   0.333   0.696     859 0.307     0.132
    -##  3 ae_per… S0003      10      10      15   0.3     0.643     898 0.230     0.106
    -##  4 ae_per… S0004      10       9      16   0.111   0.698     859 0.0252    0.016
    -##  5 ae_per… S0005      10       9      18   0.556   0.791     704 0.570     0.28 
    -##  6 ae_per… S0006      10       8      17   0       0.742     787 0.00559   0.007
    -##  7 ae_per… S0007      10      10      16   0.6     0.693     858 1         0.44 
    -##  8 ae_per… S0008      10      10      15   0.5     0.640     898 0.840     0.358
    -##  9 ae_per… S0009      10       9      17   0.111   0.742     786 0.0178    0.013
    -## 10 ae_per… S0010      10      10      16   0.5     0.695     858 0.699     0.304
    -## # … with 290 more rows, 1 more variable: pval_ecd <dbl>, and abbreviated
    -## #   variable names ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75,
    -## #   ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study,
    -## #   ⁸​prob_low
    -
    +##    study_id    site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75
    +##    <chr>       <chr>       <int>            <int>       <dbl>              <dbl>
    +##  1 ae_per_vis… S0001          10                9          16              0.556
    +##  2 ae_per_vis… S0002          10               10          14              0.3  
    +##  3 ae_per_vis… S0003          10                8          15              0.375
    +##  4 ae_per_vis… S0004          10                8          14              0.375
    +##  5 ae_per_vis… S0005          10                9          17              0.333
    +##  6 ae_per_vis… S0006          10                7          15              0.143
    +##  7 ae_per_vis… S0007          10                8          16              0.375
    +##  8 ae_per_vis… S0008          10                7          19              0.714
    +##  9 ae_per_vis… S0009          10                9          15              0.333
    +## 10 ae_per_vis… S0010          10                7          15              0.714
    +## # ℹ 290 more rows
    +## # ℹ 5 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>,
    +## #   pval <dbl>, prob_low <dbl>, pval_ecd <dbl>
    +
     df_check_pval %>%
       ggplot(aes(log(pval, base = 10), log(pval_ecd, base = 10))) +
         geom_point(alpha = 0.5, size = 2) +
    @@ -342,28 +336,27 @@ 

    Perform Same Check on

    Note: Dots on the edge of the graph that are cut off have zero value for the corresponding axis. For the tie simulations using 1000 repeats the smallest value greater zero we get for prob_low is 0.001 (1e-3).

    -
    +
     df_check_prob <- get_ecd_values(df_sim_studies, df_sim_sites, val_str = "prob_low")
     
     df_check_prob
    ## # A tibble: 300 × 11
    -##    study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷    pval prob_…⁸
    -##    <chr>   <chr>   <int>   <int>   <dbl>   <dbl>   <dbl>   <int>   <dbl>   <dbl>
    -##  1 ae_per… S0001      10       8      16   0       0.699     860 0.00834   0.004
    -##  2 ae_per… S0002      10       9      16   0.333   0.696     859 0.307     0.132
    -##  3 ae_per… S0003      10      10      15   0.3     0.643     898 0.230     0.106
    -##  4 ae_per… S0004      10       9      16   0.111   0.698     859 0.0252    0.016
    -##  5 ae_per… S0005      10       9      18   0.556   0.791     704 0.570     0.28 
    -##  6 ae_per… S0006      10       8      17   0       0.742     787 0.00559   0.007
    -##  7 ae_per… S0007      10      10      16   0.6     0.693     858 1         0.44 
    -##  8 ae_per… S0008      10      10      15   0.5     0.640     898 0.840     0.358
    -##  9 ae_per… S0009      10       9      17   0.111   0.742     786 0.0178    0.013
    -## 10 ae_per… S0010      10      10      16   0.5     0.695     858 0.699     0.304
    -## # … with 290 more rows, 1 more variable: prob_low_ecd <dbl>, and abbreviated
    -## #   variable names ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75,
    -## #   ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study,
    -## #   ⁸​prob_low
    -
    +##    study_id    site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75
    +##    <chr>       <chr>       <int>            <int>       <dbl>              <dbl>
    +##  1 ae_per_vis… S0001          10                9          16              0.556
    +##  2 ae_per_vis… S0002          10               10          14              0.3  
    +##  3 ae_per_vis… S0003          10                8          15              0.375
    +##  4 ae_per_vis… S0004          10                8          14              0.375
    +##  5 ae_per_vis… S0005          10                9          17              0.333
    +##  6 ae_per_vis… S0006          10                7          15              0.143
    +##  7 ae_per_vis… S0007          10                8          16              0.375
    +##  8 ae_per_vis… S0008          10                7          19              0.714
    +##  9 ae_per_vis… S0009          10                9          15              0.333
    +## 10 ae_per_vis… S0010          10                7          15              0.714
    +## # ℹ 290 more rows
    +## # ℹ 5 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>,
    +## #   pval <dbl>, prob_low <dbl>, prob_low_ecd <dbl>
    +
     df_check_prob %>%
       ggplot(aes(log(prob_low, base = 10), log(prob_low_ecd, base = 10))) +
         geom_point(alpha = 0.5, size = 2) +
    @@ -387,6 +380,8 @@ 

    Conclusion
    +plan(sequential)

    @@ -408,7 +403,7 @@

    Conclusion

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/check_poisson_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/check_poisson_files/figure-html/unnamed-chunk-4-1.png index 4eb24a0..e25f87d 100644 Binary files a/docs/articles/check_poisson_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/check_poisson_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/check_poisson_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/check_poisson_files/figure-html/unnamed-chunk-5-1.png index deeab82..8a3a9bb 100644 Binary files a/docs/articles/check_poisson_files/figure-html/unnamed-chunk-5-1.png and b/docs/articles/check_poisson_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/gsm_perf.html b/docs/articles/gsm_perf.html new file mode 100644 index 0000000..f8ae437 --- /dev/null +++ b/docs/articles/gsm_perf.html @@ -0,0 +1,1643 @@ + + + + + + + +Comparing {simaerep} and {gsm} Performance • simaerep + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    +
    + + + + + +
    +

    Install {gsm} +

    +
    +devtools::install_github("Gilead-BioStats/gsm", ref = "main")
    +
    +
    +

    Introduction +

    +

    The {gsm} R +package provides a standardized Risk Based Quality Monitoring (RBQM) +framework for clinical trials that pairs a flexible data pipeline with +robust reports. It also uses Funnel Plots to flag outliers which provide +broader tolerance limits for sites with low exposure and narrower limits +for sites with higher exposure. This method is different to the event +rate based limits we have used in previous heuristics to measure +{simaerep} performance. Funnel plots are discussed in greater detail by +Zink et +al. 2018

    +

    One of the draw backs of using funnel plots for flagging is that they +assume that the AE rate remains constant over the course of the +study.

    +
    +
    +

    Prepare Data +

    +
    +

    Load Portfolio Configurations +

    +

    We have prepared a snapshot of the AE reporting configuration of our +current portfolio. For each study we have also measured a visit-specific +AE rate which allows us to generate a synthetic portfolio with flexible +AE rates across a study.

    +
    +df_config <- readr::read_csv("ae_conf_20240220.csv")
    +df_ae_rates <- readr::read_csv("ae_rates_20240220.csv")
    +
    +df_config %>%
    +  head(25) %>%
    +  knitr::kable()
    + ++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    study_idae_per_visit_meansite_numbermax_visit_sdmax_visit_meann_pat
    00010.297380647463.535533916.500002
    00010.297380647470.707106827.500002
    00010.297380647500.500000019.250004
    00010.297380648158.376554622.166676
    00010.297380648160.000000027.000001
    00010.297380648170.000000031.000001
    00010.297380648180.000000030.000001
    00010.297380648912.380476122.000007
    00010.297380648930.000000020.000002
    00010.297380649321.095445126.800005
    00010.297380649411.732050827.000003
    00010.297380649421.414213625.000002
    00010.297380649430.000000025.000001
    00010.297380649660.000000018.000001
    00010.297380649670.816496618.000004
    00010.297380649680.000000024.000001
    00010.297380649691.527525221.333333
    00010.297380649841.707825130.750004
    00010.297380649858.908797221.166676
    00010.297380649860.577350320.333333
    00010.297380649881.414213619.000002
    00010.297380650792.160246923.000004
    00010.297380650800.000000023.000001
    00010.297380650810.000000023.000001
    00010.297380650821.414213622.000002
    +
    +df_ae_rates %>%
    +  head(25) %>%
    +  knitr::kable()
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    study_idcum_visitae_raten_pat
    000110.017699113
    000120.088496113
    000130.230088113
    000140.223214112
    000150.187500112
    000160.196429112
    000170.396396111
    000180.207207111
    000190.216216111
    0001100.315315111
    0001110.263636110
    0001120.318182110
    0001130.345455110
    0001140.379630108
    0001150.401869107
    0001160.485981107
    0001170.383178107
    0001180.396226106
    0001190.370000100
    0001200.43956091
    0001210.36986373
    0001220.37096862
    0001230.34545555
    0001240.44680947
    0001250.29268341
    +
    +
    +

    Simulate Portfolio +

    +

    We generate two synthetic portfolios with no AE under-reporting +sites. One portfolio with a fixed AE rate for all visits and another one +with a flexible visit-specific AE rate.

    +
    +df_portf_fix <- sim_test_data_portfolio(df_config, parallel = TRUE, progress = TRUE)
    +
    +df_portf_fix %>%
    +  head(25) %>%
    +  knitr::kable()
    + ++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    study_idae_per_visit_meansite_numbermax_visit_sdmax_visit_meanpatnumvisitn_ae
    00010.297380647463.53553416.5000110
    00010.297380647463.53553416.5000120
    00010.297380647463.53553416.5000130
    00010.297380647463.53553416.5000140
    00010.297380647463.53553416.5000150
    00010.297380647463.53553416.5000160
    00010.297380647463.53553416.5000170
    00010.297380647463.53553416.5000180
    00010.297380647463.53553416.5000190
    00010.297380647463.53553416.50001100
    00010.297380647463.53553416.50001110
    00010.297380647463.53553416.5000211
    00010.297380647463.53553416.5000221
    00010.297380647463.53553416.5000231
    00010.297380647463.53553416.5000242
    00010.297380647463.53553416.5000252
    00010.297380647463.53553416.5000263
    00010.297380647463.53553416.5000274
    00010.297380647463.53553416.5000284
    00010.297380647463.53553416.5000295
    00010.297380647463.53553416.50002105
    00010.297380647463.53553416.50002116
    00010.297380647463.53553416.50002126
    00010.297380647463.53553416.50002136
    00010.297380647463.53553416.50002146
    +
    +df_portf_flex <- sim_test_data_portfolio(df_config, df_ae_rates = df_ae_rates, parallel = TRUE, progress = TRUE)
    +
    +
    +

    Compare AE rates +

    +

    Next we confirm the different AE rates in our two synthetic +portfolios.

    +
    +df_rate_fix <- df_portf_fix %>%
    +  mutate(ae_rate = coalesce(n_ae - lag(n_ae), n_ae), .by = c("study_id", "patnum")) %>%
    +  summarise(ae_rate = mean(ae_rate), .by = c("study_id", "visit")) %>%
    +  mutate(rate = "fix")
    +
    +
    +df_rate_flex <- df_portf_flex %>%
    +  mutate(ae_rate = coalesce(n_ae - lag(n_ae), n_ae), .by = c("study_id", "patnum")) %>%
    +  summarise(ae_rate = mean(ae_rate), .by = c("study_id", "visit")) %>%
    +  mutate(rate = "flex")
    +
    +bind_rows(df_rate_flex, df_rate_fix) %>%
    +  ggplot(aes(visit, ae_rate)) +
    +    geom_line(aes(group = study_id), alpha = 0.2) +
    +    geom_smooth() +
    +    facet_wrap(~ rate) +
    +    labs(title = "Average AE rates per Study")
    +

    +
    +bind_rows(df_rate_flex, df_rate_fix) %>%
    +  filter(dense_rank(study_id) <= 16) %>%
    +  ggplot(aes(visit, ae_rate)) +
    +    geom_line(aes(group = rate, color = rate)) +
    +    facet_wrap(~ study_id, scales = "free") +
    +    labs(title = "Average AE rates for Selected Studies")
    +

    +

    We can confirm that the AE rates in the “flexible” portfolio are not +constant. Moreover we see that the AE rate profile is very unique for +each study.

    +
    +
    +
    +

    Apply {gsm} +

    +
    +

    Example +

    +

    Here we demonstrate how to use the {gsm} package on our simulated +portfolios.

    +
    +get_SUBJ <- function(df_portf) {
    +  df_portf %>%
    +    select(study_id, siteid = site_number, subjid = patnum, timeonstudy = visit) %>%
    +    summarise(timeonstudy = max(timeonstudy), .by = c(study_id, siteid, subjid)) %>%
    +    group_by(study_id) %>%
    +    nest()
    +}
    +
    +
    +get_AE <- function(df_portf) {
    +  df_portf_fix %>%
    +    select(study_id, subjid = patnum, n_ae) %>%
    +    summarise(n_ae = max(n_ae), .by = c(study_id, subjid)) %>%
    +    filter(n_ae > 0) %>%
    +    mutate(n_ae = map(n_ae, ~ tibble(n = seq(1, .)), .progress = TRUE)) %>%
    +    unnest(n_ae) %>%
    +    select(- n) %>%
    +    group_by(study_id) %>%
    +    nest()
    +}
    +
    +dfSUBJ_fix <- get_SUBJ(df_portf_fix)
    +dfAE_fix <- get_AE(df_portf_fix)
    +
    +dfInput <- gsm::AE_Map_Raw(list(dfSUBJ = dfSUBJ_fix$data[[1]], dfAE = dfAE_fix$data[[1]]))
    +dfInput
    +
    ## # A tibble: 113 × 5
    +##    SubjectID SiteID Exposure Count   Rate
    +##    <chr>     <chr>     <int> <int>  <dbl>
    +##  1 0001      4746         11     0 0     
    +##  2 0002      4746         17     6 0.353 
    +##  3 0003      4747         27     6 0.222 
    +##  4 0004      4747         27     5 0.185 
    +##  5 0005      4750         18    10 0.556 
    +##  6 0006      4750         19     8 0.421 
    +##  7 0007      4750         19     8 0.421 
    +##  8 0008      4750         18     7 0.389 
    +##  9 0009      4815         15     3 0.2   
    +## 10 0010      4815         31     2 0.0645
    +## # ℹ 103 more rows
    +
    +dfTransformed <- gsm::Transform_Rate(
    +  dfInput,
    +  strNumeratorCol = "Count",
    +  strDenominatorCol = "Exposure"
    +  )
    +dfTransformed
    +
    ## # A tibble: 44 × 4
    +##    GroupID Numerator Denominator Metric
    +##    <chr>       <int>       <int>  <dbl>
    +##  1 4746            6          28  0.214
    +##  2 4747           11          54  0.204
    +##  3 4750           33          74  0.446
    +##  4 4815           33         145  0.228
    +##  5 4816            8          27  0.296
    +##  6 4817            5          31  0.161
    +##  7 4818            5          30  0.167
    +##  8 4891           45         144  0.312
    +##  9 4893           13          40  0.325
    +## 10 4932           36         132  0.273
    +## # ℹ 34 more rows
    +
    +dfAnalyzed <- gsm::Analyze_NormalApprox(dfTransformed)
    +dfAnalyzed
    +
    ## # A tibble: 44 × 7
    +##    GroupID Numerator Denominator Metric OverallMetric Factor  Score
    +##    <chr>       <int>       <int>  <dbl>         <dbl>  <dbl>  <dbl>
    +##  1 4815           33         145  0.228         0.300   1.31 -1.65 
    +##  2 4941           17          80  0.212         0.300   1.31 -1.48 
    +##  3 4817            5          31  0.161         0.300   1.31 -1.47 
    +##  4 4818            5          30  0.167         0.300   1.31 -1.39 
    +##  5 5079           20          89  0.225         0.300   1.31 -1.35 
    +##  6 4747           11          54  0.204         0.300   1.31 -1.34 
    +##  7 5311            3          20  0.15          0.300   1.31 -1.27 
    +##  8 5084            4          21  0.190         0.300   1.31 -0.953
    +##  9 4943            5          25  0.2           0.300   1.31 -0.949
    +## 10 4746            6          28  0.214         0.300   1.31 -0.860
    +## # ℹ 34 more rows
    +
    +dfFlagged <- gsm::Flag_NormalApprox(dfAnalyzed, vThreshold = c(-3, -2, 2, 3))
    +dfFlagged
    +
    ## # A tibble: 44 × 8
    +##    GroupID Numerator Denominator Metric OverallMetric Factor Score  Flag
    +##    <chr>       <int>       <int>  <dbl>         <dbl>  <dbl> <dbl> <dbl>
    +##  1 5168            9          15  0.6           0.300   1.31  2.22     1
    +##  2 5194           76         197  0.386         0.300   1.31  2.31     1
    +##  3 4750           33          74  0.446         0.300   1.31  2.40     1
    +##  4 4815           33         145  0.228         0.300   1.31 -1.65     0
    +##  5 4941           17          80  0.212         0.300   1.31 -1.48     0
    +##  6 4817            5          31  0.161         0.300   1.31 -1.47     0
    +##  7 4818            5          30  0.167         0.300   1.31 -1.39     0
    +##  8 5079           20          89  0.225         0.300   1.31 -1.35     0
    +##  9 4747           11          54  0.204         0.300   1.31 -1.34     0
    +## 10 5311            3          20  0.15          0.300   1.31 -1.27     0
    +## # ℹ 34 more rows
    +
    +dfSummary <- gsm::Summarize(dfFlagged)
    +dfSummary
    +
    ## # A tibble: 44 × 6
    +##    GroupID Numerator Denominator Metric Score  Flag
    +##    <chr>       <int>       <int>  <dbl> <dbl> <dbl>
    +##  1 5168            9          15  0.6   2.22      1
    +##  2 4750           33          74  0.446 2.40      1
    +##  3 5194           76         197  0.386 2.31      1
    +##  4 5083           18          44  0.409 1.39      0
    +##  5 5265           16          42  0.381 1.01      0
    +##  6 5130           52         140  0.371 1.62      0
    +##  7 4986           21          58  0.362 0.908     0
    +##  8 5131            8          23  0.348 0.442     0
    +##  9 4985           38         111  0.342 0.860     0
    +## 10 5224            8          24  0.333 0.316     0
    +## # ℹ 34 more rows
    +
    +dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(dfTransformed, vThreshold = c(-3, -2, 2, 3))
    +dfBounds
    +
    ## # A tibble: 1,246 × 5
    +##    Threshold Denominator LogDenominator Numerator  Metric
    +##        <dbl>       <dbl>          <dbl>     <dbl>   <dbl>
    +##  1        -3        28.1           3.34    0.0765 0.00272
    +##  2        -3        28.8           3.36    0.187  0.00649
    +##  3        -3        29.6           3.39    0.299  0.0101 
    +##  4        -3        30.3           3.41    0.413  0.0136 
    +##  5        -3        31.0           3.43    0.527  0.0170 
    +##  6        -3        31.7           3.46    0.643  0.0203 
    +##  7        -3        32.5           3.48    0.760  0.0234 
    +##  8        -3        33.2           3.50    0.878  0.0264 
    +##  9        -3        33.9           3.52    0.997  0.0294 
    +## 10        -3        34.7           3.55    1.12   0.0322 
    +## # ℹ 1,236 more rows
    +
    +chart <- gsm::Visualize_Scatter(dfFlagged, dfBounds)
    +chart
    +

    +
    +
    +

    Simulate UR +

    +

    We write a function that removes a given ratio of AEs from one site +in the data set and returns its z-score.

    +
    +sim_site_ur_gsm <- function(site, ur_rate, dfTransformed) {
    +  dfTransformed <- dfTransformed %>%
    +    mutate(
    +      Numerator = ifelse(GroupID == site, Numerator * (1 - ur_rate), Numerator),
    +      Metric = Numerator / Denominator
    +    )
    +  
    +  gsm::Analyze_NormalApprox(dfTransformed) %>%
    +    filter(GroupID == site) %>%
    +    pull(Score)
    +}
    +
    +sim_site_ur_gsm("4747", ur_rate = 0.75, dfTransformed)
    +
    ## [1] -3.095796
    +

    We write another function that systematically applies this +sim_site_ur_gsm across all sites in all studies across a +range of under-reporting ratios.

    +
    +sim_ur_gsm <- function(dfSUBJ, dfAE) {
    +  dfSUBJ %>%
    +    inner_join(dfAE, by = "study_id") %>%
    +    ungroup() %>%
    +    mutate(
    +      trans = map2(data.x, data.y, ~ gsm::AE_Map_Raw(list(dfSUBJ = .x, dfAE = .y))),
    +      trans = map(trans, ~ gsm::Transform_Rate(., strNumeratorCol = "Count", strDenominatorCol = "Exposure")),
    +      sites = map(data.x, ~ distinct(., siteid))
    +    ) %>%
    +    select(- starts_with("data.")) %>%
    +    unnest(sites) %>%
    +    mutate(ur = list(tibble(ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1)))) %>%
    +    unnest(ur) %>%
    +    mutate(
    +      score = pmap_dbl(list(siteid, ur_rate, trans), sim_site_ur_gsm, .progress = TRUE)
    +    )
    +}
    +
    +df_sim_gsm_fix <- sim_ur_gsm(dfSUBJ_fix, dfAE_fix)
    +
    ## Warning: There were 3116 warnings in `mutate()`.
    +## The first warning was:
    +##  In argument: `z_i = ifelse(...)`.
    +## Caused by warning:
    +## ! There was 1 warning in `mutate()`.
    +##  In argument: `z_0 = ifelse(...)`.
    +## Caused by warning in `sqrt()`:
    +## ! NaNs produced
    +##  Run `dplyr::last_dplyr_warnings()` to see the 3115 remaining warnings.
    +
    +df_sim_gsm_fix
    +
    ## # A tibble: 129,966 × 5
    +##    study_id trans             siteid ur_rate  score
    +##    <chr>    <list>            <chr>    <dbl>  <dbl>
    +##  1 0001     <tibble [44 × 4]> 4746      0    -0.860
    +##  2 0001     <tibble [44 × 4]> 4746      0.1  -1.07 
    +##  3 0001     <tibble [44 × 4]> 4746      0.25 -1.38 
    +##  4 0001     <tibble [44 × 4]> 4746      0.5  -1.87 
    +##  5 0001     <tibble [44 × 4]> 4746      0.75 -2.33 
    +##  6 0001     <tibble [44 × 4]> 4746      1    -2.75 
    +##  7 0001     <tibble [44 × 4]> 4747      0    -1.34 
    +##  8 0001     <tibble [44 × 4]> 4747      0.1  -1.61 
    +##  9 0001     <tibble [44 × 4]> 4747      0.25 -1.99 
    +## 10 0001     <tibble [44 × 4]> 4747      0.5  -2.57 
    +## # ℹ 129,956 more rows
    +

    We repeat the same steps for the portfolio with the flexible AE +rates.

    +
    +dfSUBJ_flex <- get_SUBJ(df_portf_flex)
    +dfAE_flex<- get_AE(df_portf_flex)
    +
    +
    +df_sim_gsm_flex <- sim_ur_gsm(dfSUBJ_flex, dfAE_flex)
    +
    ## Warning: There were 3085 warnings in `mutate()`.
    +## The first warning was:
    +##  In argument: `z_i = ifelse(...)`.
    +## Caused by warning:
    +## ! There was 1 warning in `mutate()`.
    +##  In argument: `z_0 = ifelse(...)`.
    +## Caused by warning in `sqrt()`:
    +## ! NaNs produced
    +##  Run `dplyr::last_dplyr_warnings()` to see the 3084 remaining warnings.
    +
    +
    +
    +

    UR {simaerep} +

    +

    We simulate under-reporting for both portfolios using {simaerep}

    +
    +df_sim_simaerep_fix <- sim_ur_scenarios(
    +   df_portf_fix,
    +   extra_ur_sites = 0,
    +   ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1),
    +   parallel = TRUE,
    +   poisson = TRUE,
    +   prob_lower = TRUE,
    +   progress = TRUE
    +)
    +
    +df_sim_simaerep_flex <- sim_ur_scenarios(
    +   df_portf_flex,
    +   extra_ur_sites = 0,
    +   ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1),
    +   parallel = TRUE,
    +   poisson = TRUE,
    +   prob_lower = TRUE,
    +   progress = TRUE
    +)
    +
    +
    +

    Evaluate +

    +
    +

    Combine Results +

    +
    +df_sim_gsm_fix$ae_rate <- "AE rate: fix"
    +df_sim_gsm_flex$ae_rate <- "AE rate: flexible"
    +df_sim_simaerep_fix$ae_rate <- "AE rate: fix"
    +df_sim_simaerep_flex$ae_rate <- "AE rate: flexible"
    +
    +df_sim_thresh2 <- bind_rows(df_sim_gsm_fix, df_sim_gsm_flex) %>%
    +  mutate(
    +    is_ur = score <= -2,
    +    type = "{gsm} - thresh: -2",
    +    site_number = siteid
    +  ) %>%
    +  select(type, ae_rate, study_id, site_number, ur_rate, is_ur, score)
    +
    +
    +df_sim_simaerep_threshp95 <-  bind_rows(df_sim_simaerep_fix, df_sim_simaerep_flex) %>%
    +  mutate(
    +    is_ur = prob_low_prob_ur >= 0.95,
    +    type = "{simaerep} - thresh: 0.95"
    +  ) %>%
    +  select(type, ae_rate, study_id, site_number, ur_rate, is_ur, score = prob_low_prob_ur)
    +
    +
    +df_eval <- bind_rows(
    +  df_sim_thresh2,
    +  df_sim_simaerep_threshp95,
    +)
    +
    +
    +

    Aggregate +

    +
    +get_prop_test_ci95 <- function(..., ix) {
    +  
    +  stopifnot(ix %in% c(1, 2))
    +  
    +  tryCatch(
    +    prop.test(...)$conf.int[ix],
    +    error = function(cnd) c(NA, NA)[ix]
    +  )
    +}
    +
    +aggr_results <- function(df_eval) {
    +
    +df_perf <- df_eval %>%
    +  summarise(
    +    n = n(),
    +    .by = c(type, ae_rate, ur_rate, is_ur)
    +  ) %>%
    +  pivot_wider(
    +    names_from = is_ur,
    +    values_from = n,
    +    names_prefix = "is_ur_",
    +    values_fill = 0
    +  ) %>%
    +  mutate(
    +    n_sites = is_ur_TRUE + is_ur_FALSE + is_ur_NA,
    +    ratio = is_ur_TRUE / n_sites,
    +    ratio_type = ifelse(ur_rate == 0, "fpr", "tpr"),
    +    ci95_low = map2_dbl(is_ur_TRUE, n_sites, ~ get_prop_test_ci95(.x, .y, ix = 1)),
    +    ci95_high = map2_dbl(is_ur_TRUE, n_sites, ~ get_prop_test_ci95(.x, .y, ix = 2))
    +  )
    +}
    +
    +df_perf <- aggr_results(df_eval)
    +
    +
    +
    +

    Results +

    +
    +

    Table +

    +
    +df_perf %>%
    +  knitr::kable(digits = 3)
    + +++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    typeae_rateur_rateis_ur_FALSEis_ur_TRUEis_ur_NAn_sitesratioratio_typeci95_lowci95_high
    {gsm} - thresh: -2AE rate: fix0.0020830299532216610.014fpr0.0120.015
    {gsm} - thresh: -2AE rate: fix0.10198511278532216610.059tpr0.0560.062
    {gsm} - thresh: -2AE rate: fix0.25158485282531216610.244tpr0.2380.250
    {gsm} - thresh: -2AE rate: fix0.50915411987520216610.553tpr0.5470.560
    {gsm} - thresh: -2AE rate: fix0.75521415941506216610.736tpr0.7300.742
    {gsm} - thresh: -2AE rate: fix1.00291518251495216610.843tpr0.8380.847
    {gsm} - thresh: -2AE rate: flexible0.0020899241521216610.011fpr0.0100.013
    {gsm} - thresh: -2AE rate: flexible0.1020669471521216610.022tpr0.0200.024
    {gsm} - thresh: -2AE rate: flexible0.25197421399520216610.065tpr0.0610.068
    {gsm} - thresh: -2AE rate: flexible0.50164484698515216610.217tpr0.2110.222
    {gsm} - thresh: -2AE rate: flexible0.75123208830511216610.408tpr0.4010.414
    {gsm} - thresh: -2AE rate: flexible1.00872712437497216610.574tpr0.5680.581
    {simaerep} - thresh: 0.95AE rate: fix0.00213672940216610.014fpr0.0120.015
    {simaerep} - thresh: 0.95AE rate: fix0.102036612950216610.060tpr0.0570.063
    {simaerep} - thresh: 0.95AE rate: fix0.251715545060216610.208tpr0.2030.214
    {simaerep} - thresh: 0.95AE rate: fix0.5010635110260216610.509tpr0.5020.516
    {simaerep} - thresh: 0.95AE rate: fix0.755845158160216610.730tpr0.7240.736
    {simaerep} - thresh: 0.95AE rate: fix1.004053176080216610.813tpr0.8080.818
    {simaerep} - thresh: 0.95AE rate: flexible0.00213403210216610.015fpr0.0130.017
    {simaerep} - thresh: 0.95AE rate: flexible0.102023414270216610.066tpr0.0630.069
    {simaerep} - thresh: 0.95AE rate: flexible0.251666150000216610.231tpr0.2250.237
    {simaerep} - thresh: 0.95AE rate: flexible0.509878117830216610.544tpr0.5370.551
    {simaerep} - thresh: 0.95AE rate: flexible0.755216164450216610.759tpr0.7530.765
    {simaerep} - thresh: 0.95AE rate: flexible1.003595180660216610.834tpr0.8290.839
    +
    +
    +

    Plot Performance Metrics +

    +
      +
    • {gsm} has better performance than {simaerep} when the AE rate is +fixed, while {simaerep} greatly outperforms {gsm} when the AE rate is +flexible and mimics the AE rates encountered in real study data +sets.
    • +
    +
    +plot_perf <- function(df_perf) {
    +
    +  df_perf %>%
    +    mutate(ur_rate = paste0("under-reporting rate: ",  ur_rate, " - ", ratio_type),
    +           ur_rate = ifelse(str_detect(ur_rate, "fpr"), "fpr", ur_rate)) %>%
    +    group_by(ur_rate) %>%
    +    ggplot(aes(type, ratio)) +
    +      geom_errorbar(aes(ymin = ci95_low, ymax = ci95_high, color = type), linewidth = 1) +
    +      facet_grid(ur_rate ~ ae_rate) +
    +      coord_flip() +
    +      theme(legend.position = "bottom") +
    +      labs(
    +        x = "",
    +        y = "CI95 Performance Ratio", 
    +        title = "{simaerep} vs {gsm} Performance"
    +      ) +
    +      scale_color_manual(values = c("#5491CC", "#F46626"))
    +}
    +
    +plot_perf(df_perf)
    +

    +
    +plan(sequential)
    +
    +
    +
    + + + +
    + + + +
    + +
    +

    +

    Site built with pkgdown 2.0.7.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/articles/gsm_perf_files/figure-html/plot-1.png b/docs/articles/gsm_perf_files/figure-html/plot-1.png new file mode 100644 index 0000000..2feedb9 Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/plot-1.png differ diff --git a/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 0000000..5098a97 Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..91a7a28 Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..e27fc8a Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 0000000..524a0f5 Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..7289510 Binary files /dev/null and b/docs/articles/gsm_perf_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 8b6151d..d1f3485 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4

    @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -107,6 +110,8 @@

    Articles

    Aggregate AEs by Days or Visit?
    +
    Comparing {simaerep} and {gsm} Performance
    +
    @@ -117,7 +122,7 @@

    Articles

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/intro.html b/docs/articles/intro.html index 21c3bf2..6b4f36f 100644 --- a/docs/articles/intro.html +++ b/docs/articles/intro.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -961,11 +964,6 @@

    Applying {simaerep}
     plot(aerep)
    ## study = NULL, defaulting to study:A
    -
    ## Warning: `all_equal()` was deprecated in dplyr 1.1.0.
    -##  Please use `all.equal()` instead.
    -##  And manually order the rows/cols as needed
    -##  The deprecated feature was likely used in the simaerep package.
    -##   Please report the issue to the authors.

    For modifying the default parameters please check out the simaerep() documentation.

    @@ -989,7 +987,7 @@

    Applying {simaerep}

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/portfolio_perf.html b/docs/articles/portfolio_perf.html index aac6361..b0dab2c 100644 --- a/docs/articles/portfolio_perf.html +++ b/docs/articles/portfolio_perf.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -243,162 +246,162 @@

    Portfolio Configuration 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 10 0001 -0.3582915 +0.3746743 0002 -4.813176 -20.5 +4.452215 +18.4 10 0001 -0.3582915 +0.3746743 0003 -4.690416 -20.0 +4.802777 +18.8 10 0001 -0.3582915 +0.3746743 0004 -2.378141 -21.9 +4.571652 +18.3 10 0001 -0.3582915 +0.3746743 0005 -4.478343 -19.5 +4.691600 +20.3 10 0001 -0.3582915 +0.3746743 0006 -3.198958 -19.3 +2.884826 +19.1 10 0001 -0.3582915 +0.3746743 0007 -2.503331 -19.6 +3.829708 +18.0 10 0001 -0.3582915 +0.3746743 0008 -2.213594 -20.3 +5.185450 +21.0 10 0001 -0.3582915 +0.3746743 0009 -5.391351 -18.8 +4.948625 +19.4 10 0001 -0.3582915 +0.3746743 0010 -3.695342 -19.9 +4.115013 +19.4 10 0002 -0.4827586 +0.5005081 0001 -3.675746 -18.8 +4.552167 +19.5 10 0002 -0.4827586 +0.5005081 0002 -6.168018 -19.6 +4.321779 +18.7 10 0002 -0.4827586 +0.5005081 0003 -3.717825 -19.4 +3.333333 +18.0 10 0002 -0.4827586 +0.5005081 0004 -4.137901 -18.3 +3.772709 +21.3 10 0002 -0.4827586 +0.5005081 0005 -3.705851 -21.2 +3.695342 +21.1 10 0002 -0.4827586 +0.5005081 0006 -3.178050 -18.1 +3.951090 +17.5 10 0002 -0.4827586 +0.5005081 0007 -5.103376 -19.4 +4.104198 +21.2 10 0002 -0.4827586 +0.5005081 0008 -3.472111 -19.5 +4.391912 +19.2 10 0002 -0.4827586 +0.5005081 0009 -2.677063 +3.374743 19.5 10 0002 -0.4827586 +0.5005081 0010 -2.460804 -20.5 +3.521363 +20.8 10 @@ -439,9 +442,9 @@

    Simulate Portfolio from Configura 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 1 @@ -449,29 +452,29 @@

    Simulate Portfolio from Configura 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 2 -0 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 3 -0 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 4 @@ -479,213 +482,213 @@

    Simulate Portfolio from Configura 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 5 -2 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 6 -3 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 7 -4 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 8 -4 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 9 -5 +2 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 10 -5 +2 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 11 -5 +2 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 12 -6 +3 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 13 -6 +4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 14 -6 +4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0001 15 -6 +5 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 -0001 -16 -6 +0002 +1 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 +2 1 -0 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -2 -2 +3 +1 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -3 4 +2 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -4 -4 +5 +3 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -5 +6 4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -6 +7 4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -7 +8 4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -8 -6 +9 +4 0001 -0.3582915 +0.3746743 0001 -3.119829 +3.794733 19.2 0002 -9 -6 +10 +5 @@ -1067,7 +1070,7 @@

    Simulate Portfolio622 0001 2 -0 +1 0001 @@ -1080,7 +1083,7 @@

    Simulate Portfolio622 0001 3 -0 +1 0001 @@ -1145,7 +1148,7 @@

    Simulate Portfolio622 0001 8 -3 +1 0001 @@ -1158,7 +1161,7 @@

    Simulate Portfolio622 0001 9 -3 +1 0001 @@ -1171,7 +1174,7 @@

    Simulate Portfolio622 0001 10 -3 +1 0001 @@ -1184,7 +1187,7 @@

    Simulate Portfolio622 0001 11 -3 +1 0001 @@ -1197,7 +1200,7 @@

    Simulate Portfolio622 0001 12 -3 +1 0001 @@ -1210,7 +1213,7 @@

    Simulate Portfolio622 0001 13 -3 +1 0001 @@ -1223,7 +1226,7 @@

    Simulate Portfolio622 0001 14 -3 +1 0001 @@ -1236,7 +1239,7 @@

    Simulate Portfolio622 0001 15 -3 +1 0001 @@ -1249,7 +1252,7 @@

    Simulate Portfolio622 0001 16 -3 +1 0001 @@ -1262,7 +1265,7 @@

    Simulate Portfolio622 0001 17 -3 +1 0001 @@ -1275,7 +1278,7 @@

    Simulate Portfolio622 0001 18 -3 +1 0001 @@ -1288,7 +1291,7 @@

    Simulate Portfolio622 0001 19 -3 +1 0001 @@ -1301,7 +1304,7 @@

    Simulate Portfolio622 0001 20 -3 +2 0001 @@ -1327,7 +1330,7 @@

    Simulate Portfolio622 0002 1 -1 +0 0001 @@ -1340,7 +1343,7 @@

    Simulate Portfolio622 0002 2 -1 +0 0001 @@ -1353,7 +1356,7 @@

    Simulate Portfolio622 0002 3 -1 +0 0001 @@ -1366,7 +1369,7 @@

    Simulate Portfolio622 0002 4 -1 +0 @@ -2357,7 +2360,7 @@

    Performance Under Optimal Conditio ## 8 0 8 <tibble [3,869 × 8]> ## 9 0 9 <tibble [3,884 × 8]> ## 10 0 10 <tibble [3,884 × 8]> -## # … with 2,990 more rows +## # ℹ 2,990 more rows
     df_visit <- df_data_grid %>%
       mutate(
    @@ -4407,17 +4410,17 @@ 

    Heuristic Rank## # A tibble: 15,674 × 6 ## study_id site_number visit n_ae ae_per_visit ls_study_ae_per_visit ## <chr> <chr> <int> <int> <dbl> <list> -## 1 0001 0001 44 8 0.182 <dbl [43]> -## 2 0001 0002 49 18 0.367 <dbl [43]> -## 3 0001 0003 74 17 0.230 <dbl [43]> -## 4 0001 0004 191 49 0.257 <dbl [43]> -## 5 0001 0005 30 9 0.3 <dbl [43]> -## 6 0001 0006 35 17 0.486 <dbl [43]> +## 1 0001 0001 42 10 0.238 <dbl [43]> +## 2 0001 0002 60 14 0.233 <dbl [43]> +## 3 0001 0003 78 25 0.321 <dbl [43]> +## 4 0001 0004 189 43 0.228 <dbl [43]> +## 5 0001 0005 30 7 0.233 <dbl [43]> +## 6 0001 0006 35 9 0.257 <dbl [43]> ## 7 0001 0007 36 9 0.25 <dbl [43]> -## 8 0001 0008 166 48 0.289 <dbl [43]> -## 9 0001 0009 40 14 0.35 <dbl [43]> -## 10 0001 0010 138 33 0.239 <dbl [43]> -## # … with 15,664 more rows

    +## 8 0001 0008 192 64 0.333 <dbl [43]> +## 9 0001 0009 40 8 0.2 <dbl [43]> +## 10 0001 0010 134 30 0.224 <dbl [43]> +## # ℹ 15,664 more rows

    We write a function that: - determines how many sites should be flagged in a study - pools ae_per_visit rates and ranks sites (using dense_rank()) - site gets flagged if the specific rank for a site is @@ -4472,11 +4475,11 @@

    Heuristic Rank## # A tibble: 6 × 3 ## ur_rate ae_per_visit is_ur ## <dbl> <dbl> <lgl> -## 1 0 0.182 FALSE -## 2 0.1 0.164 FALSE -## 3 0.25 0.136 TRUE -## 4 0.5 0.0909 TRUE -## 5 0.75 0.0455 TRUE +## 1 0 0.238 FALSE +## 2 0.1 0.214 FALSE +## 3 0.25 0.179 FALSE +## 4 0.5 0.119 TRUE +## 5 0.75 0.0595 TRUE ## 6 1 0 TRUE

    We apply.

    diff --git a/docs/articles/portfolio_perf_files/figure-html/check_portf-1.png b/docs/articles/portfolio_perf_files/figure-html/check_portf-1.png index 7c83be8..cf5e656 100644 Binary files a/docs/articles/portfolio_perf_files/figure-html/check_portf-1.png and b/docs/articles/portfolio_perf_files/figure-html/check_portf-1.png differ diff --git a/docs/articles/portfolio_perf_files/figure-html/check_portf-2.png b/docs/articles/portfolio_perf_files/figure-html/check_portf-2.png index 035efa5..4c0b353 100644 Binary files a/docs/articles/portfolio_perf_files/figure-html/check_portf-2.png and b/docs/articles/portfolio_perf_files/figure-html/check_portf-2.png differ diff --git a/docs/articles/portfolio_perf_files/figure-html/check_portf_2-1.png b/docs/articles/portfolio_perf_files/figure-html/check_portf_2-1.png index de43818..bceaaf8 100644 Binary files a/docs/articles/portfolio_perf_files/figure-html/check_portf_2-1.png and b/docs/articles/portfolio_perf_files/figure-html/check_portf_2-1.png differ diff --git a/docs/articles/portfolio_perf_files/figure-html/check_portf_2-2.png b/docs/articles/portfolio_perf_files/figure-html/check_portf_2-2.png index a812251..4837d33 100644 Binary files a/docs/articles/portfolio_perf_files/figure-html/check_portf_2-2.png and b/docs/articles/portfolio_perf_files/figure-html/check_portf_2-2.png differ diff --git a/docs/articles/sas_files.html b/docs/articles/sas_files.html index f30e11b..ae70dd8 100644 --- a/docs/articles/sas_files.html +++ b/docs/articles/sas_files.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4

    @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -165,7 +168,7 @@

    SAS files## 8 CO-101-001 01001001 001 99 ## 9 CO-101-001 01001001 001 127 ## 10 CO-101-001 01001001 001 127 -## # … with 4,692 more rows +## # ℹ 4,692 more rows
     df_vs <- haven::read_sas('advs.sas7bdat') %>%
       select(STUDYID, SUBJID, SITEID, ADY) 
    @@ -184,7 +187,7 @@ 

    SAS files## 8 CO-101-001 01001001 001 29 ## 9 CO-101-001 01001001 001 29 ## 10 CO-101-001 01001001 001 38 -## # … with 45,166 more rows

    +## # ℹ 45,166 more rows

    In order to assign each AE to a visit we union both event tables and sort by date.

    @@ -797,7 +800,7 @@ 

    {simaerep}## 8 CO-101-001 001 01001001 3 8 ## 9 CO-101-001 001 01001001 3 9 ## 10 CO-101-001 001 01001001 6 10 -## # … with 5,422 more rows

    +## # ℹ 5,422 more rows
     aerep <- simaerep(df_visit)
     
    @@ -835,7 +838,7 @@ 

    {simaerep}

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/usability_limits.html b/docs/articles/usability_limits.html index dfc75e1..45122c0 100644 --- a/docs/articles/usability_limits.html +++ b/docs/articles/usability_limits.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4
    @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -553,7 +556,7 @@

    Conclusion

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/visit_med75.html b/docs/articles/visit_med75.html index 30c8979..9779a79 100644 --- a/docs/articles/visit_med75.html +++ b/docs/articles/visit_med75.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -262,7 +265,7 @@

    Early Starters

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/articles/visits_or_days.html b/docs/articles/visits_or_days.html index c1b0568..0a3940c 100644 --- a/docs/articles/visits_or_days.html +++ b/docs/articles/visits_or_days.html @@ -46,7 +46,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -92,6 +92,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -297,7 +300,7 @@

    Aggregate on Days## 8 CO-101-001 001 01001001 184 10 ## 9 CO-101-001 001 01001001 240 13 ## 10 CO-101-001 001 01001001 241 14 -## # … with 3,210 more rows +## # ℹ 3,210 more rows

    We do have gaps in between the days leading to implicitly missing values. simaerep will correct this automatically and throw a warning.

    @@ -327,7 +330,7 @@

    Aggregate on Days## 8 CO-101-001 001 01001001 12 0 ## 9 CO-101-001 001 01001001 13 0 ## 10 CO-101-001 001 01001001 14 0 -## # … with 57,863 more rows +## # ℹ 57,863 more rows

    Then we proceed as usual.

     df_sim_sites <- sim_sites(df_site, df_visit = df_days)
    @@ -530,7 +533,7 @@ 

    Compare

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/authors.html b/docs/authors.html index f05bf46..3a3a274 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -108,15 +111,16 @@

    Citation

    -

    Koneswarakantha B (2023). +

    Koneswarakantha B (2024). simaerep: Find Clinical Trial Sites Under-Reporting Adverse Events. -https://openpharma.github.io/simaerep/, https://github.com/openpharma/simaerep. +R package version 0.4.4, https://github.com/openpharma/simaerep, https://openpharma.github.io/simaerep/.

    @Manual{,
       title = {simaerep: Find Clinical Trial Sites Under-Reporting Adverse Events},
       author = {Bjoern Koneswarakantha},
    -  year = {2023},
    -  note = {https://openpharma.github.io/simaerep/, https://github.com/openpharma/simaerep},
    +  year = {2024},
    +  note = {R package version 0.4.4, https://github.com/openpharma/simaerep},
    +  url = {https://openpharma.github.io/simaerep/},
     }
    @@ -130,7 +134,7 @@

    Citation

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/index.html b/docs/index.html index 2516384..373fddb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -96,6 +96,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • @@ -392,12 +395,7 @@

    Application aerep <- simaerep(df_visit) -plot(aerep, study = "A") -#> Warning: `all_equal()` was deprecated in dplyr 1.1.0. -#> ℹ Please use `all.equal()` instead. -#> ℹ And manually order the rows/cols as needed -#> ℹ The deprecated feature was likely used in the simaerep package. -#> Please report the issue to the authors. +plot(aerep, study = "A")

    Left panel shows mean AE reporting per site (lightblue and darkblue lines) against mean AE reporting of the entire study (golden line). Single sites are plotted in descending order by AE under-reporting probability on the right panel in which grey lines denote cumulative AE count of single patients. Grey dots in the left panel plot indicate sites that were picked for single plotting. AE under-reporting probability of dark blue lines crossed threshold of 95%. Numbers in the upper left corner indicate the ratio of patients that have been used for the analysis against the total number of patients. Patients that have not been on the study long enough to reach the evaluation point (visit_med75, see introduction) will be ignored.

    @@ -459,7 +457,7 @@

    Dev status

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/news/index.html b/docs/news/index.html index 827a262..d19c200 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -91,8 +94,14 @@

    Changelog

    - -
    +
    + +
    @@ -146,7 +155,7 @@
    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 1670938..746a6e3 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,15 +1,16 @@ -pandoc: 3.0.1 -pkgdown: 2.0.5 +pandoc: 3.1.1 +pkgdown: 2.0.7 pkgdown_sha: ~ articles: check_poisson: check_poisson.html + gsm_perf: gsm_perf.html intro: intro.html portfolio_perf: portfolio_perf.html sas_files: sas_files.html usability_limits: usability_limits.html visit_med75: visit_med75.html visits_or_days: visits_or_days.html -last_built: 2023-02-28T09:05Z +last_built: 2024-02-22T10:42Z urls: reference: https://openpharma.github.io/simaerep/reference article: https://openpharma.github.io/simaerep/articles diff --git a/docs/reference/aggr_duplicated_visits.html b/docs/reference/aggr_duplicated_visits.html index 48f1dff..572dbec 100644 --- a/docs/reference/aggr_duplicated_visits.html +++ b/docs/reference/aggr_duplicated_visits.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -125,7 +128,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/check_df_visit.html b/docs/reference/check_df_visit.html index 674d749..82c9bed 100644 --- a/docs/reference/check_df_visit.html +++ b/docs/reference/check_df_visit.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -158,7 +161,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/eval_sites.html b/docs/reference/eval_sites.html index 3526a30..5feb20f 100644 --- a/docs/reference/eval_sites.html +++ b/docs/reference/eval_sites.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -174,36 +177,34 @@

    Examples

    df_eval <- eval_sites(df_sim_sites) df_eval #> # A tibble: 5 × 14 -#> study_id site_…¹ n_pat n_pat…² visit…³ mean_…⁴ mean_…⁵ n_pat…⁶ pval prob_…⁷ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 A S0002 20 17 15 3 6.48 69 1.43e-8 0 -#> 2 A S0001 20 16 15 2.94 6.44 70 1.84e-8 0 -#> 3 A S0003 20 18 16 8.06 5.80 64 1 e+0 1 -#> 4 A S0004 20 19 16 7.63 5.89 63 1 e+0 1 -#> 5 A S0005 20 16 15 8.38 5.2 70 1 e+0 1 -#> # … with 4 more variables: pval_adj <dbl>, pval_prob_ur <dbl>, -#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl>, and abbreviated variable names -#> # ¹​site_number, ²​n_pat_with_med75, ³​visit_med75, ⁴​mean_ae_site_med75, -#> # ⁵​mean_ae_study_med75, ⁶​n_pat_with_med75_study, ⁷​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0002 20 16 16 2.75 +#> 2 A S0001 20 16 15 2.62 +#> 3 A S0003 20 19 15 6.37 +#> 4 A S0004 20 16 16 7.81 +#> 5 A S0005 20 17 16 8.59 +#> # ℹ 8 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # pval <dbl>, prob_low <dbl>, pval_adj <dbl>, pval_prob_ur <dbl>, +#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl> # use deprecated method ------- df_eval <- eval_sites(df_sim_sites, method = NULL, r_sim_sites = 100) #> Warning: using deprecated method for probability adjustment df_eval #> # A tibble: 5 × 19 -#> study_id site_…¹ n_pat n_pat…² visit…³ mean_…⁴ mean_…⁵ n_pat…⁶ pval prob_…⁷ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 A S0002 20 17 15 3 6.48 69 1.43e-8 0 -#> 2 A S0001 20 16 15 2.94 6.44 70 1.84e-8 0 -#> 3 A S0003 20 18 16 8.06 5.80 64 1 e+0 1 -#> 4 A S0004 20 19 16 7.63 5.89 63 1 e+0 1 -#> 5 A S0005 20 16 15 8.38 5.2 70 1 e+0 1 -#> # … with 9 more variables: n_site <int>, pval_n_detected <int>, pval_fp <dbl>, -#> # pval_p_vs_fp_ratio <dbl>, pval_prob_ur <dbl>, prob_low_n_detected <int>, -#> # prob_low_fp <dbl>, prob_low_p_vs_fp_ratio <dbl>, prob_low_prob_ur <dbl>, -#> # and abbreviated variable names ¹​site_number, ²​n_pat_with_med75, -#> # ³​visit_med75, ⁴​mean_ae_site_med75, ⁵​mean_ae_study_med75, -#> # ⁶​n_pat_with_med75_study, ⁷​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0002 20 16 16 2.75 +#> 2 A S0001 20 16 15 2.62 +#> 3 A S0003 20 19 15 6.37 +#> 4 A S0004 20 16 16 7.81 +#> 5 A S0005 20 17 16 8.59 +#> # ℹ 13 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # pval <dbl>, prob_low <dbl>, n_site <int>, pval_n_detected <int>, +#> # pval_fp <dbl>, pval_p_vs_fp_ratio <dbl>, pval_prob_ur <dbl>, +#> # prob_low_n_detected <int>, prob_low_fp <dbl>, prob_low_p_vs_fp_ratio <dbl>, +#> # prob_low_prob_ur <dbl> @@ -218,7 +219,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/eval_sites_deprecated.html b/docs/reference/eval_sites_deprecated.html index eff3395..f4e8b5e 100644 --- a/docs/reference/eval_sites_deprecated.html +++ b/docs/reference/eval_sites_deprecated.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -192,19 +195,18 @@

    Examples

    df_eval <- eval_sites_deprecated(df_sim_sites, r_sim_sites = 100) df_eval #> # A tibble: 5 × 19 -#> study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷ pval prob_…⁸ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 A S0001 20 20 16 3.25 7.18 68 5.77e-11 0 -#> 2 A S0002 20 17 18 3.88 7.81 58 1.20e- 8 0 -#> 3 A S0003 20 18 17 10 5.78 64 1 e+ 0 1 -#> 4 A S0004 20 18 14 7.39 5.01 76 1 e+ 0 1 -#> 5 A S0005 20 18 15 7.28 5.51 72 1 e+ 0 1 -#> # … with 9 more variables: n_site <int>, pval_n_detected <int>, pval_fp <dbl>, -#> # pval_p_vs_fp_ratio <dbl>, pval_prob_ur <dbl>, prob_low_n_detected <int>, -#> # prob_low_fp <dbl>, prob_low_p_vs_fp_ratio <dbl>, prob_low_prob_ur <dbl>, -#> # and abbreviated variable names ¹​study_id, ²​site_number, ³​n_pat_with_med75, -#> # ⁴​visit_med75, ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, -#> # ⁷​n_pat_with_med75_study, ⁸​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0002 20 17 18 3.94 +#> 2 A S0001 20 18 16 3.39 +#> 3 A S0003 20 18 17 10.2 +#> 4 A S0004 20 18 14 7.28 +#> 5 A S0005 20 17 15 7.29 +#> # ℹ 13 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # pval <dbl>, prob_low <dbl>, n_site <int>, pval_n_detected <int>, +#> # pval_fp <dbl>, pval_p_vs_fp_ratio <dbl>, pval_prob_ur <dbl>, +#> # prob_low_n_detected <int>, prob_low_fp <dbl>, prob_low_p_vs_fp_ratio <dbl>, +#> # prob_low_prob_ur <dbl> @@ -219,7 +221,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/exp_implicit_missing_visits.html b/docs/reference/exp_implicit_missing_visits.html index 54f04cc..89364c5 100644 --- a/docs/reference/exp_implicit_missing_visits.html +++ b/docs/reference/exp_implicit_missing_visits.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -125,7 +128,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/figures/README-unnamed-chunk-2-1.png b/docs/reference/figures/README-unnamed-chunk-2-1.png index ca2b821..c95aec5 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-2-1.png and b/docs/reference/figures/README-unnamed-chunk-2-1.png differ diff --git a/docs/reference/get_config.html b/docs/reference/get_config.html index fd3510f..ca36e64 100644 --- a/docs/reference/get_config.html +++ b/docs/reference/get_config.html @@ -27,7 +27,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -71,6 +71,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -193,45 +196,45 @@

    Examples

    #> # A tibble: 20 × 6 #> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean n_pat #> <chr> <dbl> <chr> <dbl> <dbl> <int> -#> 1 0001 0.401 0001 3.41 20.1 10 -#> 2 0001 0.401 0002 2.33 21.1 10 -#> 3 0001 0.401 0003 3.97 20.2 10 -#> 4 0001 0.401 0004 3.30 21.3 10 -#> 5 0001 0.401 0005 4.25 20.9 10 -#> 6 0001 0.401 0006 4.50 19.5 10 -#> 7 0001 0.401 0007 3.92 17.3 10 -#> 8 0001 0.401 0008 4.76 19.7 10 -#> 9 0001 0.401 0009 4.40 19.3 10 -#> 10 0001 0.401 0010 4.27 19.3 10 -#> 11 0002 0.487 0001 2.99 20.4 10 -#> 12 0002 0.487 0002 4.30 19.7 10 -#> 13 0002 0.487 0003 2.49 19.8 10 -#> 14 0002 0.487 0004 5.32 19.4 10 -#> 15 0002 0.487 0005 3.77 19.3 10 -#> 16 0002 0.487 0006 5.44 19.7 10 -#> 17 0002 0.487 0007 4.72 19.5 10 -#> 18 0002 0.487 0008 4.10 20.8 10 -#> 19 0002 0.487 0009 3.88 17.8 10 -#> 20 0002 0.487 0010 3.89 18.3 10 +#> 1 0001 0.400 0001 4.61 18.8 10 +#> 2 0001 0.400 0002 3.78 19.4 10 +#> 3 0001 0.400 0003 3.28 20.1 10 +#> 4 0001 0.400 0004 4.84 19.4 10 +#> 5 0001 0.400 0005 4.30 21.6 10 +#> 6 0001 0.400 0006 4.18 19.1 10 +#> 7 0001 0.400 0007 4.06 17.5 10 +#> 8 0001 0.400 0008 4.10 20.8 10 +#> 9 0001 0.400 0009 4.74 18.5 10 +#> 10 0001 0.400 0010 4.30 18.6 10 +#> 11 0002 0.487 0001 3.10 20.6 10 +#> 12 0002 0.487 0002 2.75 20 10 +#> 13 0002 0.487 0003 3.71 19.2 10 +#> 14 0002 0.487 0004 5.34 20.4 10 +#> 15 0002 0.487 0005 3.84 18.5 10 +#> 16 0002 0.487 0006 4.35 19.4 10 +#> 17 0002 0.487 0007 5.48 19.4 10 +#> 18 0002 0.487 0008 3.62 22 10 +#> 19 0002 0.487 0009 4.00 17.7 10 +#> 20 0002 0.487 0010 2.60 19.1 10 df_portf <- sim_test_data_portfolio(df_config) df_portf -#> # A tibble: 3,829 × 8 -#> study_id ae_per_visit_mean site_number max_visit…¹ max_v…² patnum visit n_ae -#> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int> <int> -#> 1 0001 0.401 0001 3.41 20.1 0001 1 0 -#> 2 0001 0.401 0001 3.41 20.1 0001 2 0 -#> 3 0001 0.401 0001 3.41 20.1 0001 3 2 -#> 4 0001 0.401 0001 3.41 20.1 0001 4 2 -#> 5 0001 0.401 0001 3.41 20.1 0001 5 2 -#> 6 0001 0.401 0001 3.41 20.1 0001 6 2 -#> 7 0001 0.401 0001 3.41 20.1 0001 7 2 -#> 8 0001 0.401 0001 3.41 20.1 0001 8 3 -#> 9 0001 0.401 0001 3.41 20.1 0001 9 3 -#> 10 0001 0.401 0001 3.41 20.1 0001 10 3 -#> # … with 3,819 more rows, and abbreviated variable names ¹​max_visit_sd, -#> # ²​max_visit_mean +#> # A tibble: 3,792 × 8 +#> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean patnum +#> <chr> <dbl> <chr> <dbl> <dbl> <chr> +#> 1 0001 0.400 0001 4.61 18.8 0001 +#> 2 0001 0.400 0001 4.61 18.8 0001 +#> 3 0001 0.400 0001 4.61 18.8 0001 +#> 4 0001 0.400 0001 4.61 18.8 0001 +#> 5 0001 0.400 0001 4.61 18.8 0001 +#> 6 0001 0.400 0001 4.61 18.8 0001 +#> 7 0001 0.400 0001 4.61 18.8 0001 +#> 8 0001 0.400 0001 4.61 18.8 0001 +#> 9 0001 0.400 0001 4.61 18.8 0001 +#> 10 0001 0.400 0001 4.61 18.8 0001 +#> # ℹ 3,782 more rows +#> # ℹ 2 more variables: visit <int>, n_ae <int> df_scen <- sim_ur_scenarios(df_portf, extra_ur_sites = 2, @@ -245,23 +248,22 @@

    Examples

    df_scen #> # A tibble: 140 × 14 -#> study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷ extra…⁸ frac_…⁹ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 0001 0001 10 10 15 5.8 5.87 78 0 0 -#> 2 0001 0001 10 10 15 2.9 5.87 78 0 0.114 -#> 3 0001 0001 10 10 15 0 5.87 78 0 0.114 -#> 4 0001 0001 10 10 15 2.9 5.53 78 1 0.214 -#> 5 0001 0001 10 10 15 0 5.18 78 1 0.214 -#> 6 0001 0001 10 10 15 2.9 5.25 78 2 0.314 -#> 7 0001 0001 10 10 15 0 4.63 78 2 0.314 -#> 8 0001 0002 10 10 17 7.1 6.46 65 0 0 -#> 9 0001 0002 10 10 17 3.55 6.46 65 0 0.133 -#> 10 0001 0002 10 10 17 0 6.46 65 0 0.133 -#> # … with 130 more rows, 4 more variables: ur_rate <dbl>, prob_low <dbl>, -#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl>, and abbreviated variable names -#> # ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75, -#> # ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study, -#> # ⁸​extra_ur_sites, ⁹​frac_pat_with_ur +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 0001 0001 10 9 14 5.78 +#> 2 0001 0001 10 9 14 2.89 +#> 3 0001 0001 10 9 14 0 +#> 4 0001 0001 10 9 14 2.89 +#> 5 0001 0001 10 9 14 0 +#> 6 0001 0001 10 9 14 2.89 +#> 7 0001 0001 10 9 14 0 +#> 8 0001 0002 10 9 15 5.78 +#> 9 0001 0002 10 9 15 2.89 +#> 10 0001 0002 10 9 15 0 +#> # ℹ 130 more rows +#> # ℹ 8 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # extra_ur_sites <dbl>, frac_pat_with_ur <dbl>, ur_rate <dbl>, +#> # prob_low <dbl>, prob_low_adj <dbl>, prob_low_prob_ur <dbl> df_perf <- get_portf_perf(df_scen) @@ -269,17 +271,17 @@

    Examples

    #> # A tibble: 27 × 5 #> fpr thresh extra_ur_sites ur_rate tpr #> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 0.001 0.922 0 0 0.05 -#> 2 0.001 0.922 1 0 0.05 -#> 3 0.001 0.922 2 0 0.05 -#> 4 0.001 0.922 0 0.5 1 -#> 5 0.001 0.922 1 0.5 1 -#> 6 0.001 0.922 2 0.5 1 -#> 7 0.001 0.922 0 1 1 -#> 8 0.001 0.922 1 1 1 -#> 9 0.001 0.922 2 1 1 -#> 10 0.01 0.909 0 0 0.05 -#> # … with 17 more rows +#> 1 0.001 0.925 0 0 0.05 +#> 2 0.001 0.925 1 0 0.05 +#> 3 0.001 0.925 2 0 0.05 +#> 4 0.001 0.925 0 0.5 1 +#> 5 0.001 0.925 1 0.5 1 +#> 6 0.001 0.925 2 0.5 1 +#> 7 0.001 0.925 0 1 1 +#> 8 0.001 0.925 1 1 1 +#> 9 0.001 0.925 2 1 1 +#> 10 0.01 0.920 0 0 0.05 +#> # ℹ 17 more rows # } @@ -295,7 +297,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/get_ecd_values.html b/docs/reference/get_ecd_values.html index 5615a4f..37f1a98 100644 --- a/docs/reference/get_ecd_values.html +++ b/docs/reference/get_ecd_values.html @@ -27,7 +27,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -71,6 +71,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -172,28 +175,26 @@

    Examples

    get_ecd_values(df_sim_studies, df_sim_sites, "prob_low") #> # A tibble: 5 × 11 -#> study_id site_…¹ n_pat n_pat…² visit…³ mean_…⁴ mean_…⁵ n_pat…⁶ pval prob_…⁷ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 A S0001 20 18 17 5.89 7.78 59 0.00966 0.02 -#> 2 A S0002 20 18 15 5.5 6.85 72 0.0452 0.04 -#> 3 A S0003 20 17 16 8.53 6.70 66 1 1 -#> 4 A S0004 20 20 15 6.4 6.63 70 0.767 0.39 -#> 5 A S0005 20 16 16 8.38 6.76 67 1 1 -#> # … with 1 more variable: prob_low_ecd <dbl>, and abbreviated variable names -#> # ¹​site_number, ²​n_pat_with_med75, ³​visit_med75, ⁴​mean_ae_site_med75, -#> # ⁵​mean_ae_study_med75, ⁶​n_pat_with_med75_study, ⁷​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0001 20 18 17 5.89 +#> 2 A S0002 20 18 15 5.5 +#> 3 A S0003 20 17 16 8.53 +#> 4 A S0004 20 20 15 6.4 +#> 5 A S0005 20 16 16 8.38 +#> # ℹ 5 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # pval <dbl>, prob_low <dbl>, prob_low_ecd <dbl> get_ecd_values(df_sim_studies, df_sim_sites, "pval") #> # A tibble: 5 × 11 -#> study_id site_…¹ n_pat n_pat…² visit…³ mean_…⁴ mean_…⁵ n_pat…⁶ pval prob_…⁷ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 A S0001 20 18 17 5.89 7.78 59 0.00966 0.02 -#> 2 A S0002 20 18 15 5.5 6.85 72 0.0452 0.04 -#> 3 A S0003 20 17 16 8.53 6.70 66 1 1 -#> 4 A S0004 20 20 15 6.4 6.63 70 0.767 0.39 -#> 5 A S0005 20 16 16 8.38 6.76 67 1 1 -#> # … with 1 more variable: pval_ecd <dbl>, and abbreviated variable names -#> # ¹​site_number, ²​n_pat_with_med75, ³​visit_med75, ⁴​mean_ae_site_med75, -#> # ⁵​mean_ae_study_med75, ⁶​n_pat_with_med75_study, ⁷​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0001 20 18 17 5.89 +#> 2 A S0002 20 18 15 5.5 +#> 3 A S0003 20 17 16 8.53 +#> 4 A S0004 20 20 15 6.4 +#> 5 A S0005 20 16 16 8.38 +#> # ℹ 5 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # pval <dbl>, prob_low <dbl>, pval_ecd <dbl> @@ -208,7 +209,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/get_pat_pool_config.html b/docs/reference/get_pat_pool_config.html index fa15af2..ea36347 100644 --- a/docs/reference/get_pat_pool_config.html +++ b/docs/reference/get_pat_pool_config.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -148,14 +151,14 @@

    Examples

    #> # A tibble: 8 × 6 #> study_id site_number visit_med75 n_pat_with_med75 n_pat_study pat_pool #> <chr> <chr> <dbl> <int> <dbl> <list> -#> 1 A S0001 15 19 71 <tibble> -#> 2 A S0002 15 18 72 <tibble> -#> 3 A S0003 16 17 66 <tibble> -#> 4 A S0004 15 20 70 <tibble> -#> 5 A S0005 16 16 67 <tibble> -#> 6 B S0001 15 302 602 <tibble> -#> 7 B S0002 15 301 603 <tibble> -#> 8 B S0003 15 301 603 <tibble> +#> 1 A S0001 15 19 71 <tibble> +#> 2 A S0002 15 18 72 <tibble> +#> 3 A S0003 16 17 66 <tibble> +#> 4 A S0004 15 20 70 <tibble> +#> 5 A S0005 16 16 67 <tibble> +#> 6 B S0001 15 302 602 <tibble> +#> 7 B S0002 15 301 603 <tibble> +#> 8 B S0003 15 301 603 <tibble> @@ -170,7 +173,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/get_portf_perf.html b/docs/reference/get_portf_perf.html index 38f78d3..487734c 100644 --- a/docs/reference/get_portf_perf.html +++ b/docs/reference/get_portf_perf.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -186,20 +189,20 @@

    Examples

    df_portf #> # A tibble: 3,896 × 8 -#> study_id ae_per_visit_mean site_number max_visit…¹ max_v…² patnum visit n_ae -#> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int> <int> -#> 1 0001 0.373 0001 3.79 19.2 0001 1 0 -#> 2 0001 0.373 0001 3.79 19.2 0001 2 1 -#> 3 0001 0.373 0001 3.79 19.2 0001 3 1 -#> 4 0001 0.373 0001 3.79 19.2 0001 4 1 -#> 5 0001 0.373 0001 3.79 19.2 0001 5 3 -#> 6 0001 0.373 0001 3.79 19.2 0001 6 4 -#> 7 0001 0.373 0001 3.79 19.2 0001 7 4 -#> 8 0001 0.373 0001 3.79 19.2 0001 8 4 -#> 9 0001 0.373 0001 3.79 19.2 0001 9 4 -#> 10 0001 0.373 0001 3.79 19.2 0001 10 4 -#> # … with 3,886 more rows, and abbreviated variable names ¹​max_visit_sd, -#> # ²​max_visit_mean +#> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean patnum +#> <chr> <dbl> <chr> <dbl> <dbl> <chr> +#> 1 0001 0.373 0001 3.79 19.2 0001 +#> 2 0001 0.373 0001 3.79 19.2 0001 +#> 3 0001 0.373 0001 3.79 19.2 0001 +#> 4 0001 0.373 0001 3.79 19.2 0001 +#> 5 0001 0.373 0001 3.79 19.2 0001 +#> 6 0001 0.373 0001 3.79 19.2 0001 +#> 7 0001 0.373 0001 3.79 19.2 0001 +#> 8 0001 0.373 0001 3.79 19.2 0001 +#> 9 0001 0.373 0001 3.79 19.2 0001 +#> 10 0001 0.373 0001 3.79 19.2 0001 +#> # ℹ 3,886 more rows +#> # ℹ 2 more variables: visit <int>, n_ae <int> df_scen <- sim_ur_scenarios(df_portf, extra_ur_sites = 2, @@ -213,23 +216,22 @@

    Examples

    df_scen #> # A tibble: 140 × 14 -#> study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷ extra…⁸ frac_…⁹ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 0001 0001 10 10 15 5.1 5.06 80 0 0 -#> 2 0001 0001 10 10 15 2.55 5.06 80 0 0.111 -#> 3 0001 0001 10 10 15 0 5.06 80 0 0.111 -#> 4 0001 0001 10 10 15 2.55 4.7 80 1 0.211 -#> 5 0001 0001 10 10 15 0 4.34 80 1 0.211 -#> 6 0001 0001 10 10 15 2.55 4.43 80 2 0.311 -#> 7 0001 0001 10 10 15 0 3.8 80 2 0.311 -#> 8 0001 0002 10 10 16 6.5 5.34 73 0 0 -#> 9 0001 0002 10 10 16 3.25 5.34 73 0 0.120 -#> 10 0001 0002 10 10 16 0 5.34 73 0 0.120 -#> # … with 130 more rows, 4 more variables: ur_rate <dbl>, prob_low <dbl>, -#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl>, and abbreviated variable names -#> # ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75, -#> # ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study, -#> # ⁸​extra_ur_sites, ⁹​frac_pat_with_ur +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 0001 0001 10 10 15 5.1 +#> 2 0001 0001 10 10 15 2.55 +#> 3 0001 0001 10 10 15 0 +#> 4 0001 0001 10 10 15 2.55 +#> 5 0001 0001 10 10 15 0 +#> 6 0001 0001 10 10 15 2.55 +#> 7 0001 0001 10 10 15 0 +#> 8 0001 0002 10 10 16 6.5 +#> 9 0001 0002 10 10 16 3.25 +#> 10 0001 0002 10 10 16 0 +#> # ℹ 130 more rows +#> # ℹ 8 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # extra_ur_sites <dbl>, frac_pat_with_ur <dbl>, ur_rate <dbl>, +#> # prob_low <dbl>, prob_low_adj <dbl>, prob_low_prob_ur <dbl> df_perf <- get_portf_perf(df_scen) @@ -247,7 +249,7 @@

    Examples

    #> 8 0.001 0.983 1 1 1 #> 9 0.001 0.983 2 1 1 #> 10 0.01 0.963 0 0 0.05 -#> # … with 17 more rows +#> # ℹ 17 more rows # } @@ -263,7 +265,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/get_site_mean_ae_dev.html b/docs/reference/get_site_mean_ae_dev.html index e148b80..8fd1127 100644 --- a/docs/reference/get_site_mean_ae_dev.html +++ b/docs/reference/get_site_mean_ae_dev.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -134,7 +137,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/get_visit_med75.html b/docs/reference/get_visit_med75.html index 6106956..07dd3de 100644 --- a/docs/reference/get_visit_med75.html +++ b/docs/reference/get_visit_med75.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -134,7 +137,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/index.html b/docs/reference/index.html index 1206199..56a2716 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -279,7 +282,7 @@

    Additional Plot Functions -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/is_orivisit.html b/docs/reference/is_orivisit.html index 8d7235d..e84811d 100644 --- a/docs/reference/is_orivisit.html +++ b/docs/reference/is_orivisit.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -124,7 +127,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/is_simaerep.html b/docs/reference/is_simaerep.html index 115a25a..21030e7 100644 --- a/docs/reference/is_simaerep.html +++ b/docs/reference/is_simaerep.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -124,7 +127,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/orivisit.html b/docs/reference/orivisit.html index 5f3bca2..08d6e14 100644 --- a/docs/reference/orivisit.html +++ b/docs/reference/orivisit.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -148,26 +151,21 @@

    Examples

    #> 2288 bytes as.data.frame(visit) -#> Warning: `all_equal()` was deprecated in dplyr 1.1.0. -#> Please use `all.equal()` instead. -#> And manually order the rows/cols as needed -#> The deprecated feature was likely used in the simaerep package. -#> Please report the issue to the authors. #> # A tibble: 1,970 × 9 -#> patnum site_number is_ur max_visit_mean max_vi…¹ ae_pe…² visit n_ae study…³ -#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> <int> <chr> -#> 1 P000001 S0001 TRUE 20 4 0.2 1 0 A -#> 2 P000001 S0001 TRUE 20 4 0.2 2 0 A -#> 3 P000001 S0001 TRUE 20 4 0.2 3 0 A -#> 4 P000001 S0001 TRUE 20 4 0.2 4 0 A -#> 5 P000001 S0001 TRUE 20 4 0.2 5 0 A -#> 6 P000001 S0001 TRUE 20 4 0.2 6 0 A -#> 7 P000001 S0001 TRUE 20 4 0.2 7 0 A -#> 8 P000001 S0001 TRUE 20 4 0.2 8 0 A -#> 9 P000001 S0001 TRUE 20 4 0.2 9 0 A -#> 10 P000001 S0001 TRUE 20 4 0.2 10 0 A -#> # … with 1,960 more rows, and abbreviated variable names ¹​max_visit_sd, -#> # ²​ae_per_visit_mean, ³​study_id +#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_visit_mean visit +#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> +#> 1 P000001 S0001 TRUE 20 4 0.2 1 +#> 2 P000001 S0001 TRUE 20 4 0.2 2 +#> 3 P000001 S0001 TRUE 20 4 0.2 3 +#> 4 P000001 S0001 TRUE 20 4 0.2 4 +#> 5 P000001 S0001 TRUE 20 4 0.2 5 +#> 6 P000001 S0001 TRUE 20 4 0.2 6 +#> 7 P000001 S0001 TRUE 20 4 0.2 7 +#> 8 P000001 S0001 TRUE 20 4 0.2 8 +#> 9 P000001 S0001 TRUE 20 4 0.2 9 +#> 10 P000001 S0001 TRUE 20 4 0.2 10 +#> # ℹ 1,960 more rows +#> # ℹ 2 more variables: n_ae <int>, study_id <chr> @@ -183,7 +181,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/pat_aggr.html b/docs/reference/pat_aggr.html index 6edb543..77dff76 100644 --- a/docs/reference/pat_aggr.html +++ b/docs/reference/pat_aggr.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -126,7 +129,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/pat_pool.html b/docs/reference/pat_pool.html index ebc03af..3d76bd2 100644 --- a/docs/reference/pat_pool.html +++ b/docs/reference/pat_pool.html @@ -26,7 +26,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -70,6 +70,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -156,7 +159,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 79834a7..f659821 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -118,7 +121,7 @@

    Value

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot.simaerep.html b/docs/reference/plot.simaerep.html index 4ae2d50..01e9071 100644 --- a/docs/reference/plot.simaerep.html +++ b/docs/reference/plot.simaerep.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -194,7 +197,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot_dots.html b/docs/reference/plot_dots.html index 83eb9e6..be488bd 100644 --- a/docs/reference/plot_dots.html +++ b/docs/reference/plot_dots.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -189,7 +192,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot_sim_example.html b/docs/reference/plot_sim_example.html index 10ac0c3..3355495 100644 --- a/docs/reference/plot_sim_example.html +++ b/docs/reference/plot_sim_example.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -193,7 +196,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot_sim_examples.html b/docs/reference/plot_sim_examples.html index 84e87ae..d488552 100644 --- a/docs/reference/plot_sim_examples.html +++ b/docs/reference/plot_sim_examples.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -146,7 +149,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot_study.html b/docs/reference/plot_study.html index 5b038ec..efce2d1 100644 --- a/docs/reference/plot_study.html +++ b/docs/reference/plot_study.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -188,7 +191,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/plot_visit_med75.html b/docs/reference/plot_visit_med75.html index 43a9e5d..8d64433 100644 --- a/docs/reference/plot_visit_med75.html +++ b/docs/reference/plot_visit_med75.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -173,7 +176,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/poiss_test_site_ae_vs_study_ae.html b/docs/reference/poiss_test_site_ae_vs_study_ae.html index 3da9efd..273b862 100644 --- a/docs/reference/poiss_test_site_ae_vs_study_ae.html +++ b/docs/reference/poiss_test_site_ae_vs_study_ae.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -157,7 +160,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/prep_for_sim.html b/docs/reference/prep_for_sim.html index e049270..9ba0ada 100644 --- a/docs/reference/prep_for_sim.html +++ b/docs/reference/prep_for_sim.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -161,7 +164,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/prob_lower_site_ae_vs_study_ae.html b/docs/reference/prob_lower_site_ae_vs_study_ae.html index 0abc53f..c605d2b 100644 --- a/docs/reference/prob_lower_site_ae_vs_study_ae.html +++ b/docs/reference/prob_lower_site_ae_vs_study_ae.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -154,7 +157,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/purrr_bar.html b/docs/reference/purrr_bar.html index ee6d273..d827235 100644 --- a/docs/reference/purrr_bar.html +++ b/docs/reference/purrr_bar.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -300,7 +303,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_after_prep.html b/docs/reference/sim_after_prep.html index 1bcd4de..796f668 100644 --- a/docs/reference/sim_after_prep.html +++ b/docs/reference/sim_after_prep.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -161,16 +164,15 @@

    Examples

    df_sim #> # A tibble: 5 × 9 -#> study_id site_number n_pat n_pat_wit…¹ visit…² mean_…³ mean_…⁴ n_pat…⁵ prob_…⁶ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> -#> 1 A S0001 20 20 15 6.1 6.96 72 0.118 -#> 2 A S0002 20 17 16 6.53 7.43 67 0.132 -#> 3 A S0003 20 17 16 8.35 6.97 67 1 -#> 4 A S0004 20 20 15 6.55 6.83 72 0.353 -#> 5 A S0005 20 16 15 7.62 6.59 76 1 -#> # … with abbreviated variable names ¹​n_pat_with_med75, ²​visit_med75, -#> # ³​mean_ae_site_med75, ⁴​mean_ae_study_med75, ⁵​n_pat_with_med75_study, -#> # ⁶​prob_low +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 A S0001 20 20 15 6.1 +#> 2 A S0002 20 17 16 6.53 +#> 3 A S0003 20 17 16 8.35 +#> 4 A S0004 20 20 15 6.55 +#> 5 A S0005 20 16 15 7.62 +#> # ℹ 3 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # prob_low <dbl> @@ -185,7 +187,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_scenario.html b/docs/reference/sim_scenario.html index 8826f2e..267e268 100644 --- a/docs/reference/sim_scenario.html +++ b/docs/reference/sim_scenario.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -182,7 +185,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_sites.html b/docs/reference/sim_sites.html index 1789f96..bac4a86 100644 --- a/docs/reference/sim_sites.html +++ b/docs/reference/sim_sites.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -230,7 +233,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_studies.html b/docs/reference/sim_studies.html index dea6693..853bade 100644 --- a/docs/reference/sim_studies.html +++ b/docs/reference/sim_studies.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -201,21 +204,20 @@

    Examples

    sim_studies(df_visit, df_site, r = 3, keep_ae = TRUE) #> # A tibble: 24 × 10 -#> r study_id site_n…¹ visit…² n_pat…³ n_pat…⁴ n_ae_…⁵ n_ae_…⁶ pval prob_…⁷ -#> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr> <chr> <dbl> <dbl> -#> 1 1 A S0001 16 20 68 7,13,7… 5,4,1,… 1 1 -#> 2 1 A S0002 18 17 57 1,10,4… 6,16,7… 1 1 -#> 3 1 A S0003 17 18 63 13,11,… 10,6,4… 1 1 -#> 4 1 A S0004 14 18 76 3,9,9,… 5,4,7,… 0.201 0.179 -#> 5 1 A S0005 15 18 72 9,4,7,… 9,13,4… 1 1 -#> 6 1 B S0001 15 297 597 9,8,5,… 6,11,4… 1 1 -#> 7 1 B S0002 15 296 598 14,8,7… 5,6,9,… 1 1 -#> 8 1 B S0003 15 301 593 9,5,8,… 9,7,7,… 1 0.526 -#> 9 2 A S0001 16 20 68 10,7,5… 2,6,3,… 1 1 -#> 10 2 A S0002 18 17 57 12,12,… 5,5,13… 1 1 -#> # … with 14 more rows, and abbreviated variable names ¹​site_number, -#> # ²​visit_med75, ³​n_pat_with_med75, ⁴​n_pat_study, ⁵​n_ae_site, ⁶​n_ae_study, -#> # ⁷​prob_low +#> r study_id site_number visit_med75 n_pat_with_med75 n_pat_study n_ae_site +#> <dbl> <chr> <chr> <dbl> <int> <dbl> <chr> +#> 1 1 A S0001 16 20 68 7,13,7,4… +#> 2 1 A S0002 18 17 57 1,10,4,4… +#> 3 1 A S0003 17 18 63 13,11,13… +#> 4 1 A S0004 14 18 76 3,9,9,9,… +#> 5 1 A S0005 15 18 72 9,4,7,6,… +#> 6 1 B S0001 15 297 597 9,8,5,7,… +#> 7 1 B S0002 15 296 598 14,8,7,1… +#> 8 1 B S0003 15 301 593 9,5,8,6,… +#> 9 2 A S0001 16 20 68 10,7,5,3… +#> 10 2 A S0002 18 17 57 12,12,6,… +#> # ℹ 14 more rows +#> # ℹ 3 more variables: n_ae_study <chr>, pval <dbl>, prob_low <dbl> # } if (FALSE) { # parallel processing ------------------------- @@ -238,7 +240,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_test_data_patient.html b/docs/reference/sim_test_data_patient.html index 2f61929..c2da37b 100644 --- a/docs/reference/sim_test_data_patient.html +++ b/docs/reference/sim_test_data_patient.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -195,7 +198,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_test_data_portfolio.html b/docs/reference/sim_test_data_portfolio.html index ec1978d..7b94b1f 100644 --- a/docs/reference/sim_test_data_portfolio.html +++ b/docs/reference/sim_test_data_portfolio.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -96,7 +99,12 @@

    Simulate Portfolio Test Data

    -
    sim_test_data_portfolio(df_config, parallel = FALSE, progress = TRUE)
    +
    sim_test_data_portfolio(
    +  df_config,
    +  df_ae_rates = NULL,
    +  parallel = FALSE,
    +  progress = TRUE
    +)
    @@ -105,6 +113,10 @@

    Arguments

    dataframe as returned by get_config

    +
    df_ae_rates
    +

    dataframe with ae rates. Default: NULL

    + +
    parallel

    logical activate parallel processing, see details, Default: FALSE

    @@ -211,20 +223,20 @@

    Examples

    df_portf #> # A tibble: 3,729 × 8 -#> study_id ae_per_visit_mean site_number max_visit…¹ max_v…² patnum visit n_ae -#> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int> <int> -#> 1 0001 0.355 0001 4.23 19.9 0001 1 1 -#> 2 0001 0.355 0001 4.23 19.9 0001 2 2 -#> 3 0001 0.355 0001 4.23 19.9 0001 3 2 -#> 4 0001 0.355 0001 4.23 19.9 0001 4 2 -#> 5 0001 0.355 0001 4.23 19.9 0001 5 2 -#> 6 0001 0.355 0001 4.23 19.9 0001 6 2 -#> 7 0001 0.355 0001 4.23 19.9 0001 7 2 -#> 8 0001 0.355 0001 4.23 19.9 0001 8 3 -#> 9 0001 0.355 0001 4.23 19.9 0001 9 3 -#> 10 0001 0.355 0001 4.23 19.9 0001 10 3 -#> # … with 3,719 more rows, and abbreviated variable names ¹​max_visit_sd, -#> # ²​max_visit_mean +#> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean patnum +#> <chr> <dbl> <chr> <dbl> <dbl> <chr> +#> 1 0001 0.355 0001 4.23 19.9 0001 +#> 2 0001 0.355 0001 4.23 19.9 0001 +#> 3 0001 0.355 0001 4.23 19.9 0001 +#> 4 0001 0.355 0001 4.23 19.9 0001 +#> 5 0001 0.355 0001 4.23 19.9 0001 +#> 6 0001 0.355 0001 4.23 19.9 0001 +#> 7 0001 0.355 0001 4.23 19.9 0001 +#> 8 0001 0.355 0001 4.23 19.9 0001 +#> 9 0001 0.355 0001 4.23 19.9 0001 +#> 10 0001 0.355 0001 4.23 19.9 0001 +#> # ℹ 3,719 more rows +#> # ℹ 2 more variables: visit <int>, n_ae <int> df_scen <- sim_ur_scenarios(df_portf, extra_ur_sites = 2, @@ -238,23 +250,22 @@

    Examples

    df_scen #> # A tibble: 140 × 14 -#> study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷ extra…⁸ frac_…⁹ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 0001 0001 10 8 21 6.25 7.75 28 0 0 -#> 2 0001 0001 10 8 21 3.12 7.75 28 0 0.222 -#> 3 0001 0001 10 8 21 0 7.75 28 0 0.222 -#> 4 0001 0001 10 8 21 3.12 7.30 28 1 0.333 -#> 5 0001 0001 10 8 21 0 6.86 28 1 0.333 -#> 6 0001 0001 10 8 21 3.12 6.79 28 2 0.444 -#> 7 0001 0001 10 8 21 0 5.82 28 2 0.444 -#> 8 0001 0002 10 10 14 3.8 4.74 74 0 0 -#> 9 0001 0002 10 10 14 1.9 4.74 74 0 0.119 -#> 10 0001 0002 10 10 14 0 4.74 74 0 0.119 -#> # … with 130 more rows, 4 more variables: ur_rate <dbl>, prob_low <dbl>, -#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl>, and abbreviated variable names -#> # ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75, -#> # ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study, -#> # ⁸​extra_ur_sites, ⁹​frac_pat_with_ur +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 0001 0001 10 8 21 6.25 +#> 2 0001 0001 10 8 21 3.12 +#> 3 0001 0001 10 8 21 0 +#> 4 0001 0001 10 8 21 3.12 +#> 5 0001 0001 10 8 21 0 +#> 6 0001 0001 10 8 21 3.12 +#> 7 0001 0001 10 8 21 0 +#> 8 0001 0002 10 10 14 3.8 +#> 9 0001 0002 10 10 14 1.9 +#> 10 0001 0002 10 10 14 0 +#> # ℹ 130 more rows +#> # ℹ 8 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # extra_ur_sites <dbl>, frac_pat_with_ur <dbl>, ur_rate <dbl>, +#> # prob_low <dbl>, prob_low_adj <dbl>, prob_low_prob_ur <dbl> df_perf <- get_portf_perf(df_scen) @@ -272,7 +283,7 @@

    Examples

    #> 8 0.001 0.916 1 1 1 #> 9 0.001 0.916 2 1 1 #> 10 0.01 0.913 0 0 0.05 -#> # … with 17 more rows +#> # ℹ 17 more rows # }
    @@ -288,7 +299,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_test_data_study.html b/docs/reference/sim_test_data_study.html index 89f7d9e..e1d9160 100644 --- a/docs/reference/sim_test_data_study.html +++ b/docs/reference/sim_test_data_study.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -107,7 +110,8 @@

    simulate study test data

    ur_rate = 0, max_visit_mean = 20, max_visit_sd = 4, - ae_per_visit_mean = 0.5 + ae_per_visit_mean = 0.5, + ae_rates = NULL ) @@ -143,6 +147,10 @@

    Arguments

    ae_per_visit_mean

    mean ae per visit per patient, Default: 0.5

    + +
    ae_rates
    +

    vector with visit-specific ae rates, Default: Null

    +

    Value

    @@ -165,43 +173,61 @@

    Examples

    df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5) df_visit[which(df_visit$patnum == "P000001"),] #> # A tibble: 17 × 8 -#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_vi…¹ visit n_ae -#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> <int> -#> 1 P000001 S0001 FALSE 20 4 0.5 1 0 -#> 2 P000001 S0001 FALSE 20 4 0.5 2 1 -#> 3 P000001 S0001 FALSE 20 4 0.5 3 1 -#> 4 P000001 S0001 FALSE 20 4 0.5 4 2 -#> 5 P000001 S0001 FALSE 20 4 0.5 5 4 -#> 6 P000001 S0001 FALSE 20 4 0.5 6 5 -#> 7 P000001 S0001 FALSE 20 4 0.5 7 6 -#> 8 P000001 S0001 FALSE 20 4 0.5 8 6 -#> 9 P000001 S0001 FALSE 20 4 0.5 9 6 -#> 10 P000001 S0001 FALSE 20 4 0.5 10 6 -#> 11 P000001 S0001 FALSE 20 4 0.5 11 7 -#> 12 P000001 S0001 FALSE 20 4 0.5 12 7 -#> 13 P000001 S0001 FALSE 20 4 0.5 13 8 -#> 14 P000001 S0001 FALSE 20 4 0.5 14 8 -#> 15 P000001 S0001 FALSE 20 4 0.5 15 9 -#> 16 P000001 S0001 FALSE 20 4 0.5 16 12 -#> 17 P000001 S0001 FALSE 20 4 0.5 17 12 -#> # … with abbreviated variable name ¹​ae_per_visit_mean +#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_visit_mean visit +#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> +#> 1 P000001 S0001 FALSE 20 4 0.5 1 +#> 2 P000001 S0001 FALSE 20 4 0.5 2 +#> 3 P000001 S0001 FALSE 20 4 0.5 3 +#> 4 P000001 S0001 FALSE 20 4 0.5 4 +#> 5 P000001 S0001 FALSE 20 4 0.5 5 +#> 6 P000001 S0001 FALSE 20 4 0.5 6 +#> 7 P000001 S0001 FALSE 20 4 0.5 7 +#> 8 P000001 S0001 FALSE 20 4 0.5 8 +#> 9 P000001 S0001 FALSE 20 4 0.5 9 +#> 10 P000001 S0001 FALSE 20 4 0.5 10 +#> 11 P000001 S0001 FALSE 20 4 0.5 11 +#> 12 P000001 S0001 FALSE 20 4 0.5 12 +#> 13 P000001 S0001 FALSE 20 4 0.5 13 +#> 14 P000001 S0001 FALSE 20 4 0.5 14 +#> 15 P000001 S0001 FALSE 20 4 0.5 15 +#> 16 P000001 S0001 FALSE 20 4 0.5 16 +#> 17 P000001 S0001 FALSE 20 4 0.5 17 +#> # ℹ 1 more variable: n_ae <int> df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5, frac_site_with_ur = 0.2, ur_rate = 0.5) df_visit[which(df_visit$patnum == "P000001"),] #> # A tibble: 23 × 8 -#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_vi…¹ visit n_ae -#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> <int> -#> 1 P000001 S0001 TRUE 20 4 0.25 1 0 -#> 2 P000001 S0001 TRUE 20 4 0.25 2 0 -#> 3 P000001 S0001 TRUE 20 4 0.25 3 1 -#> 4 P000001 S0001 TRUE 20 4 0.25 4 1 -#> 5 P000001 S0001 TRUE 20 4 0.25 5 1 -#> 6 P000001 S0001 TRUE 20 4 0.25 6 2 -#> 7 P000001 S0001 TRUE 20 4 0.25 7 2 -#> 8 P000001 S0001 TRUE 20 4 0.25 8 2 -#> 9 P000001 S0001 TRUE 20 4 0.25 9 2 -#> 10 P000001 S0001 TRUE 20 4 0.25 10 2 -#> # … with 13 more rows, and abbreviated variable name ¹​ae_per_visit_mean +#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_visit_mean visit +#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> +#> 1 P000001 S0001 TRUE 20 4 0.25 1 +#> 2 P000001 S0001 TRUE 20 4 0.25 2 +#> 3 P000001 S0001 TRUE 20 4 0.25 3 +#> 4 P000001 S0001 TRUE 20 4 0.25 4 +#> 5 P000001 S0001 TRUE 20 4 0.25 5 +#> 6 P000001 S0001 TRUE 20 4 0.25 6 +#> 7 P000001 S0001 TRUE 20 4 0.25 7 +#> 8 P000001 S0001 TRUE 20 4 0.25 8 +#> 9 P000001 S0001 TRUE 20 4 0.25 9 +#> 10 P000001 S0001 TRUE 20 4 0.25 10 +#> # ℹ 13 more rows +#> # ℹ 1 more variable: n_ae <int> +ae_rates <- c(0.7, rep(0.5, 8), rep(0.3, 5)) +sim_test_data_study(n_pat = 100, n_sites = 5, ae_rates = ae_rates) +#> # A tibble: 1,968 × 8 +#> patnum site_number is_ur max_visit_mean max_visit_sd ae_per_visit_mean visit +#> <chr> <chr> <lgl> <dbl> <dbl> <dbl> <int> +#> 1 P000001 S0001 FALSE 20 4 0.443 1 +#> 2 P000001 S0001 FALSE 20 4 0.443 2 +#> 3 P000001 S0001 FALSE 20 4 0.443 3 +#> 4 P000001 S0001 FALSE 20 4 0.443 4 +#> 5 P000001 S0001 FALSE 20 4 0.443 5 +#> 6 P000001 S0001 FALSE 20 4 0.443 6 +#> 7 P000001 S0001 FALSE 20 4 0.443 7 +#> 8 P000001 S0001 FALSE 20 4 0.443 8 +#> 9 P000001 S0001 FALSE 20 4 0.443 9 +#> 10 P000001 S0001 FALSE 20 4 0.443 10 +#> # ℹ 1,958 more rows +#> # ℹ 1 more variable: n_ae <int>
    @@ -216,7 +242,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/sim_ur_scenarios.html b/docs/reference/sim_ur_scenarios.html index e5b7a48..ca0189c 100644 --- a/docs/reference/sim_ur_scenarios.html +++ b/docs/reference/sim_ur_scenarios.html @@ -24,7 +24,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -68,6 +68,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -272,45 +275,45 @@

    Examples

    #> # A tibble: 20 × 6 #> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean n_pat #> <chr> <dbl> <chr> <dbl> <dbl> <int> -#> 1 0001 0.416 0001 3.39 18.2 10 -#> 2 0001 0.416 0002 2.72 19.6 10 -#> 3 0001 0.416 0003 2.12 19.6 10 -#> 4 0001 0.416 0004 3.92 18.4 10 -#> 5 0001 0.416 0005 3.63 19.9 10 -#> 6 0001 0.416 0006 3.83 20 10 -#> 7 0001 0.416 0007 2.69 21.1 10 -#> 8 0001 0.416 0008 4.24 19 10 -#> 9 0001 0.416 0009 3.59 21.3 10 -#> 10 0001 0.416 0010 2.95 19.7 10 -#> 11 0002 0.468 0001 4.42 20 10 -#> 12 0002 0.468 0002 4.03 21.4 10 -#> 13 0002 0.468 0003 4.13 20.2 10 -#> 14 0002 0.468 0004 2.58 18.3 10 -#> 15 0002 0.468 0005 4.64 17.8 10 -#> 16 0002 0.468 0006 2.37 17.6 10 -#> 17 0002 0.468 0007 4.80 19.8 10 -#> 18 0002 0.468 0008 2 20 10 -#> 19 0002 0.468 0009 3.17 19.5 10 -#> 20 0002 0.468 0010 6.57 19.9 10 +#> 1 0001 0.366 0001 4.42 20 10 +#> 2 0001 0.366 0002 4.03 21.4 10 +#> 3 0001 0.366 0003 4.13 20.2 10 +#> 4 0001 0.366 0004 2.58 18.3 10 +#> 5 0001 0.366 0005 4.64 17.8 10 +#> 6 0001 0.366 0006 2.37 17.6 10 +#> 7 0001 0.366 0007 4.80 19.8 10 +#> 8 0001 0.366 0008 2 20 10 +#> 9 0001 0.366 0009 3.17 19.5 10 +#> 10 0001 0.366 0010 6.57 19.9 10 +#> 11 0002 0.489 0001 2.85 19.9 10 +#> 12 0002 0.489 0002 3.31 18.1 10 +#> 13 0002 0.489 0003 3.14 18.1 10 +#> 14 0002 0.489 0004 4.74 20.7 10 +#> 15 0002 0.489 0005 5.20 19.2 10 +#> 16 0002 0.489 0006 3.30 21 10 +#> 17 0002 0.489 0007 4.07 19.9 10 +#> 18 0002 0.489 0008 4.53 18.5 10 +#> 19 0002 0.489 0009 2.95 21.7 10 +#> 20 0002 0.489 0010 3.36 20.2 10 df_portf <- sim_test_data_portfolio(df_config) df_portf -#> # A tibble: 3,815 × 8 -#> study_id ae_per_visit_mean site_number max_visit…¹ max_v…² patnum visit n_ae -#> <chr> <dbl> <chr> <dbl> <dbl> <chr> <int> <int> -#> 1 0001 0.416 0001 3.39 18.2 0001 1 1 -#> 2 0001 0.416 0001 3.39 18.2 0001 2 1 -#> 3 0001 0.416 0001 3.39 18.2 0001 3 1 -#> 4 0001 0.416 0001 3.39 18.2 0001 4 1 -#> 5 0001 0.416 0001 3.39 18.2 0001 5 2 -#> 6 0001 0.416 0001 3.39 18.2 0001 6 3 -#> 7 0001 0.416 0001 3.39 18.2 0001 7 4 -#> 8 0001 0.416 0001 3.39 18.2 0001 8 4 -#> 9 0001 0.416 0001 3.39 18.2 0001 9 4 -#> 10 0001 0.416 0001 3.39 18.2 0001 10 5 -#> # … with 3,805 more rows, and abbreviated variable names ¹​max_visit_sd, -#> # ²​max_visit_mean +#> # A tibble: 3,834 × 8 +#> study_id ae_per_visit_mean site_number max_visit_sd max_visit_mean patnum +#> <chr> <dbl> <chr> <dbl> <dbl> <chr> +#> 1 0001 0.366 0001 4.42 20 0001 +#> 2 0001 0.366 0001 4.42 20 0001 +#> 3 0001 0.366 0001 4.42 20 0001 +#> 4 0001 0.366 0001 4.42 20 0001 +#> 5 0001 0.366 0001 4.42 20 0001 +#> 6 0001 0.366 0001 4.42 20 0001 +#> 7 0001 0.366 0001 4.42 20 0001 +#> 8 0001 0.366 0001 4.42 20 0001 +#> 9 0001 0.366 0001 4.42 20 0001 +#> 10 0001 0.366 0001 4.42 20 0001 +#> # ℹ 3,824 more rows +#> # ℹ 2 more variables: visit <int>, n_ae <int> df_scen <- sim_ur_scenarios(df_portf, extra_ur_sites = 2, @@ -324,23 +327,22 @@

    Examples

    df_scen #> # A tibble: 140 × 14 -#> study…¹ site_…² n_pat n_pat…³ visit…⁴ mean_…⁵ mean_…⁶ n_pat…⁷ extra…⁸ frac_…⁹ -#> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <int> <dbl> <dbl> -#> 1 0001 0001 10 10 12 5.9 4.74 88 0 0 -#> 2 0001 0001 10 10 12 2.95 4.74 88 0 0.102 -#> 3 0001 0001 10 10 12 0 4.74 88 0 0.102 -#> 4 0001 0001 10 10 12 2.95 4.53 88 1 0.202 -#> 5 0001 0001 10 10 12 0 4.33 88 1 0.202 -#> 6 0001 0001 10 10 12 2.95 4.24 88 2 0.302 -#> 7 0001 0001 10 10 12 0 3.75 88 2 0.302 -#> 8 0001 0002 10 9 15 4.78 6.52 79 0 0 -#> 9 0001 0002 10 9 15 2.39 6.52 79 0 0.102 -#> 10 0001 0002 10 9 15 0 6.52 79 0 0.102 -#> # … with 130 more rows, 4 more variables: ur_rate <dbl>, prob_low <dbl>, -#> # prob_low_adj <dbl>, prob_low_prob_ur <dbl>, and abbreviated variable names -#> # ¹​study_id, ²​site_number, ³​n_pat_with_med75, ⁴​visit_med75, -#> # ⁵​mean_ae_site_med75, ⁶​mean_ae_study_med75, ⁷​n_pat_with_med75_study, -#> # ⁸​extra_ur_sites, ⁹​frac_pat_with_ur +#> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 +#> <chr> <chr> <int> <int> <dbl> <dbl> +#> 1 0001 0001 10 9 16 5.44 +#> 2 0001 0001 10 9 16 2.72 +#> 3 0001 0001 10 9 16 0 +#> 4 0001 0001 10 9 16 2.72 +#> 5 0001 0001 10 9 16 0 +#> 6 0001 0001 10 9 16 2.72 +#> 7 0001 0001 10 9 16 0 +#> 8 0001 0002 10 9 16 4.89 +#> 9 0001 0002 10 9 16 2.44 +#> 10 0001 0002 10 9 16 0 +#> # ℹ 130 more rows +#> # ℹ 8 more variables: mean_ae_study_med75 <dbl>, n_pat_with_med75_study <int>, +#> # extra_ur_sites <dbl>, frac_pat_with_ur <dbl>, ur_rate <dbl>, +#> # prob_low <dbl>, prob_low_adj <dbl>, prob_low_prob_ur <dbl> df_perf <- get_portf_perf(df_scen) @@ -348,17 +350,17 @@

    Examples

    #> # A tibble: 27 × 5 #> fpr thresh extra_ur_sites ur_rate tpr #> <dbl> <dbl> <dbl> <dbl> <dbl> -#> 1 0.001 0.990 0 0 0.05 -#> 2 0.001 0.990 1 0 0.05 -#> 3 0.001 0.990 2 0 0.05 -#> 4 0.001 0.990 0 0.5 1 -#> 5 0.001 0.990 1 0.5 0.9 -#> 6 0.001 0.990 2 0.5 0.85 -#> 7 0.001 0.990 0 1 1 -#> 8 0.001 0.990 1 1 1 -#> 9 0.001 0.990 2 1 1 -#> 10 0.01 0.961 0 0 0.05 -#> # … with 17 more rows +#> 1 0.001 0.858 0 0 0.05 +#> 2 0.001 0.858 1 0 0.05 +#> 3 0.001 0.858 2 0 0.05 +#> 4 0.001 0.858 0 0.5 1 +#> 5 0.001 0.858 1 0.5 1 +#> 6 0.001 0.858 2 0.5 1 +#> 7 0.001 0.858 0 1 1 +#> 8 0.001 0.858 1 1 1 +#> 9 0.001 0.858 2 1 1 +#> 10 0.01 0.857 0 0 0.05 +#> # ℹ 17 more rows # } @@ -374,7 +376,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/simaerep.html b/docs/reference/simaerep.html index 0cd4853..651aeac 100644 --- a/docs/reference/simaerep.html +++ b/docs/reference/simaerep.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -251,7 +254,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/site_aggr.html b/docs/reference/site_aggr.html index 160abaf..e6da9ee 100644 --- a/docs/reference/site_aggr.html +++ b/docs/reference/site_aggr.html @@ -23,7 +23,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -67,6 +67,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -196,7 +199,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/reference/with_progress_cnd.html b/docs/reference/with_progress_cnd.html index bcc9104..765d610 100644 --- a/docs/reference/with_progress_cnd.html +++ b/docs/reference/with_progress_cnd.html @@ -25,7 +25,7 @@ simaerep - 0.4.3 + 0.4.4 @@ -69,6 +69,9 @@
  • Aggregate AEs by Days or Visit?
  • +
  • + Comparing {simaerep} and {gsm} Performance +
  • Changelog @@ -183,7 +186,7 @@

    Examples

    -

    Site built with pkgdown 2.0.5.

    +

    Site built with pkgdown 2.0.7.

    diff --git a/docs/sitemap.xml b/docs/sitemap.xml index 92594ef..d720ff5 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -15,6 +15,9 @@ https://openpharma.github.io/simaerep/articles/do_not_commit.html + + https://openpharma.github.io/simaerep/articles/gsm_perf.html + https://openpharma.github.io/simaerep/articles/index.html diff --git a/inst/WORDLIST b/inst/WORDLIST index aba68af..bd99f85 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -12,9 +12,11 @@ Hoffmann Lifecycle Modelling Ménard +RBQM Saf TP Uncompliant +Zink ae aes aggr @@ -28,6 +30,7 @@ csv darkblue df doi +dplyr ecd ecdf et @@ -38,7 +41,7 @@ frac furrr ggplot grey -https +gsm infer’ iterable iterables diff --git a/man/figures/README-unnamed-chunk-2-1.png b/man/figures/README-unnamed-chunk-2-1.png index ca2b821..c95aec5 100644 Binary files a/man/figures/README-unnamed-chunk-2-1.png and b/man/figures/README-unnamed-chunk-2-1.png differ diff --git a/man/sim_test_data_portfolio.Rd b/man/sim_test_data_portfolio.Rd index 753e7b1..b22b850 100644 --- a/man/sim_test_data_portfolio.Rd +++ b/man/sim_test_data_portfolio.Rd @@ -4,11 +4,18 @@ \alias{sim_test_data_portfolio} \title{Simulate Portfolio Test Data} \usage{ -sim_test_data_portfolio(df_config, parallel = FALSE, progress = TRUE) +sim_test_data_portfolio( + df_config, + df_ae_rates = NULL, + parallel = FALSE, + progress = TRUE +) } \arguments{ \item{df_config}{dataframe as returned by \code{\link{get_config}}} +\item{df_ae_rates}{dataframe with ae rates. Default: NULL} + \item{parallel}{logical activate parallel processing, see details, Default: FALSE} \item{progress}{logical, Default: TRUE} diff --git a/man/sim_test_data_study.Rd b/man/sim_test_data_study.Rd index 406b615..12822f8 100644 --- a/man/sim_test_data_study.Rd +++ b/man/sim_test_data_study.Rd @@ -11,7 +11,8 @@ sim_test_data_study( ur_rate = 0, max_visit_mean = 20, max_visit_sd = 4, - ae_per_visit_mean = 0.5 + ae_per_visit_mean = 0.5, + ae_rates = NULL ) } \arguments{ @@ -31,6 +32,8 @@ Default: 20} patient, Default: 4} \item{ae_per_visit_mean}{mean ae per visit per patient, Default: 0.5} + +\item{ae_rates}{vector with visit-specific ae rates, Default: Null} } \value{ tibble with columns site_number, patnum, is_ur, max_visit_mean, @@ -54,4 +57,6 @@ df_visit[which(df_visit$patnum == "P000001"),] df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5, frac_site_with_ur = 0.2, ur_rate = 0.5) df_visit[which(df_visit$patnum == "P000001"),] +ae_rates <- c(0.7, rep(0.5, 8), rep(0.3, 5)) +sim_test_data_study(n_pat = 100, n_sites = 5, ae_rates = ae_rates) } diff --git a/tests/testthat/_snaps/eval_sites.md b/tests/testthat/_snaps/eval_sites.md index 4dadce6..a446ccd 100644 --- a/tests/testthat/_snaps/eval_sites.md +++ b/tests/testthat/_snaps/eval_sites.md @@ -2,11 +2,13 @@ Code df_eval <- eval_sites(df_sim_sites, r_sim_sites = 100) - Warning + Condition + Warning in `eval_sites()`: study_id: C, site_number: a. pval == NA study_id: C, site_number: b. pval == NA study_id: C, site_number: c. pval == NA + Warning in `eval_sites()`: study_id: C, site_number: a, prob_low == NA diff --git a/vignettes/check_poisson.Rmd b/vignettes/check_poisson.Rmd index 4993ea5..ea55847 100644 --- a/vignettes/check_poisson.Rmd +++ b/vignettes/check_poisson.Rmd @@ -95,7 +95,7 @@ df_sim_sites set.seed(1) -future::plan(multiprocess) +plan(multisession, workers = 6) df_sim_studies <- sim_studies(df_visit, df_site, r = 100, @@ -155,3 +155,7 @@ Here we see that the probabilities from the site simulations (x-axis) perfectly ## Conclusion We see that the bootstrap method gives us more accurate probabilities than the p-values derived from poisson.test even though the AE generation in the sample data follows a strict poisson process. For real clinical trial data with different types of studies for which it is not clear whether AE generation is truly based on a pure poisson process we recommend to use the bootstrap method. If poisson.test shall be used we recommend checking the applicability as we just demonstrated on clinical data set. + +```{r close} +plan(sequential) +``` diff --git a/vignettes/gsm_perf.Rmd b/vignettes/gsm_perf.Rmd new file mode 100644 index 0000000..0de56d7 --- /dev/null +++ b/vignettes/gsm_perf.Rmd @@ -0,0 +1,389 @@ +--- +title: "Comparing {simaerep} and {gsm} Performance" +output: + html_document: + toc: true + toc_depth: 3 + toc_float: true + number_sections: true + code_folding: show + collapse: false +editor_options: + chunk_output_type: console +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE, cache = FALSE, message = FALSE) +``` + +# Load +```{r load} +suppressPackageStartupMessages(library(tidyverse)) +suppressPackageStartupMessages(library(knitr)) +suppressPackageStartupMessages(library(furrr)) +suppressPackageStartupMessages(library(future)) +suppressPackageStartupMessages(library(simaerep)) + +plan(multisession, workers = 6) +``` + +# Install {gsm} + +```{r eval = FALSE} +devtools::install_github("Gilead-BioStats/gsm", ref = "main") +``` + + + +# Introduction + +The [{gsm}](https://github.com/Gilead-BioStats/gsm/) R package provides a standardized Risk Based Quality Monitoring (RBQM) framework for clinical trials that pairs a flexible data pipeline with robust reports. It also uses Funnel Plots to flag outliers which provide broader tolerance limits for sites with low exposure and narrower limits for sites with higher exposure. This method is different to the event rate based limits we have used in previous heuristics to measure {simaerep} performance. Funnel plots are discussed in greater detail by [Zink et al. 2018](https://doi.org/10.1177/2168479017738981) + +One of the draw backs of using funnel plots for flagging is that they assume that the AE rate remains constant over the course of the study. + +# Prepare Data + +## Load Portfolio Configurations + +We have prepared a snapshot of the AE reporting configuration of our current portfolio. For each study we have also measured a visit-specific AE rate which allows us to generate a synthetic portfolio with flexible AE rates across a study. + +```{r real_config} + +df_config <- readr::read_csv("ae_conf_20240220.csv") +df_ae_rates <- readr::read_csv("ae_rates_20240220.csv") + +df_config %>% + head(25) %>% + knitr::kable() + +df_ae_rates %>% + head(25) %>% + knitr::kable() + +``` + +## Simulate Portfolio + +We generate two synthetic portfolios with no AE under-reporting sites. One portfolio with a fixed AE rate for all visits and another one with a flexible visit-specific AE rate. + +```{r sim_portf} + +df_portf_fix <- sim_test_data_portfolio(df_config, parallel = TRUE, progress = TRUE) + +df_portf_fix %>% + head(25) %>% + knitr::kable() + + +df_portf_flex <- sim_test_data_portfolio(df_config, df_ae_rates = df_ae_rates, parallel = TRUE, progress = TRUE) +``` + +## Compare AE rates + +Next we confirm the different AE rates in our two synthetic portfolios. + +```{r} +df_rate_fix <- df_portf_fix %>% + mutate(ae_rate = coalesce(n_ae - lag(n_ae), n_ae), .by = c("study_id", "patnum")) %>% + summarise(ae_rate = mean(ae_rate), .by = c("study_id", "visit")) %>% + mutate(rate = "fix") + + +df_rate_flex <- df_portf_flex %>% + mutate(ae_rate = coalesce(n_ae - lag(n_ae), n_ae), .by = c("study_id", "patnum")) %>% + summarise(ae_rate = mean(ae_rate), .by = c("study_id", "visit")) %>% + mutate(rate = "flex") +``` + +```{r fig.width=10, fig.height = 7} +bind_rows(df_rate_flex, df_rate_fix) %>% + ggplot(aes(visit, ae_rate)) + + geom_line(aes(group = study_id), alpha = 0.2) + + geom_smooth() + + facet_wrap(~ rate) + + labs(title = "Average AE rates per Study") +``` + + +```{r fig.width=10, fig.height = 7} +bind_rows(df_rate_flex, df_rate_fix) %>% + filter(dense_rank(study_id) <= 16) %>% + ggplot(aes(visit, ae_rate)) + + geom_line(aes(group = rate, color = rate)) + + facet_wrap(~ study_id, scales = "free") + + labs(title = "Average AE rates for Selected Studies") + +``` + +We can confirm that the AE rates in the "flexible" portfolio are not constant. Moreover +we see that the AE rate profile is very unique for each study. + + +# Apply {gsm} + +## Example + +Here we demonstrate how to use the {gsm} package on our simulated portfolios. + +```{r} + +get_SUBJ <- function(df_portf) { + df_portf %>% + select(study_id, siteid = site_number, subjid = patnum, timeonstudy = visit) %>% + summarise(timeonstudy = max(timeonstudy), .by = c(study_id, siteid, subjid)) %>% + group_by(study_id) %>% + nest() +} + + +get_AE <- function(df_portf) { + df_portf_fix %>% + select(study_id, subjid = patnum, n_ae) %>% + summarise(n_ae = max(n_ae), .by = c(study_id, subjid)) %>% + filter(n_ae > 0) %>% + mutate(n_ae = map(n_ae, ~ tibble(n = seq(1, .)), .progress = TRUE)) %>% + unnest(n_ae) %>% + select(- n) %>% + group_by(study_id) %>% + nest() +} + +dfSUBJ_fix <- get_SUBJ(df_portf_fix) +dfAE_fix <- get_AE(df_portf_fix) + +``` + +```{r} +dfInput <- gsm::AE_Map_Raw(list(dfSUBJ = dfSUBJ_fix$data[[1]], dfAE = dfAE_fix$data[[1]])) +dfInput + +dfTransformed <- gsm::Transform_Rate( + dfInput, + strNumeratorCol = "Count", + strDenominatorCol = "Exposure" + ) +dfTransformed + +dfAnalyzed <- gsm::Analyze_NormalApprox(dfTransformed) +dfAnalyzed + +dfFlagged <- gsm::Flag_NormalApprox(dfAnalyzed, vThreshold = c(-3, -2, 2, 3)) +dfFlagged + +dfSummary <- gsm::Summarize(dfFlagged) +dfSummary + +dfBounds <- gsm::Analyze_NormalApprox_PredictBounds(dfTransformed, vThreshold = c(-3, -2, 2, 3)) +dfBounds + +chart <- gsm::Visualize_Scatter(dfFlagged, dfBounds) +chart +``` + +## Simulate UR + +We write a function that removes a given ratio of AEs from one site in the data set and returns its z-score. + +```{r} +sim_site_ur_gsm <- function(site, ur_rate, dfTransformed) { + dfTransformed <- dfTransformed %>% + mutate( + Numerator = ifelse(GroupID == site, Numerator * (1 - ur_rate), Numerator), + Metric = Numerator / Denominator + ) + + gsm::Analyze_NormalApprox(dfTransformed) %>% + filter(GroupID == site) %>% + pull(Score) +} + +sim_site_ur_gsm("4747", ur_rate = 0.75, dfTransformed) +``` + +We write another function that systematically applies this `sim_site_ur_gsm` across all sites in all studies across a range of under-reporting ratios. + +```{r} + +sim_ur_gsm <- function(dfSUBJ, dfAE) { + dfSUBJ %>% + inner_join(dfAE, by = "study_id") %>% + ungroup() %>% + mutate( + trans = map2(data.x, data.y, ~ gsm::AE_Map_Raw(list(dfSUBJ = .x, dfAE = .y))), + trans = map(trans, ~ gsm::Transform_Rate(., strNumeratorCol = "Count", strDenominatorCol = "Exposure")), + sites = map(data.x, ~ distinct(., siteid)) + ) %>% + select(- starts_with("data.")) %>% + unnest(sites) %>% + mutate(ur = list(tibble(ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1)))) %>% + unnest(ur) %>% + mutate( + score = pmap_dbl(list(siteid, ur_rate, trans), sim_site_ur_gsm, .progress = TRUE) + ) +} + +df_sim_gsm_fix <- sim_ur_gsm(dfSUBJ_fix, dfAE_fix) +``` + +```{r} +df_sim_gsm_fix +``` + +We repeat the same steps for the portfolio with the flexible AE rates. + +```{r} + +dfSUBJ_flex <- get_SUBJ(df_portf_flex) +dfAE_flex<- get_AE(df_portf_flex) + + +df_sim_gsm_flex <- sim_ur_gsm(dfSUBJ_flex, dfAE_flex) +``` + + +# UR {simaerep} + +We simulate under-reporting for both portfolios using {simaerep} + +```{r} +df_sim_simaerep_fix <- sim_ur_scenarios( + df_portf_fix, + extra_ur_sites = 0, + ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1), + parallel = TRUE, + poisson = TRUE, + prob_lower = TRUE, + progress = TRUE +) +``` + +```{r} +df_sim_simaerep_flex <- sim_ur_scenarios( + df_portf_flex, + extra_ur_sites = 0, + ur_rate = c(0, 0.1, 0.25, 0.5, 0.75, 1), + parallel = TRUE, + poisson = TRUE, + prob_lower = TRUE, + progress = TRUE +) +``` + +# Evaluate + +## Combine Results + +```{r} + +df_sim_gsm_fix$ae_rate <- "AE rate: fix" +df_sim_gsm_flex$ae_rate <- "AE rate: flexible" +df_sim_simaerep_fix$ae_rate <- "AE rate: fix" +df_sim_simaerep_flex$ae_rate <- "AE rate: flexible" + +df_sim_thresh2 <- bind_rows(df_sim_gsm_fix, df_sim_gsm_flex) %>% + mutate( + is_ur = score <= -2, + type = "{gsm} - thresh: -2", + site_number = siteid + ) %>% + select(type, ae_rate, study_id, site_number, ur_rate, is_ur, score) + + +df_sim_simaerep_threshp95 <- bind_rows(df_sim_simaerep_fix, df_sim_simaerep_flex) %>% + mutate( + is_ur = prob_low_prob_ur >= 0.95, + type = "{simaerep} - thresh: 0.95" + ) %>% + select(type, ae_rate, study_id, site_number, ur_rate, is_ur, score = prob_low_prob_ur) + + +df_eval <- bind_rows( + df_sim_thresh2, + df_sim_simaerep_threshp95, +) +``` + + +## Aggregate + +```{r} +get_prop_test_ci95 <- function(..., ix) { + + stopifnot(ix %in% c(1, 2)) + + tryCatch( + prop.test(...)$conf.int[ix], + error = function(cnd) c(NA, NA)[ix] + ) +} + +aggr_results <- function(df_eval) { + +df_perf <- df_eval %>% + summarise( + n = n(), + .by = c(type, ae_rate, ur_rate, is_ur) + ) %>% + pivot_wider( + names_from = is_ur, + values_from = n, + names_prefix = "is_ur_", + values_fill = 0 + ) %>% + mutate( + n_sites = is_ur_TRUE + is_ur_FALSE + is_ur_NA, + ratio = is_ur_TRUE / n_sites, + ratio_type = ifelse(ur_rate == 0, "fpr", "tpr"), + ci95_low = map2_dbl(is_ur_TRUE, n_sites, ~ get_prop_test_ci95(.x, .y, ix = 1)), + ci95_high = map2_dbl(is_ur_TRUE, n_sites, ~ get_prop_test_ci95(.x, .y, ix = 2)) + ) +} + +df_perf <- aggr_results(df_eval) +``` + +# Results + +## Table + +```{r} +df_perf %>% + knitr::kable(digits = 3) + +``` + + + +## Plot Performance Metrics + +- {gsm} has better performance than {simaerep} when the AE rate is fixed, while {simaerep} greatly outperforms {gsm} when the AE rate is flexible and mimics the AE rates encountered in real study data sets. + +```{r, plot, fig.width=10, fig.height = 12} + +plot_perf <- function(df_perf) { + + df_perf %>% + mutate(ur_rate = paste0("under-reporting rate: ", ur_rate, " - ", ratio_type), + ur_rate = ifelse(str_detect(ur_rate, "fpr"), "fpr", ur_rate)) %>% + group_by(ur_rate) %>% + ggplot(aes(type, ratio)) + + geom_errorbar(aes(ymin = ci95_low, ymax = ci95_high, color = type), linewidth = 1) + + facet_grid(ur_rate ~ ae_rate) + + coord_flip() + + theme(legend.position = "bottom") + + labs( + x = "", + y = "CI95 Performance Ratio", + title = "{simaerep} vs {gsm} Performance" + ) + + scale_color_manual(values = c("#5491CC", "#F46626")) +} + +plot_perf(df_perf) +``` + + + +```{r close} +plan(sequential) +```