Skip to contents

repair_bootstrap() samples whole people with replacement and calls repair_refit() to rebuild the complete analysis. Each selected occurrence gets fresh person and nuisance IDs. Measurement models, predictions, prediction-error covariance, structural moments, corrections, and weights are re-estimated for each attempt. The original fit and its conditional inference remain available for comparison.

This functionality is experimental: software replay tests verify the calculation, while targeted simulation screens show condition-dependent coverage. Broader independent coverage validation remains outstanding. It assumes independent people. It does not remedy dependence across people, misspecification, informative missingness, or weak identification.

Fit, sample, and report

When repeated measurement refits produce convergence warnings, select a fitting strategy before running the bootstrap. repair_lmer_refitter() uses a deterministic nloptwrap starting fit followed by likelihood-checked BOBYQA and, when needed, bounded retries. Use it to fit the original measurement model:

fitter <- repair_lmer_refitter(score ~ day + (day | person))
model <- fitter(repair_example$repeated)
fit <- repair(re("day") ~ practice, model, repair_example$people, "person")
boot <- repair_bootstrap(fit, repair_example$repeated,
                         repair_example$people, B = 1999, seed = 214)
repair_bootstrap_diagnostics(boot)$optimization[[1]]
attr(model, "repair_lmer_optimization")

The model retains its recipe, so reference and resampled fits use it automatically, including after saving/loading. Do not add a different optimizer strategy only to failed bootstrap draws from an existing analysis: rebuild the original fit with the chosen recipe first. Every optimizer attempt is retained in the audit; an unresolved convergence or likelihood check still withholds default inference. Retries do not add bootstrap draws, change the measurement model or structural regularization, or consume random numbers. Singular fits alone are not failures. This improves numerical fitting; it does not establish coverage, remove estimator bias, or justify dropping failed attempts. The robust helper currently covers Gaussian lmer models; nlme replay remains unchanged.

data(repair_example)
repeated <- repair_example$repeated
people <- repair_example$people
model <- lme4::lmer(score ~ day + (day | person), repeated,
  control = lme4::lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 100000)))
fit <- repair(re("day") ~ practice, model, people, "person")

# Nine attempts make this guide quick to run; they are not adequate for inference.
boot <- repair_bootstrap(fit, repeated, people, B = 9, seed = 41)
summary(boot)
#> REPAIR person bootstrap (experimental)
#> re("day") ~ practice 
#> People: 60 ; attempts: 9 ; usable: 9 ; failed: 0 
#>         term   estimate  std.error   conf.low  conf.high conf.level     method
#>  (Intercept) -0.7895288 0.13208676 -0.9447660 -0.6071569       0.95 percentile
#>     practice  0.1754854 0.02626268  0.1337869  0.2126906       0.95 percentile
#>  attempted usable failed conditional_on_success                     inference
#>          9      9      0                  FALSE Experimental person bootstrap
#>          9      9      0                  FALSE Experimental person bootstrap
#> Experimental person-level cases bootstrap; marginal percentile intervals; coverage not yet validated. 
#> Assess Monte Carlo stability before interpreting interval tails.

The default is B = 1999, counting attempts, with reproducible seed = 1. Real analyses need sufficient tail resolution and checks of stability over larger B and different seeds. Neither a large B nor a high success rate establishes coverage. A run rebuilds the measurement model repeatedly, so it can take much longer than the original structural analysis.

coef(boot)                           # original-data estimates
#> (Intercept)    practice 
#>  -0.7895288   0.1754854
vcov(boot)                           # empirical bootstrap covariance
#>              (Intercept)      practice
#> (Intercept)  0.017446913 -0.0023636515
#> practice    -0.002363651  0.0006897282
#> attr(,"method")
#> [1] "empirical covariance"
#> attr(,"attempted")
#> [1] 9
#> attr(,"usable")
#> [1] 9
#> attr(,"failed")
#> [1] 0
#> attr(,"conditional_on_success")
#> [1] FALSE
#> attr(,"inference")
#> [1] "Experimental person bootstrap"
confint(boot, level = .90)            # marginal percentile intervals
#>                    5 %       95 %
#> (Intercept) -0.9296336 -0.6084578
#> practice     0.1373470  0.2080242
#> attr(,"method")
#> [1] "percentile"
#> attr(,"attempted")
#> [1] 9
#> attr(,"usable")
#> [1] 9
#> attr(,"failed")
#> [1] 0
#> attr(,"conditional_on_success")
#> [1] FALSE
#> attr(,"inference")
#> [1] "Experimental person bootstrap"
repair_bootstrap_coefficients(boot, conf.level = .90)
#>          term   estimate  std.error   conf.low  conf.high conf.level     method
#> 1 (Intercept) -0.7895288 0.13208676 -0.9296336 -0.6084578        0.9 percentile
#> 2    practice  0.1754854 0.02626268  0.1373470  0.2080242        0.9 percentile
#>   attempted usable failed conditional_on_success                     inference
#> 1         9      9      0                  FALSE Experimental person bootstrap
#> 2         9      9      0                  FALSE Experimental person bootstrap
repair_coefficients(fit, conf.level = .90)  # original conditional Wald comparison
#>          term   estimate std.error statistic      p.value   conf.low  conf.high
#> 1 (Intercept) -0.7895288 0.1147252 -6.881912 5.905430e-12 -0.9782350 -0.6008226
#> 2    practice  0.1754854 0.0214190  8.192979 2.548386e-16  0.1402543  0.2107165
#>   conf.level
#> 1        0.9
#> 2        0.9

