Skip to contents

Simulate baseline data with survival outcomes

Usage

simulate_survival(
  n,
  specification,
  covariates = NULL,
  id = "id",
  seed = NULL,
  digits = NULL,
  envir = parent.frame(),
  batch = NULL
)

Arguments

n

Number of observations.

specification

Survival definitions from define_survivals(), in either the hazard() call form or the column form.

covariates

Optional baseline base data.frame with n rows.

id

Identifier name used when covariates are omitted. Defaults to "id" and is ignored when covariates is supplied.

seed, digits, envir

Arguments passed to augment_survival().

batch

Optional single positive whole number. When given, the simulator runs batch times and returns a plain list of batch results, each exactly what the same call without batch returns. With a seed, every dataset gets its own seed drawn from seed, so the whole batch is reproducible; without one the datasets are consecutive draws from the session's random-number stream. The default NULL returns a single result.

Value

A simulab_sim base data.frame with one row per simulated subject: the identifier (or the supplied covariates) followed by one column per event defined in specification. The survival_definitions component holds the specification that generated it.

Examples

result <- simulate_survival(
  n = 100,
  specification = define_survivals(define_survival("time", formula = -8, shape = 0.3)),
  seed = 1
)
head(result)
#> <simulab_sim:survival> 6 rows x 2 columns
#>   id      time
#> 1  1 11.997214
#> 2  2 10.985087
#> 3  3  9.248955
#> 4  4  5.462235
#> 5  5 12.694901
#> 6  6  5.640350
#> 
#> Truth (survival_definitions):
#>   event formula scale shape transition
#> 1  time      -8     1   0.3          0

# A hazard call states the same process, with the log rate as an expression.
head(simulate_survival(
  n = 100,
  specification = define_survivals(time = hazard(log_rate = -8, shape = 0.3)),
  seed = 1
))
#> <simulab_sim:survival> 6 rows x 2 columns
#>   id      time
#> 1  1 11.997214
#> 2  2 10.985087
#> 3  3  9.248955
#> 4  4  5.462235
#> 5  5 12.694901
#> 6  6  5.640350
#> 
#> Truth (survival_definitions):
#>   event formula scale shape transition
#> 1  time      -8     1   0.3          0