Skip to contents

Read saved predictions and their sampling-error variances without refitting or navigating the different single- and multiple-model prediction containers.

Usage

repair_predictions(object, scope = c("structural", "all"))

Arguments

object

A repair() result or an assembled repair_data() object. A numerical structural failure is accepted because MLM predictions exist.

scope

"structural" (default) returns retained structural IDs in their analysis order. "all" returns each model's effective grouping levels in saved prediction-extraction order, including units outside or excluded from the analysis.

Value

A plain data frame with columns in order: id, model, group, term, label, role (character), prediction, std.error, prediction.error.variance (numeric), scope (character), analyzed (logical), status, reason (character). Rows follow selected-effect order (outcome first when random, then predictor references), then IDs within each effect. The key is (model, group, term, id); IDs are character and never stored only in row names. label is the qualified formula label, and role is "outcome" or "predictor". Successful rows have status "ok" and an empty reason. The schema is identical for one or many models.

Details

Only effects selected in the structural formula are returned. Predictions are likelihood-only random deviations, not BLUPs or fixed-plus-random totals. std.error is the square root of the prediction-error variance conditional on fitted MLM parameters; it is not a posterior SD or a structural SE. Marginal variances alone do not describe all prediction uncertainty: use repair_prediction_covariance() for retained within- and cross-model covariances.

A unit's structural exclusion does not itself indicate a failed prediction. Failed predictions remain as rows, with missing estimates/uncertainty where saved, status = "failed", and a reason. Absent MLM IDs have no prediction row; use repair_diagnostics(fit, table = "excluded") for their exclusion reasons.

Examples

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