Bootstrap SEs are SDs of complete usable coefficient vectors. Percentile endpoints are their empirical quantiles using R’s quantile(type = 7). The same vectors are used for all coefficients and the joint covariance. Bootstrap variance is not added to conditional variance. These are marginal intervals, not a simultaneous confidence region. There are no bootstrap p-values or bootstrap Wald z-statistics in the table.

Examine attempts and reproduce a sampled analysis

attempts <- repair_bootstrap_diagnostics(boot)
attempts[, c("replicate", "usable", "stage", "n_people", "n_measurement",
  "measurement_singular", "preliminary_multiplier", "final_multiplier")]
#>   replicate usable    stage n_people n_measurement measurement_singular
#> 1         1   TRUE complete       60           592                FALSE
#> 2         2   TRUE complete       60           580                FALSE
#> 3         3   TRUE complete       60           609                FALSE
#> 4         4   TRUE complete       60           584                FALSE
#> 5         5   TRUE complete       60           591                FALSE
#> 6         6   TRUE complete       60           578                FALSE
#> 7         7   TRUE complete       60           579                FALSE
#> 8         8   TRUE complete       60           593                FALSE
#> 9         9   TRUE complete       60           590                FALSE
#>   preliminary_multiplier final_multiplier
#> 1                   0.95             0.95
#> 2                   0.95             0.95
#> 3                   0.95             0.95
#> 4                   0.95             0.95
#> 5                   0.95             0.95
#> 6                   0.95             0.95
#> 7                   0.95             0.95
#> 8                   0.95             0.95
#> 9                   0.95             0.95

mapping <- repair_bootstrap_diagnostics(boot, "draws")
head(mapping)
#>   replicate draw source_id refit_id
#> 1         1    1      P045 r0000001
#> 2         1    2      P046 r0000002
#> 3         1    3      P014 r0000003
#> 4         1    4      P031 r0000004
#> 5         1    5      P048 r0000005
#> 6         1    6      P044 r0000006

Each mapping row identifies (replicate, draw, source_id, refit_id). Repeated source IDs within a replicate correspond to distinct people in that refit. Generated IDs are reused between independently fitted replicates, so always keep the replicate key. Character source IDs, including leading zeros, stay intact.

For example, replay the first recorded sample without generating another one:

first_ids <- mapping$source_id[mapping$replicate == 1L]
first <- repair_refit(fit, repeated, people, draw = first_ids)
stopifnot(isTRUE(all.equal(unname(coef(first)), unname(boot$replicates[1, ]),
  tolerance = 1e-6)))

All effective observations for a sampled person are copied in their original order, including unequal observation counts and schedules. There is no resampling of observations within people. Contained nuisance groups such as person:day remain separate for duplicate people. See the refitting guide for exact replay, row/coding rules, supported lmer/lme settings, and explicit refitter(data) callbacks. Each attempt uses that same reference validation.

Failures are part of the result

A lost factor level, unusable score, measurement nonconvergence, or structural failure invalidates the whole coefficient vector. The attempt stays in the result with its source-ID map, stage, reason, warnings/messages when available, and an all-NA coefficient row. There are no replacement bootstrap samples, trimming, or within-attempt omission to rescue a fit. A recorded robust measurement recipe can retry numerical optimization within the same sample and records every internal fit in the optimization list-column. Singular lmer fits are retained when convergence, scoring, and structural estimation remain usable; lme singularity is not assessed. Warnings alone do not automatically invalidate an attempt.

This deliberately sparse factor demonstrates why successful samples can be a selected distribution:

sparse_people <- people
sparse_people$rare <- factor(seq_len(nrow(people)) == 1L)
sparse_fit <- repair(re("day") ~ practice + rare, model, sparse_people, "person")
sparse_boot <- repair_bootstrap(sparse_fit, repeated, sparse_people, B = 10, seed = 41)
#> Warning: 2 of 10 bootstrap attempts failed; all attempts retained. Inference is withheld
#> by default; inspect `repair_bootstrap_diagnostics()`.
summary(sparse_boot)  # remains inspectable; intervals are withheld
#> REPAIR person bootstrap (experimental)
#> re("day") ~ practice + rare 
#> People: 60 ; attempts: 10 ; usable: 8 ; failed: 2 
#> Bootstrap inference withheld: 2 of 10 attempts failed. Inspect
#> `repair_bootstrap_diagnostics()`; use `allow_failed = TRUE` only for inference
#> conditional on successful replicates. 
#> Experimental person-level cases bootstrap; marginal percentile intervals; coverage not yet validated. 
#> Assess Monte Carlo stability before interpreting interval tails.
failed <- repair_bootstrap_diagnostics(sparse_boot)
failed[!failed$usable, c("replicate", "stage", "reason")]
#>   replicate            stage
#> 1         1 replacement_data
#> 6         6 replacement_data
#>                                                                                                                                 reason
#> 1 \033[1m\033[22mRefit factor \033[34m"rare"\033[39m has new or absent levels; the original coefficient\nschema must remain estimable.
#> 6 \033[1m\033[22mRefit factor \033[34m"rare"\033[39m has new or absent levels; the original coefficient\nschema must remain estimable.

