set_levels: Set simulation levels

View source: R/set_levels.R

set_levelsR 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
#>   level_id alpha beta
#> 1        1     1    5
#> 2        2     2    5
#> 3        3     3    5
#> 4        4     1    6
#> 5        5     2    6
#> 6        6     3    6
sim %<>% set_levels(.keep=c(1,2,6))
sim$levels_grid
#>   level_id alpha beta
#> 1        1     1    5
#> 2        2     2    5
#> 6        6     3    6

Avi-Kenny/SimEngine documentation built on March 16, 2024, 4:34 p.m.