Skip to contents

Merge results from additional or updated simulations

Usage

upsert_merge(x, y, by)

merge_additional_results(
  old,
  new,
  design_names = NULL,
  descriptive_regex = NULL
)

Arguments

x

left data.frame

y

right data.frame

by

columns to match by

old

old results

new

new/additional results

design_names

names of the paramterst

descriptive_regex

regular expression for columns of descriptive statistics

Value

a data.frame

a data.frame of the merged simulation results

Details

updates columns in x with values from matched rows in y and add joins columns from y not present in x. Calls rows_upsert and then full_join.

if design_names is omitted its value is taken from the design_names attribute of the simulation results.

If descriptive_regex is given, columns matching the regular expression in both datasets are compared, a warning is given, if the values of those columns do not match. This is intended to compare descriptive statistics or results of unchanged analysis methods to ensure, that both results stem from an exact replication of the simulation results.

Functions

  • upsert_merge(): Update or add Rows and Columns

Examples

a <- data.frame(x=5:2, y=5:2, a=5:2)
b <- data.frame(x=1:4, y=1:4+10, b=1:4*10)
upsert_merge(a, b, by="x")
#>   x  y  a  b
#> 1 5  5  5 NA
#> 2 4 14  4 40
#> 3 3 13  3 30
#> 4 2 12  2 20
#> 5 1 11 NA 10
# \donttest{
condition <- merge(
  assumptions_delayed_effect(),
  design_fixed_followup(),
  by=NULL
) |>
  tail(4) |>
  true_summary_statistics_delayed_effect(cutoff_stats = 15)

condition_1 <- condition[1:2, ]
condition_2 <- condition[3:4, ]

# runs simulations
sim_results_1 <- runSimulation(
  design=condition_1,
  replications=100,
  generate=generate_delayed_effect,
  analyse=list(
    logrank  = analyse_logrank(alternative = "one.sided"),
    maxcombo = analyse_logrank(alternative = "one.sided")
  ),
  summarise = create_summarise_function(
    logrank = summarise_test(0.025),
    maxcombo = summarise_test(0.025)
  )
)
#> 
#> 
Design: 1/2;   RAM Used: 175.3 Mb;   Replications: 100;   Total Time: 0.00s 
#>  Conditions: delay=121., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=1034, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
Design: 2/2;   RAM Used: 175.4 Mb;   Replications: 100;   Total Time: 3.22s 
#>  Conditions: delay=182., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=1004, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
#> Simulation complete. Total execution time: 6.24s

sim_results_2 <- runSimulation(
  design=condition_2,
  replications=100,
  generate=generate_delayed_effect,
  analyse=list(
    logrank  = analyse_logrank(alternative = "one.sided"),
    maxcombo = analyse_logrank(alternative = "one.sided")
  ),
  summarise = create_summarise_function(
    logrank = summarise_test(0.025),
    maxcombo = summarise_test(0.025)
  )
)
#> 
#> 
Design: 1/2;   RAM Used: 175.6 Mb;   Replications: 100;   Total Time: 0.00s 
#>  Conditions: delay=243., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=974, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
Design: 2/2;   RAM Used: 175.6 Mb;   Replications: 100;   Total Time: 3.02s 
#>  Conditions: delay=304., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=943., mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
#> Simulation complete. Total execution time: 6.05s

sim_results_3 <- runSimulation(
  design=condition,
  replications=100,
  generate=generate_delayed_effect,
  analyse=list(
    mwlrt = analyse_modelstly_weighted(t_star = m2d(24))
  ),
  summarise = create_summarise_function(
    mwlrt = summarise_test(0.025)
  )
)
#> 
#> 
Design: 1/4;   RAM Used: 175.8 Mb;   Replications: 100;   Total Time: 0.00s 
#>  Conditions: delay=121., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=1034, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
Design: 2/4;   RAM Used: 175.7 Mb;   Replications: 100;   Total Time: 0.67s 
#>  Conditions: delay=182., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=1004, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
Design: 3/4;   RAM Used: 175.8 Mb;   Replications: 100;   Total Time: 1.27s 
#>  Conditions: delay=243., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=974, mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
Design: 4/4;   RAM Used: 175.8 Mb;   Replications: 100;   Total Time: 1.93s 
#>  Conditions: delay=304., hzrd_c=0.0009, hzrd_t=0.0006, rndm_w=0.0001, n_trt=150, n_ctrl=150, follwp=730., rcrtmn=182., mdn_srvvl_t=943., mdn_srvvl_c=730., rmst_t_15=14.8, rmst_c_15=14.8, gAHR_1=1, AHR_15=1, AHRc_15=1, AHR__1=1
#> 

#> 
#> Simulation complete. Total execution time: 2.60s

all_results <- sim_results_1 |>
  merge_additional_results(sim_results_2) |>
  merge_additional_results(sim_results_3)

all_results |>
  subset(select=c(delay, logrank.rejection_0.025, maxcombo.rejection_0.025, mwlrt.rejection_0.025))
#> # A tibble: 4 × 4
#>    delay logrank.rejection_0.025 maxcombo.rejection_0.025 mwlrt.rejection_0.025
#>    <dbl>                   <dbl>                    <dbl>                 <dbl>
#> 1 121.75                    0.86                     0.86                  0.93
#> 2 182.62                    0.82                     0.82                  0.82
#> 3 243.5                     0.73                     0.73                  0.86
#> 4 304.38                    0.87                     0.87                  0.81

# }