Run a series of simulated trials according to a specified design
sim_trial.Rd
Run a series of simulated trials according to a specified design
Usage
sim_trial(
design,
runs1,
runs2,
adapt_rule,
data_gen_1,
data_gen_2,
include_designs = FALSE
)
Arguments
- design
cer_design or multiarm_design object to be used for the simulation
- runs1
Number of trials to run in the first stage
- runs2
Number of second stage to run for every first stage trial
- adapt_rule
function that takes a cer_design object after the first interim test and returns the same object with appropiate adaptions
- data_gen_1
function for generating first stage data, see details
- data_gen_2
function for generating second stage data, see details
- include_designs
boolean indicating whether to include the designs objects in the output
Details
data_gen_1 and data_gen_2 should take two arguments, the number of trials to simulate and the adapted design object, and return a matrix or dataframe with each row being the p-values for a single trial.
See also get_data_gen()
and get_data_gen_2()
for further information on
how the input and output of data generating functions should look.
Examples
as <- function(x,t) 2-2*pnorm(qnorm(1-x/2)/sqrt(t))
design <- multiarm_cer_design(
controls = 1,
treatment_assoc = c(1,1),
n_controls = 50,
n_treatments = 50,
weights = c(0.5, 0.5),
alpha = 0.05,
test_m = rbind(c(0, 1),
c(1, 0)),
alpha_spending_f = as,
t = 0.5)
adaption <- function(design) {
design |> multiarm_drop_arms(1)
}
data_gen <- get_data_gen(
matrix(1),
rbind(
c(1, 0.5),
c(0.5, 1)
),
c(0, 0.3),
100,
100
)
data_gen_2 <- get_data_gen_2(
matrix(1),
rbind(
c(1, 0.5),
c(0.5, 1)
),
c(0, 0)
)
sim_trial(
design,
5,
3,
adaption,
data_gen,
data_gen_2
)
#> run1 rej_1 rej_2 rej_any p_1 p_2 interim_rej_1 interim_rej_2
#> 1 1 FALSE FALSE FALSE 1 0.961581340 FALSE FALSE
#> 2 1 FALSE FALSE FALSE 1 0.338177340 FALSE FALSE
#> 3 1 FALSE FALSE FALSE 1 0.633886523 FALSE FALSE
#> 4 2 FALSE TRUE TRUE 1 0.020024391 FALSE FALSE
#> 5 2 FALSE TRUE TRUE 1 0.005126956 FALSE FALSE
#> 6 2 FALSE FALSE FALSE 1 0.242792223 FALSE FALSE
#> 7 3 FALSE FALSE FALSE 1 0.380815234 FALSE FALSE
#> 8 3 FALSE FALSE FALSE 1 0.035221224 FALSE FALSE
#> 9 3 FALSE FALSE FALSE 1 0.726402738 FALSE FALSE
#> 10 4 FALSE FALSE FALSE 1 0.274957013 FALSE FALSE
#> 11 4 FALSE FALSE FALSE 1 0.054485800 FALSE FALSE
#> 12 4 FALSE TRUE TRUE 1 0.011712328 FALSE FALSE
#> 13 5 FALSE FALSE FALSE 1 0.047619141 FALSE FALSE
#> 14 5 FALSE FALSE FALSE 1 0.272722814 FALSE FALSE
#> 15 5 FALSE FALSE FALSE 1 0.098743385 FALSE FALSE
#> interim_p_1 interim_p_2
#> 1 0.9883835 0.58079009
#> 2 0.9883835 0.58079009
#> 3 0.9883835 0.58079009
#> 4 0.2565430 0.00480112
#> 5 0.2565430 0.00480112
#> 6 0.2565430 0.00480112
#> 7 0.9918850 0.39739172
#> 8 0.9918850 0.39739172
#> 9 0.9918850 0.39739172
#> 10 0.3274491 0.02894867
#> 11 0.3274491 0.02894867
#> 12 0.3274491 0.02894867
#> 13 0.6145201 0.04164344
#> 14 0.6145201 0.04164344
#> 15 0.6145201 0.04164344