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\), and the bias, as well as the mean squared error (MSE) of the treatment effect estimates based on a given number of replications.

Usage

sim_study_par(
  nsim,
  scenarios,
  arms,
  models = c("fixmodel", "sepmodel", "poolmodel"),
  endpoint,
  perc_cores = 0.9,
  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.

perc_cores

Double. What percentage of available cores should be used for the simulations. Default=0.9.

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\), and the bias, as well as the mean squared error (MSE) of the treatment effect estimates.

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_par(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:19:21.580538"
#> [1] "Scenario 1/18 done. Time: 2023-06-15 17:19:28.698113"
#> [1] "Scenario 2/18 done. Time: 2023-06-15 17:19:29.543042"
#> [1] "Scenario 3/18 done. Time: 2023-06-15 17:19:30.415569"
#> [1] "Scenario 4/18 done. Time: 2023-06-15 17:19:31.263772"
#> [1] "Scenario 5/18 done. Time: 2023-06-15 17:19:32.114397"
#> [1] "Scenario 6/18 done. Time: 2023-06-15 17:19:33.002093"
#> [1] "Scenario 7/18 done. Time: 2023-06-15 17:19:33.892851"
#> [1] "Scenario 8/18 done. Time: 2023-06-15 17:19:34.740734"
#> [1] "Scenario 9/18 done. Time: 2023-06-15 17:19:35.631759"
#> [1] "Scenario 10/18 done. Time: 2023-06-15 17:19:36.514705"
#> [1] "Scenario 11/18 done. Time: 2023-06-15 17:19:37.410884"
#> [1] "Scenario 12/18 done. Time: 2023-06-15 17:19:38.285891"
#> [1] "Scenario 13/18 done. Time: 2023-06-15 17:19:39.251427"
#> [1] "Scenario 14/18 done. Time: 2023-06-15 17:19:40.090667"
#> [1] "Scenario 15/18 done. Time: 2023-06-15 17:19:40.947087"
#> [1] "Scenario 16/18 done. Time: 2023-06-15 17:19:41.751704"
#> [1] "Scenario 17/18 done. Time: 2023-06-15 17:19:42.581011"
#> [1] "Scenario 18/18 done. Time: 2023-06-15 17:19:43.386365"
# }