If any attempt fails, vcov(), confint(), and the bootstrap coefficient extractor stop by default. Investigate the reasons and the original model first. Explicitly requesting allow_failed = TRUE gives a summary conditional on successful replicates; it does not recover the distribution of all attempts:

repair_bootstrap_coefficients(sparse_boot, allow_failed = TRUE)
#>          term    estimate  std.error    conf.low  conf.high conf.level
#> 1 (Intercept) -0.78919429 0.14079535 -0.88191602 -0.4903135       0.95
#> 2    practice  0.17516878 0.02565318  0.13032045  0.1936065       0.95
#> 3    rareTRUE  0.06075446 0.09440081 -0.04142959  0.1846861       0.95
#>       method attempted usable failed conditional_on_success
#> 1 percentile        10      8      2                   TRUE
#> 2 percentile        10      8      2                   TRUE
#> 3 percentile        10      8      2                   TRUE
#>                                                             inference
#> 1 Experimental person bootstrap, conditional on successful replicates
#> 2 Experimental person bootstrap, conditional on successful replicates
#> 3 Experimental person bootstrap, conditional on successful replicates

Counts and the changed interpretation appear in the table and summary. Covariance and interval matrices carry counts, method, conditional-on-success status, and an experimental label as attributes. At least two complete vectors are required even after opt-in. This is only a numerical minimum, not a precision or validity criterion. B = 1 and runs with no usable vectors remain useful for diagnostics.

Cohort and inference boundaries

The first implementation supports one referenced measurement model: Gaussian lmer, including contained nuisance groups, or supported single-group linear lme. The measurement and analyzed person cohorts must coincide. Measurement-only people or people omitted structurally despite having measurement data require an explicitly revised reference fit before sampling. The source order is the original analysis order. Sampling conditions on the chosen cohort, selection rule, and observed missingness pattern; it does not generate new within-person histories.

Structural and measurement IDs may use different column names. The target must be a bare measurement ID; IDs used as substantive covariates and unsupported nuisance mappings cannot be automatically re-keyed. Shared nuisance effects remain rejected. Factor coding and coefficient identities remain fixed; losing a level invalidates an attempt rather than changing the estimand.

Regularization policy/custom alpha, ML/REML, optimizer and covariance recipes, formula, and computation backend follow the reference fit. Data-dependent regularization multipliers and weights are recomputed; transitions in those quantities can affect the distribution. Scores remain random deviations rather than fixed-plus-random totals, and re-estimated fixed effects can change centering.

No stratification, higher-level cluster sampling, multiple-model bootstrap, cross-model covariance replay, parallel execution, checkpoints/resume, BCa, studentized, or simultaneous intervals are included. The next scientific gate is a larger independent coverage study across reliability, sample size, design imbalance, variance boundaries, and weak corrected moments.

Reproducibility and saved results

The serial engine assigns one L’Ecuyer-CMRG stream to preflight and a separate stream to each attempt, using Inversion normals and Rejection sampling. A fitting failure or RNG use in one attempt cannot change subsequent samples. Extending B with the same seed/data/recipe preserves the initial attempts in the same numerical environment. boot$rng stores those streams; boot$replicates is the B-by-p coefficient matrix. These are documented result fields, including all failed rows.

The caller’s RNG kind and .Random.seed (including its absence) are restored on success or error. Box-Muller and user-supplied caller RNGs are rejected before changing state: their hidden state cannot be restored from .Random.seed. Callbacks remain deterministic, explicit fitting recipes; no guarantee is made for callbacks with external state or changing global options.

Save the bootstrap object with saveRDS() and reload with readRDS() after loading repair. Extraction needs no original data bindings. The result stores original estimates, the conditional comparison table, draws, attempts, reference audit, streams, and versions. boot$specification records formula text, selected effects, ID column, observable measurement settings, structural backend, and regularization controls without formula environments or raw datasets. It retains neither every fitted replicate model nor copied raw datasets. Retain original inputs, fitting code, and sessionInfo() separately to rerun the analysis. Optimizer/dependency changes can affect numerical results; cross-version bitwise equivalence is not promised.

The R RNG-stream documentation describes the stream mechanism, and the R quantile documentation specifies the percentile endpoint calculation. Neither establishes scientific coverage for REPAIR; see the developer bootstrap design and implementation audit in the repository for the outstanding validation plan.