Skip to contents

Start with a complete teaching example

repair_example contains entirely synthetic daily learning scores and prior practice hours for 60 people. It is not a real study or a reproduction of the paper’s Monte Carlo results. Its help page describes the generating model and its known coefficients; those generating values are not inputs to the analysis.

data(repair_example)
head(repair_example$repeated)
#>   person day    score
#> 1   P001   0 57.78002
#> 2   P001   1 57.80489
#> 3   P001   2 58.22970
#> 4   P001   3 60.11052
#> 5   P001   4 62.93869
#> 6   P001   5 63.15122
head(repair_example$people)
#>   person practice
#> 1   P001      6.7
#> 2   P002      8.7
#> 3   P003      4.7
#> 4   P004      9.5
#> 5   P005      7.9
#> 6   P006      1.9
growth <- lme4::lmer(score ~ day + (day | person), repair_example$repeated)
models <- list(growth = growth)
repair_effects(models)
#>    model  group        term n_levels
#> 1 growth person (Intercept)       60
#> 2 growth person         day       60

analysis <- repair_data(
  re("day", model = "growth") ~ practice,
  models, repair_example$people, id = "person"
)
head(repair_predictions(analysis))
#>     id  model  group term                       label    role prediction
#> 1 P001 growth person  day re("day", model = "growth") outcome  0.4451909
#> 2 P002 growth person  day re("day", model = "growth") outcome  0.4105728
#> 3 P003 growth person  day re("day", model = "growth") outcome -0.4013259
#> 4 P004 growth person  day re("day", model = "growth") outcome  0.6289102
#> 5 P005 growth person  day re("day", model = "growth") outcome  0.6052267
#> 6 P006 growth person  day re("day", model = "growth") outcome -1.2120879
#>   std.error prediction.error.variance      scope analyzed status reason
#> 1 0.1401763                0.01964941 structural     TRUE     ok       
#> 2 0.1401763                0.01964941 structural     TRUE     ok       
#> 3 0.2268540                0.05146273 structural     TRUE     ok       
#> 4 0.1618617                0.02619921 structural     TRUE     ok       
#> 5 0.1401763                0.01964941 structural     TRUE     ok       
#> 6 0.2268540                0.05146273 structural     TRUE     ok

