simulate_until_event: Simulate events and retain records through the nth event

View source: R/sequences.R

simulate_until_eventR Documentation

Simulate events and retain records through the nth event

Description

Simulate events and retain records through the nth event

Usage

simulate_until_event(
  data,
  definition,
  occurrence = 1L,
  id = "id",
  period = "period",
  seed = NULL,
  envir = parent.frame(),
  batch = NULL
)

Arguments

data

Long-form base data.frame.

definition

One binary variable definition from define_variable().

occurrence, id, period

Event trimming arguments.

seed

Optional random seed.

envir

Formula evaluation environment.

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 the generated event indicator and records through the requested occurrence.

Examples

# Long-form input: one row per unit per period.
data <- expand_periods(data.frame(id = 1:30), periods = 8,
                       id = "id", period = "period")

result <- simulate_until_event(
  data,
  definition = define_variable("event", formula = "0.3", distribution = "binary"),
  occurrence = 1,
  seed = 1
)
head(result)

simulab documentation built on Oct. 15, 2026, 5:08 p.m.