### Examples Source: https://openpharma.github.io/simaerep/reference/sim_after_prep.html Example of how to use the sim_after_prep function with test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_prep <- simaerep:::prep_for_sim(df_site, df_visit) df_sim <- simaerep:::sim_after_prep(df_prep) df_sim #> # A tibble: 5 × 9 #> study_id site_number n_pat n_pat_with_med75 visit_med75 mean_ae_site_med75 #> #> 1 A S0001 20 20 15 18.8 #> 2 A S0002 20 17 16 18 #> 3 A S0003 20 17 16 12 #> 4 A S0004 20 20 15 10.2 #> 5 A S0005 20 16 15 11.2 #> # ℹ 3 more variables: mean_ae_study_med75 , n_pat_with_med75_study , #> # prob_low ``` -------------------------------- ### Example Source: https://openpharma.github.io/simaerep/reference/get_portf_config.html Example of how to use get_portf_config to generate portfolio configuration from simulated study data. ```R df_visit1 <- sim_test_data_study(n_pat = 100, n_sites = 10, ratio_out = 0.4, factor_event_rate = - 0.6, study_id = "A") df_visit2 <- sim_test_data_study(n_pat = 100, n_sites = 10, ratio_out = 0.2, factor_event_rate = - 0.1, study_id = "B") df_visit <- dplyr::bind_rows(df_visit1, df_visit2) get_portf_config(df_visit) #> # A tibble: 20 × 6 #> study_id event_per_visit_mean site_id max_visit_sd max_visit_mean n_pat #> #> 1 0001 0.455 0001 2.86 20.2 10 #> 2 0001 0.455 0002 3.98 20.1 10 #> 3 0001 0.455 0003 5.87 19.6 10 #> 4 0001 0.455 0004 4.38 18.1 10 #> 5 0001 0.455 0005 5.43 18.9 10 #> 6 0001 0.455 0006 3.74 19.7 10 #> 7 0001 0.455 0007 3.08 18.8 10 #> 8 0001 0.455 0008 4.12 19.4 10 #> 9 0001 0.455 0009 3.49 22.2 10 #> 10 0001 0.455 0010 2.23 20.9 10 #> 11 0002 0.576 0001 3.98 18.5 10 #> 12 0002 0.576 0002 3.03 19.6 10 #> 13 0002 0.576 0003 2.86 20.8 10 #> 14 0002 0.576 0004 4.88 20.5 10 #> 15 0002 0.576 0005 4.90 21.3 10 #> 16 0002 0.576 0006 3.74 19.8 10 #> 17 0002 0.576 0007 6.07 20 10 #> 18 0002 0.576 0008 4.38 18.6 10 #> 19 0002 0.576 0009 4.75 17.9 10 #> 20 0002 0.576 0010 3.14 19.1 10 # \donttest{ ``` -------------------------------- ### Database Example Source: https://openpharma.github.io/simaerep/reference/get_portf_event_rates.html Shows how to use get_portf_event_rates with a database connection. ```R # Database example con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:") dplyr::copy_to(con, df_visit, "visit") tbl_visit <- dplyr::tbl(con, "visit") get_portf_event_rates(tbl_visit) #> # A tibble: 59 × 4 #> study_id visit event_rate n_pat #> #> 1 0001 4 1.57 100 #> 2 0001 7 0.57 100 #> 3 0001 13 0.0526 95 #> 4 0001 21 0.114 35 #> 5 0002 2 1.76 100 #> 6 0002 22 0 26 #> 7 0002 26 0 9 #> 8 0001 5 0.95 100 #> 9 0002 8 0.41 100 #> 10 0002 9 0.3 100 #> # ℹ 49 more rows DBI::dbDisconnect(con) # } ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/prep_for_sim.html Example of how to use the prep_for_sim function with test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_prep <- simaerep:::prep_for_sim(df_site, df_visit) df_prep ``` -------------------------------- ### Example Usage Source: https://openpharma.github.io/simaerep/reference/get_portf_event_rates.html Demonstrates how to use the get_portf_event_rates function with sample dataframes. ```R df_visit1 <- sim_test_data_study(n_pat = 100, n_sites = 10, ratio_out = 0.4, factor_event_rate = - 0.6, study_id = "A") df_visit2 <- sim_test_data_study(n_pat = 100, n_sites = 10, ratio_out = 0.2, factor_event_rate = - 0.1, study_id = "B") df_visit <- dplyr::bind_rows(df_visit1, df_visit2) get_portf_event_rates(df_visit) #> # A tibble: 59 × 4 #> study_id visit event_rate n_pat #> #> 1 0001 1 0 100 #> 2 0001 2 1.35 100 #> 3 0001 3 1.5 100 #> 4 0001 4 1.57 100 #> 5 0001 5 0.95 100 #> 6 0001 6 0.87 100 #> 7 0001 7 0.57 100 #> 8 0001 8 0.32 100 #> 9 0001 9 0.263 99 #> 10 0001 10 0.182 99 #> # ℹ 49 more rows ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/eval_sites.html An example of how to use the eval_sites function with simulated data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_sim_sites <- sim_sites(df_site, df_visit, r = 100) df_eval <- eval_sites(df_sim_sites) df_eval ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/sim_test_data_portfolio.html Example of how to use sim_test_data_portfolio to simulate portfolio test data. ```R # \donttest{ # df_visit1 <- sim_test_data_study(n_pat = 100, n_sites = 10, # ratio_out = 0.4, factor_event_rate = 0.6, # study_id = "A") # # df_visit2 <- sim_test_data_study(n_pat = 100, n_sites = 10, # ratio_out = 0.2, factor_event_rate = 0.1, # study_id = "B") # # # df_visit <- dplyr::bind_rows(df_visit1, df_visit2) # # df_config <- get_portf_config(df_visit) # # df_config # #> # A tibble: 20 × 6 # #> study_id event_per_visit_mean site_id max_visit_sd max_visit_mean n_pat # #> # #> 1 0001 0.778 0001 3.08 20.8 10 # #> 2 0001 0.778 0002 3.39 20.8 10 # #> 3 0001 0.778 0003 4.93 19.5 10 # #> 4 0001 0.778 0004 3.43 19.3 10 # #> 5 0001 0.778 0005 4.50 19.5 10 # #> 6 0001 0.778 0006 3.92 17.3 10 # #> 7 0001 0.778 0007 4.76 19.7 10 # #> 8 0001 0.778 0008 4.40 19.3 10 # #> 9 0001 0.778 0009 4.27 19.3 10 # #> 10 0001 0.778 0010 2.99 20.4 10 # #> 11 0002 0.632 0001 4.30 19.7 10 # #> 12 0002 0.632 0002 2.49 19.8 10 # #> 13 0002 0.632 0003 5.32 19.4 10 # #> 14 0002 0.632 0004 3.77 19.3 10 # #> 15 0002 0.632 0005 5.44 19.7 10 # #> 16 0002 0.632 0006 4.72 19.5 10 # #> 17 0002 0.632 0007 4.10 20.8 10 # #> 18 0002 0.632 0008 3.88 17.8 10 # #> 19 0002 0.632 0009 3.89 18.3 10 # #> 20 0002 0.632 0010 3.19 17.8 10 # # df_portf <- sim_test_data_portfolio(df_config) # # df_portf # #> # A tibble: 3,725 × 8 # #> study_id event_per_visit_mean site_id max_visit_sd max_visit_mean patient_id # #> # #> 1 0001 0.778 0001 3.08 20.8 0001 # #> 2 0001 0.778 0001 3.08 20.8 0001 # #> 3 0001 0.778 0001 3.08 20.8 0001 # #> 4 0001 0.778 0001 3.08 20.8 0001 # #> 5 0001 0.778 0001 3.08 20.8 0001 # #> 6 0001 0.778 0001 3.08 20.8 0001 # #> 7 0001 0.778 0001 3.08 20.8 0001 # #> 8 0001 0.778 0001 3.08 20.8 0001 # #> 9 0001 0.778 0001 3.08 20.8 0001 # #> 10 0001 0.778 0001 3.08 20.8 0001 # #> # ℹ 3,715 more rows # #> # ℹ 2 more variables: visit , n_event # # # } ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/site_aggr.html Example of how to use the site_aggr function with test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_site %>% knitr::kable(digits = 2) ``` -------------------------------- ### Example Usage Source: https://openpharma.github.io/simaerep/reference/plot_sim_example.html An example of how to call the plot_sim_example function with a modified argument. ```R # \donttest{ plot_sim_example(size_dots = 5) #> Warning: Cannot convert object of class list into a grob. # } ``` -------------------------------- ### Example Source: https://openpharma.github.io/simaerep/reference/orivisit.html Example of how to use the orivisit function with simulated test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = - 0.6 )#' visit <- orivisit(df_visit) object.size(df_visit) #> 131576 bytes object.size(visit) #> 3544 bytes as.data.frame(visit) #> # A tibble: 1,932 × 9 #> patient_id site_id is_out max_visit_mean max_visit_sd event_per_visit_mean #> #> 1 P000001 S0001 TRUE 20 4 0.141 #> 2 P000001 S0001 TRUE 20 4 0.141 #> 3 P000001 S0001 TRUE 20 4 0.141 #> 4 P000001 S0001 TRUE 20 4 0.141 #> 5 P000001 S0001 TRUE 20 4 0.141 #> 6 P000001 S0001 TRUE 20 4 0.141 #> 7 P000001 S0001 TRUE 20 4 0.141 #> 8 P000001 S0001 TRUE 20 4 0.141 #> 9 P000001 S0001 TRUE 20 4 0.141 #> 10 P000001 S0001 TRUE 20 4 0.141 #> # ℹ 1,922 more rows #> # ℹ 3 more variables: visit , n_event , study_id ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/pat_pool.html Example of how to use the pat_pool function. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_pat_pool <- simaerep:::pat_pool(df_visit, df_site) df_pat_pool #> # A tibble: 1 × 2 #> study_id pat_pool #> #> 1 A ``` -------------------------------- ### Usage Source: https://openpharma.github.io/simaerep/reference/sim_after_prep.html The usage of the sim_after_prep function. ```R sim_after_prep( df_sim_prep, r = 1000, poisson_test = FALSE, prob_lower = TRUE, progress = FALSE, under_only = TRUE ) ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/plot_dots.html An example of how to use the plot_dots function with a sample dataframe. ```R study <- tibble::tibble( site = LETTERS[1:3], patients = c(list(seq(1, 50, 1)), list(seq(1, 40, 1)), list(seq(1, 10, 1))) ) %>% tidyr::unnest(patients) %>% dplyr::mutate(n_ae = as.integer(runif(min = 0, max = 10, n = nrow(.)))) plot_dots(study) ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/sim_sites.html An example demonstrating how to use the sim_sites function with simulated data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( n_ae = n_event, site_number = site_id, patnum = patient_id ) df_site <- site_aggr(df_visit) df_sim_sites <- sim_sites(df_site, df_visit, r = 100) df_sim_sites %>% knitr::kable(digits = 2) ``` -------------------------------- ### Example Source: https://openpharma.github.io/simaerep/reference/sim_out.html Example of simulating under-reporting and comparing cumulated events. ```R df_visit <- sim_test_data_study(n_pat = 100, n_sites = 10) df_ur <- sim_out(df_visit, "A", site_id = "S0001", factor_event = - 0.35) # Example cumulated event for first patient with 35% under-reporting df_ur[df_ur$site_id == "S0001" & df_ur$patient_id == "P000001",]$n_event #> [1] 0.0 0.0 0.0 0.5 1.5 2.5 3.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 #> [20] 4.5 6.5 6.5 6.5 6.5 # Example cumulated event for first patient with no under-reporting df_visit[df_visit$site_id == "S0001" & df_visit$patient_id == "P000001",]$n_event #> [1] 0 2 2 4 5 6 7 8 8 8 8 8 8 8 8 8 8 8 8 8 10 10 10 10 ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/sim_test_data_study.html Example of how to use the `sim_test_data_study` function. ```R set.seed(1) # no outlier df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5) df_visit[which(df_visit$patient_id == "P000001"),] #> # A tibble: 17 × 9 #> patient_id site_id is_out max_visit_mean max_visit_sd event_per_visit_mean #> #> 1 P000001 S0001 FALSE 20 4 0.353 #> 2 P000001 S0001 FALSE 20 4 0.353 #> 3 P000001 S0001 FALSE 20 4 0.353 #> 4 P000001 S0001 FALSE 20 4 0.353 #> 5 P000001 S0001 FALSE 20 4 0.353 #> 6 P000001 S0001 FALSE 20 4 0.353 #> 7 P000001 S0001 FALSE 20 4 0.353 #> 8 P000001 S0001 FALSE 20 4 0.353 #> 9 P000001 S0001 FALSE 20 4 0.353 #> 10 P000001 S0001 FALSE 20 4 0.353 #> 11 P000001 S0001 FALSE 20 4 0.353 #> 12 P000001 S0001 FALSE 20 4 0.353 #> 13 P000001 S0001 FALSE 20 4 0.353 #> 14 P000001 S0001 FALSE 20 4 0.353 #> 15 P000001 S0001 FALSE 20 4 0.353 #> 16 P000001 S0001 FALSE 20 4 0.353 #> 17 P000001 S0001 FALSE 20 4 0.353 #> # ℹ 3 more variables: visit , n_event , study_id # under-reporting outlier df_visit <- sim_test_data_study(n_pat = 100, n_sites = 5, ratio_out = 0.2, factor_event_rate = -0.5) df_visit[which(df_visit$patient_id == "P000001"),] #> # A tibble: 23 × 9 #> patient_id site_id is_out max_visit_mean max_visit_sd event_per_visit_mean #> #> 1 P000001 S0001 TRUE 20 4 0.176 #> 2 P000001 S0001 TRUE 20 4 0.176 #> 3 P000001 S0001 TRUE 20 4 0.176 #> 4 P000001 S0001 TRUE 20 4 0.176 #> 5 P000001 S0001 TRUE 20 4 0.176 #> 6 P000001 S0001 TRUE 20 4 0.176 #> 7 P000001 S0001 TRUE 20 4 0.176 #> 8 P000001 S0001 TRUE 20 4 0.176 #> 9 P000001 S0001 TRUE 20 4 0.176 #> 10 P000001 S0001 TRUE 20 4 0.176 #> # ℹ 13 more rows #> # ℹ 3 more variables: visit , n_event , study_id ``` -------------------------------- ### Example 1: Basic usage Source: https://openpharma.github.io/simaerep/reference/sim_studies.html This example demonstrates the basic usage of the sim_studies function with sample data. ```R # \donttest{ df_visit1 <- sim_test_data_study(n_pat = 100, n_sites = 5, frac_site_with_ur = 0.4, ur_rate = 0.6) df_visit1$study_id <- "A" df_visit2 <- sim_test_data_study(n_pat = 1000, n_sites = 3, frac_site_with_ur = 0.2, ur_rate = 0.1) df_visit2$study_id <- "B" df_visit <- dplyr::bind_rows(df_visit1, df_visit2) df_site <- site_aggr(df_visit) sim_studies(df_visit, df_site, r = 3, keep_ae = TRUE) #> # A tibble: 24 × 10 #> r study_id site_number visit_med75 n_pat_with_med75 n_pat_study n_ae_site #> #> 1 1 A S0001 16 18 68 11,5,7,4… #> 2 1 A S0002 18 17 53 11,16,8,… #> 3 1 A S0003 17 18 62 13,11,13… #> 4 1 A S0004 14 18 74 7,9,7,6,… #> 5 1 A S0005 15 17 71 6,9,5,4,… #> 6 1 B S0001 15 297 597 10,13,11… #> 7 1 B S0002 15 296 598 3,10,4,6… #> 8 1 B S0003 15 301 593 3,6,7,10… #> 9 2 A S0001 16 18 68 10,5,7,3… #> 10 2 A S0002 18 17 53 5,17,8,6… #> # ℹ 14 more rows #> # ℹ 3 more variables: n_ae_study , pval , prob_low # } ``` -------------------------------- ### Database Calculation Example Source: https://openpharma.github.io/simaerep/articles/intro.html Demonstrates setting up a DuckDB database, creating tables for study data and replications, and running the simaerep function with lazy tables. ```R con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:") df_r <- tibble(rep = seq(1, 1000)) df_visit <- sim_test_data_study( n_pat = 100, # number of patients in study n_sites = 10, # number of sites in study ratio_out = 0.1, # ratio of sites with outlier factor_event_rate = -0.5, # rate of under-reporting # non-constant event rates based on gamma distribution event_rates = (dgamma(seq(1, 20, 0.5), shape = 5, rate = 2) * 5) + 0.1, max_visit = 20, max_visit_sd = 10, study_id = "A" ) dplyr::copy_to(con, df_visit, "visit") dplyr::copy_to(con, df_r, "r") tbl_visit <- tbl(con, "visit") tbl_r <- tbl(con, "r") evrep_db <- simaerep(tbl_visit, r = tbl_r) ``` -------------------------------- ### Example 2: Parallel processing Source: https://openpharma.github.io/simaerep/reference/sim_studies.html This example shows how to use parallel processing with the sim_studies function. ```R # parallel processing ------------------------- library(future) future::plan(multiprocess) sim_studies(df_visit, df_site, r = 3, keep_ae = TRUE, parallel = TRUE) future::plan(sequential) ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/check_df_visit.html Example of how to use the check_df_visit function with test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = 0.6 ) %>% # internal functions require internal column names dplyr::rename( site_number = site_id, patnum = patient_id ) df_visit_filt <- df_visit %>% dplyr::filter(visit != 3) df_visit_corr <- check_df_visit(df_visit_filt) #> Warning: implicitly missing visit numbers detected and corrected 3 %in% df_visit_corr$visit #> [1] TRUE nrow(df_visit_corr) == nrow(df_visit) #> [1] TRUE df_visit_corr <- check_df_visit(dplyr::bind_rows(df_visit, df_visit)) #> Warning: Duplicated visit entries for some patients detected and corrected. nrow(df_visit_corr) == nrow(df_visit) #> [1] TRUE ``` -------------------------------- ### Usage Source: https://openpharma.github.io/simaerep/reference/get_config.html Function signature for get_config. ```R get_config( df_site, min_pat_per_study = 100, min_sites_per_study = 10, anonymize = TRUE, pad_width = 4 ) ``` -------------------------------- ### Usage Source: https://openpharma.github.io/simaerep/reference/get_portf_config.html The function signature for get_portf_config. ```R get_portf_config( df_visit, check = TRUE, min_pat_per_study = 100, min_sites_per_study = 10, anonymize = TRUE, pad_width = 4 ) ``` -------------------------------- ### Install simaerep Development Version from GitHub Source: https://openpharma.github.io/simaerep/index.html Install the development version of the simaerep package from GitHub using the devtools package. ```r # install.packages("devtools") devtools::install_github("openpharma/simaerep") ``` -------------------------------- ### purrr::walk example Source: https://openpharma.github.io/simaerep/reference/purrr_bar.html Example of using purrr_bar with purrr::walk and Sys.sleep. ```R # purrr::walk progressr::with_progress( purrr_bar(rep(0.25, 5), .purrr = purrr::walk,.f = Sys.sleep, .steps = 5) ) ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/sim_test_data_patient.html Examples demonstrating the output of sim_test_data_patient with default parameters and with custom event per visit sampling. ```R replicate(5, sim_test_data_patient()) #> [[1]] #> [1] 0 2 2 4 5 6 6 7 10 10 10 11 12 13 13 13 14 15 15 15 #> #> [[2]] #> [1] 0 0 0 0 0 0 0 0 0 1 3 4 4 4 4 4 4 5 #> #> [[3]] #> [1] 0 2 3 4 5 6 7 7 7 7 9 11 11 11 12 12 12 13 14 #> #> [[4]] #> [1] 0 1 1 1 1 1 2 2 2 2 2 2 3 5 6 6 #> #> [[5]] #> [1] 1 1 1 3 3 5 6 6 7 7 7 7 7 7 7 10 12 12 12 12 #> replicate(5, sim_test_data_patient( .f_sample_event_per_visit = function(x) rpois(x, 1.2)) ) #> [[1]] #> [1] 1 2 2 3 3 4 5 7 7 7 10 10 12 15 15 15 15 16 19 19 19 20 22 24 #> #> [[2]] #> [1] 2 4 5 6 6 6 6 6 8 10 12 13 14 15 17 19 20 23 24 25 26 26 28 #> #> [[3]] #> [1] 0 1 1 1 1 3 8 9 9 12 13 13 13 14 14 16 17 20 23 25 26 28 30 31 31 #> #> [[4]] #> [1] 2 2 2 3 4 7 9 10 10 11 12 13 16 16 17 17 17 18 18 #> #> [[5]] #> [1] 2 3 4 4 5 7 10 12 12 14 16 18 18 20 21 21 21 21 22 25 #> replicate(5, sim_test_data_patient( .f_sample_max_visit = function() rnorm(1, mean = 5, sd = 5)) ) #> [[1]] #> [1] 1 2 2 #> #> [[2]] #> [1] 1 #> #> [[3]] #> [1] 0 1 #> #> [[4]] #> [1] 0 0 2 4 5 6 6 6 #> #> [[5]] #> [1] 0 0 1 1 1 1 1 #> ``` -------------------------------- ### Example Usage 1 Source: https://openpharma.github.io/simaerep/reference/poiss_test_site_ae_vs_study_ae.html An example demonstrating the usage of `poiss_test_site_ae_vs_study_ae` with sample AE data and a visit median. ```R simaerep:::poiss_test_site_ae_vs_study_ae( site_ae = c(5, 3, 3, 2, 1, 6), study_ae = c(9, 8, 7, 9, 6, 7, 8), visit_med75 = 10 ) #> [1] 0.0009782833 ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/with_progress_cnd.html Examples demonstrating the use of `with_progress_cnd` for controlling progress bars, including nested progress bars. ```R if (interactive()) { with_progress_cnd( purrr_bar(rep(0.25, 5), .purrr = purrr::map, .f = Sys.sleep, .steps = 5), progress = TRUE ) with_progress_cnd( purrr_bar(rep(0.25, 5), .purrr = purrr::map, .f = Sys.sleep, .steps = 5), progress = FALSE ) # wrap a function with progress bar with another call with progress bar f1 <- function(x, progress = TRUE) { with_progress_cnd( purrr_bar(x, .purrr = purrr::walk, .f = Sys.sleep, .steps = length(x), .progress = progress), progress = progress ) } # inner progress bar blocks outer progress bar progressr::with_progress( purrr_bar( rep(rep(1, 3),3), .purrr = purrr::walk, .f = f1, .steps = 3, .f_args = list(progress = TRUE) ) ) # inner progress bar turned off progressr::with_progress( purrr_bar( rep(list(rep(0.25, 3)), 5), .purrr = purrr::walk, .f = f1, .steps = 5, .f_args = list(progress = FALSE) ) ) } ``` -------------------------------- ### Example Usage 2 Source: https://openpharma.github.io/simaerep/reference/poiss_test_site_ae_vs_study_ae.html A second example of `poiss_test_site_ae_vs_study_ae` with different AE data. ```R simaerep:::poiss_test_site_ae_vs_study_ae( site_ae = c(11, 9, 8, 6, 3), study_ae = c(9, 8, 7, 9, 6, 7, 8), visit_med75 = 10 ) #> [1] 0.9154536 ``` -------------------------------- ### Examples Source: https://openpharma.github.io/simaerep/reference/plot.simaerep.html Demonstrates how to use the plot function with simulated data. ```R # \donttest{ # df_visit <- sim_test_data_study( # n_pat = 100, # n_sites = 5, # ratio_out = 0.4, # factor_event_rate = - 0.6 # ) # # evrep <- simaerep(df_visit) # # plot(evrep, what = "prob", study = "A") # # plot(evrep, what = "med75", study = "A") # #> purple line: mean site event of patients with visit_med75 # #> grey line: patient included # #> black dashed line: patient excluded # #> dotted vertical line: visit_med75, 0.75 x median of maximum patient visits of site # #> solid vertical line: visit_med75 adjusted, increased to minimum maximum patient visit of included patients # #> dashed vertical line: maximum value for visit_med75 adjusted, 80% quantile of maximum patient visits of study # #> # # # } ``` -------------------------------- ### Example Usage Source: https://openpharma.github.io/simaerep/reference/sim_inframe.html An example demonstrating how to use the sim_inframe function with simulated test data. ```R df_visit <- sim_test_data_study( n_pat = 100, n_sites = 5, ratio_out = 0.4, factor_event_rate = - 0.6 ) %>% dplyr::rename( site_number = site_id, patnum = patient_id, n_ae = n_event ) df_sim <- simaerep:::sim_inframe(df_visit) ``` -------------------------------- ### Install {gsm} Package Source: https://openpharma.github.io/simaerep/articles/funnel_perf.html Installs the {gsm} R package from a specific GitHub repository and branch. ```r devtools::install_github("Gilead-BioStats/gsm@v1.9.2", ref = "main") ``` -------------------------------- ### Simulate portfolio performance Source: https://openpharma.github.io/simaerep/reference/get_config.html This code snippet simulates portfolio data based on the generated configuration and then simulates under-reporting scenarios. ```r df_portf <- sim_test_data_portfolio(df_config) df_portf df_scen <- sim_ur_scenarios(df_portf, extra_ur_sites = 2, ur_rate = c(0.5, 1)) df_scen ``` -------------------------------- ### Simulate study data and generate configuration Source: https://openpharma.github.io/simaerep/reference/get_config.html This code snippet simulates data for two studies, combines them, calculates site-level maximums, and then uses `get_config` to generate a configuration object. ```r # Simulate data for two studies df_visit1 <- sim_test_data_study(n_pat = 100, n_sites = 10, frac_site_with_ur = 0.4, ur_rate = 0.6) df_visit1$study_id <- "A" df_visit2 <- sim_test_data_study(n_pat = 100, n_sites = 10, frac_site_with_ur = 0.2, ur_rate = 0.1) df_visit2$study_id <- "B" # Combine the dataframes df_visit <- dplyr::bind_rows(df_visit1, df_visit2) # Calculate site-level maximums df_site_max <- df_visit %>% dplyr::group_by(study_id, site_number, patnum) %>% dplyr::summarise(max_visit = max(visit), max_ae = max(n_ae), .groups = "drop") # Generate the configuration object df_config <- get_config(df_site_max) df_config ``` -------------------------------- ### Example Usage Source: https://openpharma.github.io/simaerep/reference/prob_lower_site_ae_vs_study_ae.html An example demonstrating how to use the prob_lower_site_ae_vs_study_ae function with sample site and study AE data, and the expected output. ```R simaerep:::prob_lower_site_ae_vs_study_ae( site_ae = c(5, 3, 3, 2, 1, 6), study_ae = c(9, 8, 7, 9, 6, 7, 8) ) #> [1] 0.011 ```