Convert an simulate_data() result with a gen_outcome() generator into an
analysis-ready data set and inferred brms formula. The helper recomputes
observed between- and within-person predictors from the raw simulated
columns, creates within-person centered lag columns for ar1() terms, and
creates a complr() object when the outcome is compositional.
Arguments
- sim
An
mlsim_dataobject returned bysimulate_data().- outcome
Optional character scalar naming the outcome generator. When
NULL, the helper uses the only generator withdistribution = "outcome".- drop_lag_na
Logical scalar. When
FALSE, the default, first rows in each series are retained and lag-derived columns are left asNA. WhenTRUE, rows with missing lag-derived predictors are removed.
Value
An mlsim_analysis object, a list with:
dataAnalysis data with derived between/within and lag columns.
formulaAn inferred
brmsformula.complrA
complrobject for compositional outcomes, otherwiseNULL.metadataPreparation metadata, including derived column names and formula mappings.
Details
The analysis formula is inferred from the stored gen_outcome() formula.
Simulation terms between(x) and within(x) become observed-data columns
named x_between and x_within, computed from x by the simulation group
identifier. These columns are recomputed even when columns with the same
names already exist in sim$data.
For dynamic formulas, ar1() is translated to within-person centered lag
predictors. For compositional outcomes, the helper rebuilds the ILR
coordinates through complr() using the simulator's parts and SBP metadata,
then lags the generated z coordinates used by brmcoda().
Examples
params <- list(
location = list(beta = matrix(0, nrow = 1, dimnames = list("(Intercept)", "y"))),
scale = list(beta = matrix(log(0.2), nrow = 1, dimnames = list("(Intercept)", "y")))
)
sim <- simulate_data(
n = 5,
seed = 1,
generators = list(
outcome = gen_outcome(
y ~ 1,
scale = sigma ~ 1,
params = params,
burnin = 0
)
)
)
analysis <- prep_sim_analysis(sim)
analysis$formula
#> y ~ 1
#> sigma ~ 1