fit <- repair(
  re("day", model = "growth") ~ practice,
  models, repair_example$people, id = "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
repair_diagnostics(fit, table = "scope")
#>   n_requested n_analyzed n_excluded
#> 1          60         60          0

The practice coefficient describes the association between one extra hour of prior practice and the random learning slope, in score units per day. re("day") selects a deviation from the fitted fixed slope, not the raw score or the fixed-plus-random slope. The generating association is 0.18; one simulated sample need not reproduce it exactly. This is an association, not evidence of causation.

repair_effects() discovers usable names; repair_data() aligns and exposes inputs; repair() fits the structural model. For the full sequence, formula examples, and regularization choices, see vignette("repair-workflow").

Support matrix

This matrix is the current user-facing support boundary. Historical development audits describe the scope at the time they were written.

Component Supported Boundary or assumption
lme4 MLM Gaussian lmer() with one target grouping factor, including independent target blocks and nuisance groups contained within targets GLMMs and nuisance levels shared across targets are rejected; see vignette("nested-nuisance")
nlme MLM Linear lme() with one grouping factor and retained effective data (keep.data = TRUE) Nonlinear or multilevel lme fits are rejected
Experimental Bayesian MLM Explicit repair_bayes_plugin() snapshots of sampled brms/rstanarm Gaussian identity-link fits; additive numeric columns, one random block, constant independent residual variance Plug-in summaries only; no step-1 uncertainty propagation, Bayesian structural posterior, or established full-refitted-workflow coverage. See vignette("bayesian-plugin") for exclusions
nlme residual correlation Independent, corAR1, corCAR1; internal ARMA(1,0) representation of AR(1) Correlation grouping must match random-effects grouping; other structures are unsupported
nlme residual variance Constant, varIdent, varPower, including supported fitted-value covariates Other variance structures are rejected; see vignette("nlme-workflow")
Structural equation Additive regression with an intercept; random effects on either side At least one predictor and one re() reference; no random-effect interactions, nonlinear transformations, offsets, ., or joint equations
Observed structural variables Numeric outcome; numeric/logical/factor predictors Treated as measured without error; precompute observed transformations and explicitly convert character categories to factors
Multiple MLMs Named fits with model-qualified effects and ID matching Explicit independent-error or supplied prediction-error covariance policy; separate fitting does not establish independence
IDs and missingness One structural row per unit; character-value ID matching; explicit na_action = "omit" audit Duplicate/missing/empty IDs always fail; default is to stop on incomplete inputs
Estimation Modified method of moments with minimum, none, step_up, or custom regularization, using R or Rcpp none still subtracts measurement error; step-up records selected constants and whether its conditioning criteria were met
Structural inference Conditional model-based SEs and normal intervals/tests Does not propagate fitted measurement-parameter or estimated supplied-block uncertainty; no robust-sandwich option
Experimental bootstrap Whole-person sampling, empirical covariance and marginal percentile intervals through repair_refit() One model, coinciding cohorts; failures retained and inference withheld by default; coverage validation outstanding
Reliability Marginal posterior reliability; intercept-residualized slope reliability for two-coefficient intercept/slope models Plug-in diagnostics with explicit undefined cases; no automatic adequacy cutoff or reliability CI
Dependence between people Independent structural analysis people Contained nuisance levels preserve conditional independence; shared nuisance levels remain rejected because their cross-person error covariance cannot enter the estimator

For multiple models and covariance input formats, see vignette("multiple-models"). Keep the within-model joint covariance even when choosing cross-model independent errors. repair_prediction_covariance(fit) exposes what actually enters the estimator.

Three kinds of uncertainty

Quantity Interface Meaning
Likelihood-only sampling error repair_predictions(), repair_prediction_covariance() Error in estimated unit-specific random effects, conditional on fitted MLM quantities
Posterior reliability repair_reliability() Reduction in uncertainty under the fitted MLM relative to its prior random-effect variance
Structural coefficient uncertainty vcov(), confint(), repair_coefficients() Conditional model-based uncertainty in the structural regression coefficients

A BLUP’s posterior covariance cannot replace likelihood-only sampling-error covariance. Neither successful computation nor high reliability establishes nominal interval coverage. Small samples, weak information, and correlated effects require particular care and analysis-specific simulation; no universal diagnostic cutoff is imposed. MLM adequacy must be assessed with the usual lme4/nlme tools before interpreting structural estimates.

Diagnose before changing an analysis

repair_diagnostics(fit, table = "status")
#>   converged     step message
#> 1      TRUE complete      ok
repair_diagnostics(fit, table = "mlm")
#>    model  group backend singular n_levels n_outside_requested messages
#> 1 growth person    lme4    FALSE       60                   0
repair_diagnostics(fit, table = "conditioning")
#>          step dimension min_eigenvalue max_eigenvalue condition_number
#> 1 preliminary         2       17.52838       1747.322         99.68531
#> 2       final         2       74.13875       7551.600        101.85768
repair_diagnostics(fit, table = "weight_summary")
#>   n_units max_fraction weight_equivalent_n
#> 1      60   0.01788085            59.82168
repair_reliability(fit)[, c("term", "measure", "reliability", "n_defined")]
#>   term      measure reliability n_defined
#> 1  day     marginal   0.9433813        60
#> 2  day residualized   0.8967932        60
Message or finding Inspect Appropriate next step
Unknown/ambiguous random-effect reference repair_effects(models) Use the exact scalar coefficient name, model qualifier, and target group if needed; factor slopes can expand to multiple coefficients
Shared nuisance levels across target people Measurement grouping membership on all effective fitted rows Correct genuinely local occasion IDs if appropriate to the design; structural omission cannot waive this restriction, and truly shared effects require a different analysis
Duplicate, missing, or empty structural IDs The ID column in the person table Correct identity/aggregation upstream; row order or automatic deduplication is not a matching strategy
ID absent from a MLM or missing structural value Original IDs/variables; the exclusion table if omission was requested Resolve the mismatch or make an explicit, substantively justified scope decision
Likelihood-only predictions failed Measurement records and within-unit design; prediction_failures when a fit/assembly exists Check sufficient within-unit predictor variation and design rank; do not substitute a BLUP or zero covariance
Singular MLM fit lme4 convergence/singularity diagnostics and substantive model specification Singularity is different from a rank-deficient person design and does not automatically prevent direct prediction extraction; assess whether the MLM is defensible
Missing nlme variance-parameter uncertainty information nlme model messages and model adequacy This message is not by itself a convergence test or evidence that all predictions are invalid
Structural design is rank-deficient Redundant/constant predictors, factor expansion, and the selected scope Correct the intended specification; do not silently delete estimated terms
Structural fit failed numerically repair_diagnostics(fit, "status"), prediction error variances and available conditioning diagnostics Investigate information and the model; failed fits remain inspectable, while coefficient/CI accessors refuse invalid estimates
Concentrated weights or poorly conditioned corrected moments weights, weight_summary, conditioning, and variable units Examine influential information patterns and design adequacy; weight-equivalent count is not an inferential sample size
Undefined reliability status, reason, n_defined, and n_undefined in reliability output Distinguish zero/degenerate variance from missing information; do not reinterpret undefined reliability as zero
Multiple models without a covariance policy The substantive measurement-error design Supply justified covariance blocks or explicitly justify independent prediction errors; do not choose independence merely to remove an error

If input validation stops before an analysis object exists, inspect the original data and MLM fits. A diagnostics extractor cannot recover an object that was never created. When a numerical structural fit fails after assembly, measurement/scope diagnostics remain available; unavailable structural tables are empty and the status table identifies the failure.

Make omissions explicit

people <- repair_example$people
people$practice[2] <- NA_real_
# The default would stop. Here we deliberately request and inspect the omission.
complete <- repair(re("day") ~ practice, growth, people, "person", na_action = "omit")
#> Warning: Omitting 1 analysis row(s); inspect `@diagnostics$excluded`.
repair_diagnostics(complete, table = "excluded")
#>     id                                       reason
#> 1 P002 missing/nonfinite observed variable practice
nobs(complete)
#> [1] 59

The warning and exclusion audit document an analysis choice. Omitting incomplete people is not a correction for informative missingness. Do not repeatedly discard people or alter error covariance until a desirable coefficient appears.

Save results and record the environment

path <- tempfile(fileext = ".rds")
saveRDS(fit, path)
restored <- readRDS(path)
repair_coefficients(restored)
#>          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
unlink(path)

In a new R session, load library(repair) before using a restored object. The package tests saved single- and multiple-model fits in a fresh R process with the same installed package/dependency versions. This is not a guarantee of S7 object compatibility across future package versions. Keep the analysis code, original data, packageVersion("repair"), and sessionInfo() with a saved analysis. For long-term reporting, also export the plain tables shown in vignette("extracting-results"); retain covariance when exporting predictions for reuse.

Verify a changed analysis

For one supported MLM, repair_refit() verifies the original data and fitting recipe before accepting replacements or deterministic person draws. It checks identities, coding and outputs, captures warnings, and rejects implicit replacement-row omission. See vignette("refitting"). Its current coefficient SEs remain conditional. repair_bootstrap() adds separate experimental person-level sampling and percentile intervals; see vignette("person-bootstrap") for the failure policy, seed contract, cohort restrictions, and inferential limits.

Interface stability and reporting

The high-level fit/assembly functions, standard generics, and documented table schemas are the supported routine workflow. fit_mmom() and repair_ranef_gls() are advanced interfaces requiring correct error inputs and assumptions. The exported class_repair_mod is available for type checks/advanced integration; its internal properties are not a substitute for the stable table interfaces. Construct ordinary fits through repair().

Reports should identify the MLM specifications, structural equation, scope and omissions, cross-model covariance policy, regularization settings, coefficient units, and conditional nature of inference. Record the software version and use citation("repair") to distinguish software and method citations. Zachary A. Vig and Michael N. Hallquist are package authors and co-maintainers; Zach is the primary R package maintainer contact. Report reproducible problems at https://github.com/HallquistLab/repair/issues, with a small synthetic example and session information rather than identifiable participant data.