Skip to contents

Replay one MLM and the complete structural analysis using explicit reference inputs. Optional replacement inputs or a deterministic whole-unit draw are fitted only after identity replay succeeds. This is a refitting tool, not a bootstrap inference engine.

Usage

repair_refit(
  object,
  mlm_data,
  data,
  new_mlm_data = NULL,
  new_data = NULL,
  id = NULL,
  refitter = NULL,
  draw = NULL,
  tolerance = 1e-06
)

Arguments

object

A converged repair() fit using one MLM.

mlm_data

Reference repeated-observation data, as a data frame or one-element list named like the fitted model. Retain original fitted row names. Rows excluded from the original MLM fit are filtered by those names.

data

Original unit-level data, including requested/excluded unit rows.

new_mlm_data

Optional replacement effective repeated observations. Every supplied row must be used; implicit subset or omission is rejected.

new_data

Optional replacement unit-level data. Every requested unit must be complete; the original coefficient schema must remain estimable.

id

Structural ID column; defaults to the original ID column and must match it.

refitter

Optional deterministic function of one data frame returning a fitted lmer/lme model. Required for nonliteral control objects or unsupported formula/argument dependencies. Its reference replay is subject to the same checks.

draw

Optional character vector of analyzed source IDs, with repeats allowed. Copy whole people and assign fresh target/nuisance identities. Cannot be combined with replacement data; no randomness or intervals are generated.

tolerance

Positive finite numerical tolerance for identity replay; default 1e-6. Identity/schema/scope checks are exact.

Value

An ordinary fitted REPAIR object, with a reference/replacement audit in summary(result)$refit. Original conditional SEs remain conditional; no bootstrap uncertainty or coverage claim is added.

Details

Native adapters rebuild supported Gaussian lmer and single-group lme fits using data-only formulas, weights/offsets, literal fitting constructors, recorded ML/REML, and fixed factor coding. They do not evaluate original data or subset expressions in the caller's environment. Reference fitting uses the original effective rows; replacements require explicit complete rows. Symbolic controls and other external dependencies require refitter. Recorded control recipes are compared exactly; lmer also retains optimizer settings. Unrecoverable nlme options are the callback author's explicit declaration, identified as callback_declared in the audit.

Original-data replay checks effective observations, designs, weights/offsets, covariance, predictions, structural inputs, coefficients and their covariance. Measurement convergence, specification, and coefficient identities are checked again for replacements. Singular but usable MLM fits are retained. Warnings/messages are recorded in summary(result)$refit; fitting errors stop. Original structural formula, regularization and computation backend are retained.

draw requires matching MLM/structural scopes and a bare target ID. Nuisance IDs must be bare columns or grouping expressions containing that ID. Shared nuisance groups are rejected by the ordinary structural validator. See vignette("refitting", package = "repair") for scope and examples.

Examples

data(repair_example)
growth <- lme4::lmer(score ~ day + (day | person), repair_example$repeated)
fit <- repair(re("day") ~ practice, growth, repair_example$people, "person")
replay <- repair_refit(fit, repair_example$repeated, repair_example$people)
repair_coefficients(replay)
#>          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
summary(replay)$refit$checks
#>       stage n_rows n_requested n_analyzed           controls verified
#> 1 reference    586          60         60 recorded_optimizer     TRUE