set_levels {SimEngine} | R Documentation |
Set simulation levels
Description
Set one or more simulation levels, which are things that vary between simulation replicates.
Usage
set_levels(sim, ..., .keep = NA)
Arguments
sim | A simulation object of class sim_obj, usually created by new_sim |
... | One or more key-value pairs representing simulation levels. Each value can either be a vector (for simple levels) or a list of lists (for more complex levels). See examples. |
.keep | An integer vector specifying which level combinations to keep; see examples. |
Value
The original simulation object with the old set of levels replaced with the new set
Examples
# Basic usage is as follows:
sim <- new_sim()
sim %<>% set_levels(
"n" = c(10, 100, 1000),
"theta" = c(2, 3)
)
sim$levels
# More complex levels can be set using lists:
sim <- new_sim()
sim %<>% set_levels(
"n" = c(10, 100, 1000),
"theta" = c(2, 3),
"method" = list(
"spline1" = list(knots=c(2,4), slopes=c(0.1,0.4)),
"spline2" = list(knots=c(1,5), slopes=c(0.2,0.3))
)
)
sim$levels
# If you don't want to run simulations for all level combinations, use the
# .keep option. First, set the levels normally. Second, view the
# sim$levels_grid dataframe to examine the level combinations and the
# associated level_id values. Third, call set_levels again with the .keep
# option to specify which levels to keep (via a vector of level_id values).
sim <- new_sim()
sim %<>% set_levels(alpha=c(1,2,3), beta=c(5,6))
sim$levels_grid
sim %<>% set_levels(.keep=c(1,2,6))
sim$levels_grid
[Package SimEngine version 1.2.0 ]