Skip to contents

This function performs a simulation study for a given set of scenarios, analyzing simulated data using different models as indicated by the user. Performs inference for indicated experimental treatment arms. Simulates the probability to reject \(H_0\) based on a given number of replications.

Usage

sim_study(
  nsim,
  scenarios,
  arms,
  models = c("fixmodel", "sepmodel", "poolmodel"),
  endpoint,
  verbose = TRUE
)

Arguments

nsim

Integer. Number of replications. Must be larger than 1.

scenarios

Data frame containing all parameters for scenarios that should be simulated.

arms

Integer vector with treatment arms to perform inference on. These arms are compared to the control group. Default - all arms except the first one.

models

Character vector with models that should be used for the analysis. Default=c("fixmodel", "sepmodel", "poolmodel"). Available models for continuous endpoints are: 'fixmodel', 'fixmodel_cal', 'gam', 'MAPprior', 'mixmodel', 'mixmodel_cal', 'mixmodel_AR1', 'mixmodel_AR1_cal', 'piecewise', 'piecewise_cal', 'poolmodel', 'sepmodel', 'sepmodel_adj', 'splines', 'splines_cal', 'timemachine'. Available models for binary endpoints are: 'fixmodel', 'fixmodel_cal', 'MAPprior', 'poolmodel', 'sepmodel', 'sepmodel_adj', 'timemachine'.

endpoint

Endpoint indicator. "cont" for continuous endpoints, "bin" for binary endpoints.

verbose

Logical. Indicates whether to print a message (system time and number of finished scenarios) after simulating each scenario in order to track the progress of the simulations. Default=TRUE.

Value

Data frame with all considered scenarios and corresponding results - the probability to reject \(H_0\).

Author

Pavla Krotka

Examples


# \donttest{
# Create data frame with all parameters:
sim_scenarios <- data.frame(num_arms = 4,
n_arm = 250,
d1 = 250*0,
d2 = 250*1,
d3 = 250*2,
d4 = 250*3,
period_blocks = 2,
mu0 = 0,
sigma = 1,
theta1 = 0,
theta2 = 0,
theta3 = 0,
theta4 = 0,
lambda0 = rep(seq(-0.15, 0.15, length.out = 9), 2),
lambda1 = rep(seq(-0.15, 0.15, length.out = 9), 2),
lambda2 = rep(seq(-0.15, 0.15, length.out = 9), 2),
lambda3 = rep(seq(-0.15, 0.15, length.out = 9), 2),
lambda4 = rep(seq(-0.15, 0.15, length.out = 9), 2),
trend = c(rep("linear", 9), rep("stepwise_2", 9)),
alpha = 0.025,
ncc = TRUE)

# Run simulation study:
sim_results <- sim_study(nsim = 100, scenarios = sim_scenarios, arms = c(3, 4),
models = c("fixmodel", "sepmodel", "poolmodel"), endpoint = "cont")
#> [1] "Starting the simulations. 18 scenarios will be simulated. Starting time: 2023-06-15 17:18:28.325615"
#> [1] "Scenario 1/18 done. Time: 2023-06-15 17:18:31.407138"
#> [1] "Scenario 2/18 done. Time: 2023-06-15 17:18:34.915403"
#> [1] "Scenario 3/18 done. Time: 2023-06-15 17:18:37.776169"
#> [1] "Scenario 4/18 done. Time: 2023-06-15 17:18:40.558491"
#> [1] "Scenario 5/18 done. Time: 2023-06-15 17:18:43.312991"
#> [1] "Scenario 6/18 done. Time: 2023-06-15 17:18:46.177698"
#> [1] "Scenario 7/18 done. Time: 2023-06-15 17:18:49.034121"
#> [1] "Scenario 8/18 done. Time: 2023-06-15 17:18:51.993325"
#> [1] "Scenario 9/18 done. Time: 2023-06-15 17:18:55.19815"
#> [1] "Scenario 10/18 done. Time: 2023-06-15 17:18:58.140603"
#> [1] "Scenario 11/18 done. Time: 2023-06-15 17:19:00.985676"
#> [1] "Scenario 12/18 done. Time: 2023-06-15 17:19:03.920289"
#> [1] "Scenario 13/18 done. Time: 2023-06-15 17:19:06.782618"
#> [1] "Scenario 14/18 done. Time: 2023-06-15 17:19:09.620936"
#> [1] "Scenario 15/18 done. Time: 2023-06-15 17:19:12.538929"
#> [1] "Scenario 16/18 done. Time: 2023-06-15 17:19:15.282896"
#> [1] "Scenario 17/18 done. Time: 2023-06-15 17:19:18.14485"
#> [1] "Scenario 18/18 done. Time: 2023-06-15 17:19:21.191437"
# }