Skip to contents

Make list of analysis objects for class Simulation

Usage

make_analysis_object_list(simulation_obj, quiet = TRUE)

Arguments

simulation_obj

Simulation. Object of class Simulation created by psborrow2:::.simulation_obj().

quiet

logical. Whether to print messages (quiet = FALSE) or not (quiet = TRUE, the default)

Value

list of lists of Analysis objects

Examples


base_mat <- matrix(
  c(
    rep(0, 200), rep(0, 200), rep(1, 200),
    rep(1, 200), rep(0, 200), rep(0, 200),
    rep(0, 600)
  ),
  ncol = 3,
  dimnames = list(NULL, c("ext", "trt", "driftOR"))
)

add_binary_endpoint <- function(odds_ratio,
                                base_matrix = base_mat) {
  linear_predictor <- base_matrix[, "trt"] * log(odds_ratio)
  prob <- 1 / (1 + exp(-linear_predictor))

  bin_endpoint <- rbinom(
    NROW(base_matrix),
    1,
    prob
  )

  cbind(base_matrix, matrix(bin_endpoint, ncol = 1, dimnames = list(NULL, "ep")))
}

data_list <- list(
  list(add_binary_endpoint(1.5), add_binary_endpoint(1.5)),
  list(add_binary_endpoint(2.5), add_binary_endpoint(2.5))
)

guide <- data.frame(
  trueOR = c(1.5, 2.5),
  driftOR = c(1.0, 1.0),
  index = 1:2
)

sdl <- sim_data_list(
  data_list = data_list,
  guide = guide,
  effect = "trueOR",
  drift = "driftOR",
  index = "index"
)

sim_object <- psborrow2:::.simulation_obj(
  data_matrix_list = sdl,
  outcome = sim_outcome_list(list(default = logistic_bin_outcome("ep", normal_prior(0, 1000)))),
  covariate = sim_covariate_list(covariate_list = list(`No adjustment` = NULL)),
  borrowing = sim_borrowing_list(list(
    full_borrowing = borrowing_details("Full borrowing", "ext"),
    bdb = borrowing_details("BDB", "ext", exponential_prior(0.0001))
  )),
  treatment = sim_treatment_list(list(default = treatment_details("trt", normal_prior(0, 1000))))
)

sim_object@guide <- Reduce(
  merge,
  init = sim_object@data_matrix_list@guide,
  x = list(
    sim_object@outcome@guide,
    sim_object@borrowing@guide,
    sim_object@covariate@guide,
    sim_object@treatment@guide
  )
)

sim_object@n_combos <- NROW(sim_object@guide)
sim_object@n_analyses <- sum(sim_object@guide$n_datasets_per_param)

psborrow2:::make_analysis_object_list(sim_object)
#> [[1]]
#> [[1]][[1]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: Full borrowing 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> [[1]][[2]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: Full borrowing 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> 
#> [[2]]
#> [[2]][[1]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: Full borrowing 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> [[2]][[2]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: Full borrowing 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> 
#> [[3]]
#> [[3]][[1]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: BDB 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> [[3]][[2]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: BDB 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> 
#> [[4]]
#> [[4]][[1]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: BDB 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#> [[4]][[2]]
#> Analysis Object
#> 
#> Outcome model: LogisticBinaryOutcome 
#> Outcome variable: ep 
#> 
#> Borrowing method: BDB 
#> External flag: ext 
#> 
#> Treatment variable: trt 
#> 
#> Data: Matrix with 600 observations 
#>     -  200  internal controls
#>     -  200  external controls 
#>     -  200  internal experimental
#> 
#> Stan model compiled and ready to sample.
#>  Call mcmc_sample() next.
#>