Test function, test applicability of poisson test, by calculating a the bootstrapped probability of obtaining a specific p-value or lower, use in combination with get_ecd_values().

sim_studies(
  df_visit,
  df_site,
  r = 100,
  poisson_test = TRUE,
  prob_lower = TRUE,
  r_prob_lower = 1000,
  under_only = TRUE,
  parallel = FALSE,
  keep_ae = FALSE,
  min_n_pat_with_med75 = 1,
  studies = NULL,
  .progress = TRUE
)

Arguments

df_visit

dataframe

df_site

dataframe

r

integer, denotes number of simulations, Default: 1000

poisson_test

logical, calculates poisson.test pvalue, Default: TRUE

prob_lower

logical, calculates probability for getting a lower value, Default: FALSE

r_prob_lower

integer, denotes number of simulations for prob_lower value calculation,, Default: 1000

under_only

compute under-reporting probabilities only, default = TRUE

parallel

logical, see examples for registering parallel processing framework , Default: FALSE

keep_ae

logical, keep ae numbers in output dataframe memory increase roughly 30 percent, Default: F

min_n_pat_with_med75

integer, min number of patients with med75 at site to simulate, Default: 1

studies

vector with study names, Default: NULL

.progress

logical, show progress bar

Value

dataframe

Details

Here we simulate study replicates maintaining the same number of sites, patients and visit_med75 by bootstrap resampling, then probabilities for obtaining lower or same mean_ae count and p-values using poisson.test are calculated.

adds column with simulated probabilities for equal or lower mean_ae at visit_med75

Examples

# \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
#>    <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 -------------------------
library(future)
future::plan(multiprocess)
sim_studies(df_visit, df_site, r = 3, keep_ae = TRUE, parallel = TRUE)
future::plan(sequential)
}