update_sim: Update a simulation

View source: R/update_sim.R

update_simR Documentation

Update a simulation


This function updates a previously run simulation. After a simulation has been run, you can alter the levels of the resulting object of class sim_obj using set_levels, or change the configuration (including the number of simulation replicates) using set_config. Executing update_sim on this simulation object will only run the added levels/replicates, without repeating anything that has already been run.


update_sim(sim, keep_errors = TRUE, keep_extra = FALSE)



A simulation object of class sim_obj, usually created by new_sim, that has already been run by the run function


logical (TRUE by default); if TRUE, do not try to re-run simulation reps that results in errors previously; if FALSE, attempt to run those reps again


logical (FALSE by default); if TRUE, keep previously run simulation reps even if they exceed the current num_sim in config or are from a level that has been dropped; if FALSE, drop excess reps (starting from the last rep for that particular simulation level)


  • It is not possible to add new level variables, only new levels of the existing variables. Because of this, it is best practice to include all potential level variables before initially running a simulation, even if some of them only contain a single level. This way, additional levels can be added later.

  • In general, if num_sim has been reduced prior to running update_sim, it is best to use the default option keep_extra = FALSE. Otherwise, some simulation levels will have more replicates than others, which makes comparison difficult.


The original simulation object with additional simulation replicates in results or errors


sim <- new_sim()
create_data <- function(n) { rpois(n, lambda=5) }
est_mean <- function(dat, type) {
  if (type=="M") { return(mean(dat)) }
  if (type=="V") { return(var(dat)) }
sim %<>% set_levels(n=c(10,100), est="M")
sim %<>% set_config(num_sim=10)
sim %<>% set_script(function() {
  dat <- create_data(L$n)
  lambda_hat <- est_mean(dat=dat, type=L$est)
  return (list("lambda_hat"=lambda_hat))
sim %<>% run()
sim %<>% set_levels(n=c(10,100,1000), est=c("M","V"))
sim %<>% set_config(num_sim=5)
sim %<>% update_sim()

Avi-Kenny/SimEngine documentation built on June 23, 2022, 11:09 a.m.