Random-Effect Prediction Adjustment for Inference in Regression (REPAIR) accounts for sampling error when estimated random effects are used as predictors, the outcome, or both in a second-stage regression.
Arguments
- formula
An additive structural formula with at least one
re()marker. Observed predictors may be numeric, logical, or factors. The outcome must be numeric or a random effect. An intercept is always included.- models
A fitted Gaussian
lme4::lmer()or linearnlme::lme()model, an experimentalrepair_bayes_plugin()snapshot, or named list. Bayesian support is restricted to the snapshot's documented scope; its structural inference conditions on posterior summaries, does not propagate step-1 uncertainty, and has unvalidated full-workflow coverage. Select one target grouping factor per model. Gaussian lmer models may also contain nuisance groups whose every fitted level belongs to exactly one target level; nlme models must have one grouping factor. Grouping column names may differ, but their values must identify the same units. Alternatively supply arepair_mlm()specification, or a named list mixing specifications and fitted models. Each specification is fitted once per call through its native engine before the usual validation and extraction.- data
A data frame with one row per analysis ID, containing the observed structural variables. Its ID values must match the model's grouping levels.
- id
Name of the ID column in
data; need not equal the grouping name.- na_action
"fail"(default) or"omit". Omission covers missing or nonfinite observed values, unmatched IDs, and failed prediction blocks; it warns and records every excluded ID and reason.- regularization
Moment regularization:
"minimum"(default),"none","step_up", or"custom"."none"still subtracts measurement error; it disables only stabilization. The same setting is used for preliminary and final moments.- alpha
Custom regularization constant, at least the number of structural predictor columns plus two. Required for
regularization = "custom".- backend
M-MOM computation backend:
"auto","r", or"rcpp".- cross_model_error
Cross-model prediction-error covariance policy. Default
NULLis valid only when the formula references one model. For multiple models, use"independent"to explicitly assume zero cross-model prediction extraction error covariance, or a list of blocks, one for every unordered model pair. Each block islist(models = c("a", "b"), covariance = array(...)). The numeric array must have three named dimensions: coefficient names from model a, coefficient names from model b, and unit IDs. Term names must exactly cover the effects selected from those models. Every retained ID must be present; extra IDs are allowed. Order does not matter. Values are covariances of likelihood-only prediction errors, not latent coefficients or raw observations. The assembled covariance must be positive semidefinite. Missing/invalid supplied blocks are errors even withna_action = "omit".- step_up_control
Named list of search settings for
regularization = "step_up". Seefit_mmom()for defaults, guards, and fallback behavior. The same search settings are used in both stages; the selected alphas can differ.
Value
An S7 class_repair_mod with @mlm_fit, @struc_fit, and
inspectable @analysis_data. Use summary(), coef(), vcov(),
confint(), and nobs() for standard output.
Details
Select random effects with re(), match them to unit-level data by
ID, and fit the modified method-of-moments (M-MOM) regression. MLMs can be
fitted beforehand or supplied as explicit
repair_mlm() specifications for fitting during this call.
The supported structural grammar is additive with an intercept.
Effects may come from multiple Gaussian lmer or linear lme models, each with
one target grouping factor. Gaussian lmer models may have nuisance groups
entirely contained within targets; shared nuisance levels are rejected.
Full within-unit prediction-error covariance is retained.
Experimental Bayesian measurement fits require an explicit
repair_bayes_plugin() snapshot; see its restrictions and inference limits.
Multiple models require an explicit cross_model_error policy; separate
fits do not establish independent prediction errors. See repair_data().
Observed variables are treated as measured without error. Predictions are random
deviations, not fixed-plus-random individual coefficients. For nlme fits,
supported residual structures and stored-data requirements are described
in repair_ranef_gls(). Use repair_refit() to verify and replay one
MLM with explicit reference/replacement data.
Standard errors condition on fitted MLM quantities and use
the modified final predictor moment (the manuscript M-MOM calculation).
They assume the model-based normal-error covariance; MLM
parameter uncertainty is not propagated. Intervals and tests use normal
reference distributions. Numerical fitting failures return a result with
@struc_fit@converged = FALSE and issue a warning.
Examples
growth <- lme4::lmer(Reaction ~ Days + (Days | Subject), lme4::sleepstudy)
people <- data.frame(Subject = levels(lme4::sleepstudy$Subject),
observed = seq_len(18))
repair_effects(list(growth = growth))
#> model group term n_levels
#> 1 growth Subject (Intercept) 18
#> 2 growth Subject Days 18
fit <- repair(re("Days", model = "growth") ~ observed,
models = list(growth = growth), data = people, id = "Subject")
summary(fit)
#> REPAIR structural regression
#> re("Days", model = "growth") ~ observed
#> Units: 18 analyzed / 18 requested; 0 excluded
#> MLM: growth (lme4; group Subject; 0 IDs outside scope)
#> Cross-model prediction errors: not applicable (one model)
#> Predictions: likelihood-only random deviations
#> model group term role
#> growth Subject Days outcome
#>
#> Posterior reliability (structural scope; equal unit weights):
#> model term role measure reliability n_units n_defined
#> growth Days outcome marginal 0.849 18 18
#> growth Days outcome residualized 0.828 18 18
#>
#> estimate se zstat pval ci_low ci_high
#> (Intercept) -2.9721 3.215 -0.9245 0.3552 -9.2729 3.3287
#> observed 0.3129 0.297 1.0534 0.2922 -0.2692 0.8949
#>
#> Regularization (preliminary / final): minimum / minimum
#> Error-moment subtraction multipliers: 0.8333 / 0.8333
#> Largest analysis-weight fraction: 0.0556 ; weight-equivalent count: 18
#> Moment conditioning and unit weights: repair_diagnostics(fit).
#> Conditional on fitted MLM parameters; model-based normal SEs and intervals.
confint(fit)
#> 2.5 % 97.5 %
#> (Intercept) -9.272872 3.3286569
#> observed -0.269238 0.8949449
