Skip to contents

Compute target-specific GLS predictions after subtracting fitted fixed effects and offsets. The target covariance excludes the target random effects and includes residual and nuisance-group covariance contributions.

Usage

repair_ranef_gls(mlm, target_group = NULL, include_fixed = FALSE)

Arguments

mlm

A Gaussian lme4::lmer() or nlme::lme() fit, or an experimental repair_bayes_plugin() snapshot.

target_group

Grouping factor for prediction extraction; NULL predicts all groups.

include_fixed

Add matching fixed coefficients to the predictions. Default FALSE gives deviations. TRUE requires a fixed coefficient for every random coefficient; it does not reconstruct covariate-dependent individual effects.

Value

An S7 prediction object with group-keyed @predictions matrices (ID by coefficient), @prediction_error_covariance arrays (coefficient by coefficient by ID), @levels, @terms, and @diagnostics; @success is true only if all selected clusters predicted successfully. These are sampling-error covariances, not posterior BLUP covariances.

Details

Failed clusters have missing predictions and covariance blocks, issue a warning, and appear in @diagnostics[[group]]$failed_levels. A singular random-effect covariance is allowed when the target design is identifiable. Standard errors condition on fitted MLM parameters. Bayesian snapshots use posterior means of shared parameters; step-1 uncertainty is not propagated and full-workflow coverage is unvalidated.

Single-group linear nlme fits must retain their data (keep.data = TRUE). Supported correlations are independent, corAR1, and corCAR1; an AR(1) represented internally as corARMA(p = 1, q = 0) is also accepted. Supported residual variance structures are constant, varIdent, and varPower (including fitted-value covariates). Correlation groups must match the random-effects grouping factor. Other structures, nonlinear nlme fits, and multilevel nlme fits are rejected explicitly.

nlme designs use stored effective observation IDs and fitted contrasts. Residual covariance uses fitted residual SDs and correlation blocks; na.exclude padding and re-evaluation of subset cannot add observations. See vignette("nlme-workflow", package = "repair") for reproduction examples.

The structural repair() workflow accepts lmer nuisance groups only when every fitted nuisance level belongs to one target level. It rejects shared nuisance levels: per-cluster blocks do not describe their cross-cluster prediction errors. Lower-level prediction extraction of such shared structures remains experimental; computing predictions alone does not validate structural inference.

Examples

data(repair_example)
growth <- lme4::lmer(score ~ day + (day | person), repair_example$repeated)
predictions <- repair_ranef_gls(growth, target_group = "person")
head(predictions@predictions$person)
#>      (Intercept)        day
#> P001  6.07896679  0.4451909
#> P002  1.77920961  0.4105728
#> P003  1.22602983 -0.4013259
#> P004  1.23695761  0.6289102
#> P005 -2.93458244  0.6052267
#> P006 -0.02682852 -1.2120879
predictions@prediction_error_covariance$person[, , 1]
#>             (Intercept)         day
#> (Intercept)  0.68772918 -0.09824703
#> day         -0.09824703  0.01964941