Describe a Gaussian MLM to fit when repair(), repair_data(), or
repair_effects() consumes it. Construction does not fit a model.
Usage
repair_mlm(formula, data, engine = c("lmer", "lme"), ...)Arguments
- formula
A two-sided formula. For
engine = "lmer", include random effects using lme4 syntax. Forengine = "lme", this is the fixed-effects formula; supplyrandomseparately in....- data
A nonempty repeated-observation data frame. This is separate from the one-row-per-unit structural
datasupplied torepair().- engine
Native fitter:
"lmer"(default) or"lme".- ...
Fully named arguments to the selected native fitter, such as
REML,method,random,control,contrasts,weights,offset,correlation,subset, orna.action, as supported by that fitter. For lmer,weights,offset, andsubsetuse native data expressions; for lme,subsetdoes. Other arguments are evaluated at construction.
Value
An unfitted repair_mlm_spec specification, accepted wherever REPAIR
accepts measurement models. Its print method displays the formula, engine,
observation count and supplied argument names without fitting.
Details
Pass a specification directly as models, or combine specifications
and fitted models in a uniquely named list. A bare specification is named
mlm. Each consuming call fits its specifications once. Reuse the fitted
models in a result's @mlm_fit to avoid fitting again during discovery or
another structural analysis.
Fitting uses lme4::lmer() or nlme::lme() with native defaults, controls,
warnings and errors; no optimizer retries or model selection are added.
Formula and data are retained in the specification. For lme, random is
required and keep.data = FALSE is rejected because prediction extraction
needs the data. The optional nlme package is required for that engine.
Existing Gaussian-model, grouping, residual-structure, structural-scope and
cross-model covariance restrictions still apply. This helper changes neither
the structural estimator nor its inference.
Results contain ordinary fitted models with explicit fitting arguments and
a retained data binding. repair_refit() and repair_bootstrap() still
require the original repeated and structural data explicitly, and retain
their single-model and reference-replay checks. Data-only expressions and
supported formulas can use native replay. External vectors, custom formula
dependencies and other unsupported recipes still require an explicit
refitter. This helper does not turn an arbitrary R expression into a
portable replay recipe.
Examples
data(repair_example)
growth <- repair_mlm(score ~ day + (day | person),
repair_example$repeated, REML = TRUE)
fit <- repair(re("day", "growth") ~ practice, list(growth = growth),
repair_example$people, "person")
repair_coefficients(fit)
#> term estimate std.error statistic p.value conf.low conf.high
#> 1 (Intercept) -0.7895289 0.1147252 -6.881913 5.905407e-12 -1.0143862 -0.5646716
#> 2 practice 0.1754854 0.0214190 8.192979 2.548385e-16 0.1335049 0.2174659
#> conf.level
#> 1 0.95
#> 2 0.95
if (requireNamespace("nlme", quietly = TRUE)) {
growth_lme <- repair_mlm(score ~ day, repair_example$repeated,
engine = "lme", random = ~ day | person)
repair_effects(list(growth = growth_lme))
}
#> model group term n_levels
#> 1 growth person (Intercept) 60
#> 2 growth person day 60
