Captures named expressions, unevaluated, to be evaluated inside the
simulated data. They are used for the init_recode, in_recode
and out_recode hooks of gformula and
mediation, and for the recode argument of
spec_model. Expressions are evaluated in order, so a later one
can use the result of an earlier one.
The simulated cohort starts with only the subject identifier and the baseline covariates, so every lag, counter or other derived variable a model uses must be created here, even if it already exists in the data:
init_recode: at the first time step, before the models are evaluated (initial values).in_recode: at the start of every later time step, before the models are evaluated (lags, functions of time).out_recode: at the end of every time step, the first included, after the models are evaluated (cumulative counts, carrying an absorbing state forward). A variable it updates needs a starting value frominit_recode.
Examples
# One-period lags: 0 at the first time step, then the previous value
init <- recodes(lag1_A = 0, lag1_L = 0)
upd <- recodes(lag1_A = A, lag1_L = L)
# A function of the time variable, e.g. for in_recode
recodes(day_sq = day^2)
#> $day_sq
#> day^2
#>
#> attr(,"class")
#> [1] "causalMed_recodes" "list"
# A running count of exposed steps: start at 0 (init_recode), add the
# current step's exposure at the end of each step (out_recode)
init <- recodes(cum_A = 0)
upd <- recodes(cum_A = cum_A + A)