sim: Start simulation

Description Usage Arguments Details Value Examples

View source: R/01-sim.R

Description

This function will start the simulation. Use the printing method as long as you are testing the scenario.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sim(
  x,
  R = 1,
  path = NULL,
  overwrite = TRUE,
  ...,
  suffix = NULL,
  fileExt = ".csv",
  libs = NULL,
  exports = NULL
)

Arguments

x

a sim_setup

R

number of repetitions.

path

optional path in which the simulation results can be saved. They will we coerced to a data.frame and then saved as 'csv'.

overwrite

TRUE/FALSE. If TRUE files in path are replaced. If FALSE files in path are not replaced and simulation will not be recomputed.

...

arguments passed to parallelStart.

suffix

an optional suffix of file names.

fileExt

the file extension. Default is ".csv" - alternative it can be ".RData".

libs

arguments passed to parallelLibrary. Will be used in a call to do.call after coersion with as.list.

exports

arguments passed to parallelExport. Will be used in a call to do.call after coersion with as.list.

Details

The package parallelMap is utilized as back-end for parallel computations.

Use the argument path to store the simulation results in a directory. This may be a good idea for long running simulations and for those using large data.frames. You can use sim_read_data to read them in. The return value will change to NULL in each run.

Value

The return value is a list. The elements are the results of each simulation run, typically of class data.frame. In case you specified path, each element is NULL.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
setup <- sim_base_lm()
resultList <- sim(setup, R = 1)

# For parallel computations you may need to export objects
localFun <- function() cat("Hello World!")
comp_fun <- function(dat) {
  localFun()
  dat
}

res <- sim_base_lm() %>% 
  sim_comp_pop(comp_fun) %>% 
  sim(R = 2, 
      mode = "socket", cpus = 2,
      exports = "localFun")

str(res)

wahani/saeSim documentation built on Feb. 12, 2022, 7:21 p.m.