Skip to contents

Use the returned function for the original measurement fit. Models retain the recipe, so repair_refit() and repair_bootstrap() apply it automatically to reference and replacement data, including after saving/reloading a model.

Usage

repair_lmer_refitter(
  formula,
  REML = TRUE,
  weights = NULL,
  offset = NULL,
  contrasts = NULL,
  maxfun = 200000L,
  objective_tolerance = 1e-06
)

Arguments

formula

A supported data-only lmer formula.

REML

Logical; retain REML (default) or use ML consistently.

weights, offset

Optional names of explicit numeric measurement columns. Formula offsets are also supported. Expressions/global vectors are not read.

contrasts

Optional explicit contrast list passed to lmer.

maxfun

Positive integer evaluation budget for each optimizer attempt.

objective_tolerance

Nonnegative finite absolute deviance tolerance.

Value

A function of one measurement data frame. It returns an lmer model with repair_lmer_recipe and repair_lmer_optimization attributes. The latter records every attempted fit, warnings/messages, objective, singularity and selection. If finite fits remain unresolved, the best BOBYQA model is returned with a warning and usable = FALSE; refitting/bootstrap inference rejects it. If no finite BOBYQA fit exists, an error retains the attempt history.

Details

The recipe fits nloptwrap to obtain a starting point, then BOBYQA with tighter tolerances and a larger evaluation budget. If needed it retries BOBYQA from its default start and a deterministic interior perturbation. A selected fit must pass the ordinary convergence checks and have REML/ML deviance within objective_tolerance of the best finite attempted value. Singular-but-usable fits are retained. No convergence checks are disabled, no random starts are drawn, and the bootstrap failure gate is unchanged.

This changes the numerical fitting recipe. Refit the original measurement model and rebuild repair() before bootstrapping; do not attach this callback to an analysis fitted with a different recipe. Nonlinear formulas and implicit omissions unsupported by native replay remain unsupported. For categorical predictors supply explicit contrasts to insulate a callback from global options.

Examples

data(repair_example)
fitter <- repair_lmer_refitter(score ~ day + (day | person))
model <- fitter(repair_example$repeated)
fit <- repair(re("day") ~ practice, model, repair_example$people, "person")
replay <- repair_refit(fit, repair_example$repeated, repair_example$people)
attr(model, "repair_lmer_optimization")
#> $attempts
#>       attempt usable objective singular reason warnings messages
#> 1 nlopt_start   TRUE  2498.677    FALSE                         
#> 2 bobyqa_warm   TRUE  2498.677    FALSE                         
#> 
#> $selected
#> [1] 2
#> 
#> $usable
#> [1] TRUE
#> 
#> $objective_tolerance
#> [1] 1e-06
#>