inst/nami_simulations/simulation_code/run_experiments.R

#-----
# 3) Create study environment (TEST/NO TEST)
# Result: experimental registry
#-----

# Create registry and results directories
if (!dir.exists("registry"))
    dir.create("registry")
if (!dir.exists("results"))
    dir.create("results")
reg <- makeExperimentRegistry(file.dir = file.path("registry", REGISTRY), 
                              packages = c("tram"), seed = SEED)

# Specifications
reg$default.resources <- list(
  ntasks = 1L,
  ncpus = 1L,
  nodes = 1L,
  clusters = "serial")
reg$cluster.functions <- makeClusterFunctionsMulticore(CORES)


#----
# 4) Add problem = based on setup 
#----
addProblem(PROBNAM, fun = fun, reg = reg)
prob.designs <- list(setups)
names(prob.designs) <- PROBNAM

#----
# 5) Add algorithms 
#----
algo.designs <- list()
for (method in names(methods)) {
  addAlgorithm(method, fun = methods[[method]], reg = reg)
  algo.designs[[method]] <- data.frame()
}

#----
# 6) add experiments
#----
addExperiments(prob.designs, algo.designs, reg = reg)

# get only ids of marginal model with a single covariate and no prognostic effect
# only for RCT, not for observational data
sim <- unwrap(getJobPars())
if (is.null(setups$pisetup) | all(is.na(setups$pisetup))) {
  grepw <- grepl(pattern = "_w$", x = sim$algorithm) & sim$P > 2
  if (any(grepw)) {
    sim <- sim[-which(grepw),]
  }
}
runids <- sim$job.id

#----
# 7) check setup
#----
# check what has been created
print(summarizeExperiments(reg = reg, ids = runids))

#-----
# 8) submit jobs
#----
submitJobs(ids = runids)
waitForJobs()

#-----
# 9) save results
#----
res <- extract_results(reg)
saveRDS(res, file = RESNAME)

Try the tram package in your browser

Any scripts or data that you put into this service are public.

tram documentation built on Nov. 23, 2026, 5:07 p.m.