
Reliability and analysis diagnostics
Source:vignettes/reliability-diagnostics.Rmd
reliability-diagnostics.RmdAssess the information behind an analysis
Random-Effect Prediction Adjustment for Inference in Regression (REPAIR) reports posterior reliability for the random effects selected by the structural formula and provides tables of sample, prediction, and numerical diagnostics. These are descriptive checks, not automatic tests of whether an analysis is adequate. Numerical convergence alone does not establish strong information or reliable inference.
This executable example uses a synthetic reproduction dataset with unequal observation counts, AR(1) residual correlation, and phase-specific residual SDs. An ordinary analysis supplies its own MLMs and unit-level table.
case <- readRDS(system.file("extdata", "nlme-workflow-reference.rds",
package = "repair"))$cases$both_ar1_ident
measurement <- nlme::lme(y ~ z, random = ~ z | id, data = case$data,
correlation = nlme::corAR1(form = ~ time | id),
weights = nlme::varIdent(form = ~ 1 | phase),
control = nlme::lmeControl(msMaxIter = 300))
fit <- repair(re("z", "growth") ~ re("(Intercept)", "growth"),
list(growth = measurement), case$people, "id")
summary(fit)
#> REPAIR structural regression
#> re("z", "growth") ~ re("(Intercept)", "growth")
#> Units: 60 analyzed / 60 requested; 0 excluded
#> MLM: growth (nlme; group id; 0 IDs outside scope)
#> nlme singularity is not assessed; inspect the MLM fit and its fitting warnings.
#> Cross-model prediction errors: not applicable (one model)
#> Predictions: likelihood-only random deviations
#> model group term role
#> growth id z outcome
#> growth id (Intercept) predictor
#>
#> Posterior reliability (structural scope; equal unit weights):
#> model term role measure reliability n_units n_defined
#> growth z outcome marginal 0.759 60 60
#> growth z outcome residualized 0.703 60 60
#> growth (Intercept) predictor marginal 0.872 60 60
#>
#> estimate se zstat pval ci_low
#> (Intercept) -0.002612 0.1232 -0.02121 0.9831 -0.2440
#> re("(Intercept)", model = "growth") 0.118333 0.1269 0.93231 0.3512 -0.1304
#> ci_high
#> (Intercept) 0.2388
#> re("(Intercept)", model = "growth") 0.3671
#>
#> Regularization (preliminary / final): minimum / minimum
#> Error-moment subtraction multipliers: 0.95 / 0.95
#> Largest analysis-weight fraction: 0.0204 ; weight-equivalent count: 58.2
#> Moment conditioning and unit weights: repair_diagnostics(fit).
#> Conditional on fitted MLM parameters; model-based normal SEs and intervals.The summary labels effect roles so the predictor-side reliability emphasized in the paper is easy to identify. Reliability does not modify predictions, covariances, regularization, coefficients, or standard errors.
Two distinct uncertainty calculations
For a selected random effect k, marginal posterior reliability for person i is
Here G is the fitted random-effect covariance, Z_i is the effective random-effect design, and R_i is the fitted residual covariance. This calculation uses all random effects within that MLM. It supports a singular G without inverting it. It conditions on fitted parameters.
V_i is a posterior covariance. REPAIR’s structural estimator instead uses likelihood-only predictions and their sampling-error covariance. These are different quantities. Do not replace the estimator’s error inputs with posterior variances. A cluster with an unidentifiable likelihood-only slope can still have a defined posterior reliability because its posterior also uses G; that does not rescue its failed likelihood-only prediction for structural analysis.
For an intercept/slope model, the slope component residualized on the intercept is . With , its reliability is . This is the manuscript’s residualized diagnostic; it uses off-diagonal covariance and does not condition on other structural predictors or on another measurement process. It is available only for selected slopes in two-coefficient random-intercept/random-slope models in this release.
r <- repair_reliability(fit)
r[, c("model", "term", "role", "measure", "reliability", "n_units", "n_defined")]
#> model term role measure reliability n_units n_defined
#> 1 growth z outcome marginal 0.7587021 60 60
#> 2 growth z outcome residualized 0.7032858 60 60
#> 3 growth (Intercept) predictor marginal 0.8718890 60 60
person <- repair_reliability(fit, detail = "unit")
head(person[, c("id", "term", "measure", "n_observations", "prior_variance",
"posterior_variance", "reliability")])
#> id term measure n_observations prior_variance posterior_variance
#> 1 p01 z marginal 6 0.5961595 0.23788382
#> 2 p02 z marginal 7 0.5961595 0.14523820
#> 3 p03 z marginal 8 0.5961595 0.14044483
#> 4 p04 z marginal 9 0.5961595 0.08821424
#> 5 p05 z marginal 10 0.5961595 0.08592509
#> 6 p06 z marginal 11 0.5961595 0.05642756
#> reliability
#> 1 0.6009729
#> 2 0.7563770
#> 3 0.7644174
#> 4 0.8520291
#> 5 0.8558690
#> 6 0.9053482The default type = "both" reports marginal reliability
for every selected effect and residualized reliability where applicable.
type = "marginal" selects only marginal values. With
type = "residualized", an inapplicable selected effect
receives an explicit status and reason instead of disappearing.
Cohorts and undefined values
By default the scope consists of the analyzed units, equally weighted. The aggregate is the arithmetic mean of their unit-specific reliabilities, matching the manuscript’s empirical formula. It is not weighted by observation count or by the structural estimator’s inverse-variance weights.
# Compare the same MLM fit across different structural scopes.
subset_fit <- repair(re("z", "growth") ~ re("(Intercept)", "growth"),
list(growth = measurement), case$people[1:40, ], "id")
repair_reliability(subset_fit)[, c("term", "measure", "scope", "n_units", "reliability")]
#> term measure scope n_units reliability
#> 1 z marginal structural 40 0.7605593
#> 2 z residualized structural 40 0.7052565
#> 3 (Intercept) marginal structural 40 0.8718881
repair_reliability(subset_fit, scope = "all")[,
c("term", "measure", "scope", "n_units", "reliability")]
#> term measure scope n_units reliability
#> 1 z marginal all 60 0.7587021
#> 2 z residualized all 60 0.7032858
#> 3 (Intercept) marginal all 60 0.8718890scope = "all" includes all effective grouping levels,
separately for each referenced model. It can include people excluded
from structural analysis. In multiple-model analyses, analyzed-scope
summaries use the same units for all models; MLM-scope denominators may
differ. Reliability is computed within each MLM and does not borrow
information across models or infer anything from the cross-model
prediction-error policy.
A zero or numerically degenerate prior contrast variance makes the
reliability ratio undefined. Singularity of G alone does not make every
marginal ratio undefined. Rows record status and
reason; no undefined ratio is converted to zero
reliability. If any requested reliability is undefined, the overall
reliability is NA. mean_defined is a
separately labeled mean over defined values, with n_defined
and n_undefined exposing its denominator. Person-level rows
retain posterior computation failures. Tiny excursions beyond zero or
one within 1e-8 are rounded to the boundary; larger excursions remain
undefined with a reason. No substantive reliability cutoff is
imposed.
Plot heterogeneity
plot(person)
plot(person, type = "observations", pch = 19)
Panels identify model, coefficient, and measure. Subtitles identify the scope and defined/total counts. These plots do not imply that observation count alone determines reliability: time design, residual structure, and variance components also matter. Undefined rows are not drawn and remain visible in the counts.
Inspect structural diagnostics
d <- repair_diagnostics(fit)
d$scope
#> n_requested n_analyzed n_excluded
#> 1 60 60 0
d$mlm
#> model group backend singular n_levels n_outside_requested messages
#> 1 growth id nlme NA 60 0
d$excluded
#> [1] id reason
#> <0 rows> (or 0-length row.names)
d$prediction_failures
#> [1] model group id analyzed reason
#> <0 rows> (or 0-length row.names)
d$regularization
#> step policy alpha subtraction_multiplier regularized
#> 1 preliminary minimum 3 0.95 TRUE
#> 2 final minimum 3 0.95 TRUE
d$conditioning
#> step dimension min_eigenvalue max_eigenvalue condition_number
#> 1 preliminary 2 59.99969 67.17127 1.119527
#> 2 final 2 65.87229 74.70369 1.134068
d$weight_summary
#> n_units max_fraction weight_equivalent_n
#> 1 60 0.02043895 58.22499
head(d$weights)
#> id weight fraction
#> 1 p01 0.8387544 0.01272013
#> 2 p02 1.0908966 0.01654399
#> 3 p03 1.1054677 0.01676497
#> 4 p04 1.2540782 0.01901873
#> 5 p05 1.2611884 0.01912656
#> 6 p06 1.3477263 0.02043895
head(d$prediction_error_variances)
#> id term role variance
#> 1 p01 re("z", "growth") outcome 0.4915095
#> 2 p02 re("z", "growth") outcome 0.2303442
#> 3 p03 re("z", "growth") outcome 0.2193759
#> 4 p04 re("z", "growth") outcome 0.1206865
#> 5 p05 re("z", "growth") outcome 0.1167271
#> 6 p06 re("z", "growth") outcome 0.0711804-
scopeandexcludedexplain which people entered the structural fit.prediction_failuresidentifies the model, ID, reason, and inclusion status, including failed predictions outside the structural scope. -
prediction_error_varianceslists the input-scale likelihood-only error variances for structural outcomes and predictor columns. Observed variables have zero error under the model’s assumptions. Full covariances remain infit@analysis_data. -
regularizationshows policy, alpha, and the error-subtraction multiplier for each moment step. A multiplier of one means full error subtraction. Disabling regularization does not disable measurement-error correction. -
conditioningdescribes the preliminary and final corrected predictor moments, including the structural intercept. Condition numbers depend on predictor units; these raw values are not invariant adequacy predictions. A nonpositive minimum eigenvalue gives an infinite condition number. -
weightscontains analyzed IDs, inverse case-variance weights, and their fractions.weight_equivalent_n = 1 / sum(fraction^2)describes weight concentration; it is neither an inferential sample size nor degrees of freedom. -
reliabilitycontains the analyzed-scope reliability table, andcross_model_errorpreserves the policy and supplied blocks.
On numerical structural failure, status reports the
failed step and message. Measurement and scope diagnostics remain
usable. Structural diagnostic tables whose intermediate state is
unavailable have zero rows; they do not fabricate partial estimates.
These diagnostics do not propagate MLM or covariance-estimation
uncertainty and do not establish nominal coverage for a particular
dataset.
For a single diagnostic table, use
repair_diagnostics(fit, table = "weights") or another exact
table name. The existing list interface above remains available. Use
repair_coefficients(fit) for a structural reporting table,
repair_predictions(fit) for ID-keyed predictions and
sampling-error SDs, and repair_prediction_covariance(fit)
for correlated prediction errors. See
vignette("extracting-results") for safe joins between
prediction and reliability tables.
Reproducibility
Frozen reliability fixtures were generated without loading
repair, using the companion simulation’s posterior
covariance, marginal reliability, contrast reliability, and residualized
slope helpers. Tests refit balanced, unbalanced, and
AR(1)/heteroskedastic MLMs, and also check lmer posterior variances
against ranef(condVar = TRUE). Separate tests cover
singular priors, rank-deficient clusters, scope selection, multiple
models, failed structural fits, and reconstruction of structural moment
diagnostics. Existing REPAIR coefficient/SE reference tests remain
unchanged.