Skip to contents

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().

Usage

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>            <dbl>       <dbl> <chr>    
#>  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 <chr>, pval <dbl>, prob_low <dbl>
# }
if (FALSE) { # \dontrun{
# parallel processing -------------------------
library(future)
future::plan(multiprocess)
sim_studies(df_visit, df_site, r = 3, keep_ae = TRUE, parallel = TRUE)
future::plan(sequential)
} # }