Skip to contents

Get Portfolio configuration from a df_visit input dataframe. Will . filter studies with only a few sites and patients and will anonymize IDs. . Portfolio configuration can be used by sim_test_data_portfolio to generate data for an artificial portfolio.

Usage

get_portf_config(
  df_visit,
  check = TRUE,
  min_pat_per_study = 100,
  min_sites_per_study = 10,
  anonymize = TRUE,
  pad_width = 4
)

Arguments

df_visit

input dataframe with columns study_id, site_id, patient_id, visit, n_events. Can also be a lazy database table.

check

logical, perform standard checks on df_visit, Default: TRUE

min_pat_per_study

minimum number of patients per study, Default: 100

min_sites_per_study

minimum number of sites per study, Default: 10

anonymize

logical, Default: TRUE

pad_width

padding width for newly created IDs, Default: 4

Value

dataframe with the following columns:

study_id

study identification

event_per_visit_mean

mean event per visit per study

site_id

site

max_visit_sd

standard deviation of maximum patient visits per site

max_visit_mean

mean of maximum patient visits per site

n_pat

number of patients

See also

Examples

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
#>    <chr>                   <dbl> <chr>          <dbl>          <dbl> <int>
#>  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
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = ":memory:")
dplyr::copy_to(con, df_visit, "visit")
tbl_visit <- dplyr::tbl(con, "visit")
get_portf_config(tbl_visit)
#> # A tibble: 20 × 6
#>    study_id event_per_visit_mean site_id max_visit_sd max_visit_mean n_pat
#>    <chr>                   <dbl> <chr>          <dbl>          <dbl> <dbl>
#>  1 0001                    0.455 0001            2.86           20.2    10
#>  2 0001                    0.455 0010            2.23           20.9    10
#>  3 0001                    0.455 0009            3.49           22.2    10
#>  4 0001                    0.455 0004            4.38           18.1    10
#>  5 0002                    0.576 0001            3.98           18.5    10
#>  6 0002                    0.576 0010            3.14           19.1    10
#>  7 0002                    0.576 0009            4.75           17.9    10
#>  8 0002                    0.576 0004            4.88           20.5    10
#>  9 0001                    0.455 0007            3.08           18.8    10
#> 10 0001                    0.455 0008            4.12           19.4    10
#> 11 0001                    0.455 0005            5.43           18.9    10
#> 12 0002                    0.576 0007            6.07           20      10
#> 13 0002                    0.576 0008            4.38           18.6    10
#> 14 0002                    0.576 0005            4.90           21.3    10
#> 15 0001                    0.455 0002            3.98           20.1    10
#> 16 0001                    0.455 0006            3.74           19.7    10
#> 17 0001                    0.455 0003            5.87           19.6    10
#> 18 0002                    0.576 0002            3.03           19.6    10
#> 19 0002                    0.576 0006            3.74           19.8    10
#> 20 0002                    0.576 0003            2.86           20.8    10
DBI::dbDisconnect(con)
# }