R/group_data.R
genNthEvent.Rd
Generate event data using longitudinal data, and restrict output to time until the nth event.
genNthEvent(dtName, defEvent, nEvents = 1, perName = "period", id = "id")
name of existing data table
data definition table (created with defDataAdd) that determines the event generating process.
maximum number of events that will be generated (the nth event).
variable name for period field. Defaults to "period"
string representing name of the id field in table specified by dtName
data.table that stops after "nEvents" are reached.
defD <- defData(
varname = "effect", formula = 0, variance = 1,
dist = "normal"
)
defE <- defDataAdd(
varname = "died", formula = "-2.5 + 0.3*period + effect",
dist = "binary", link = "logit"
)
d <- genData(1000, defD)
d <- addPeriods(d, 10)
dx <- genNthEvent(d, defEvent = defE, nEvents = 3)