ransac_lme4: RANSAC initial estimator for LMM

View source: R/ransac.R

ransac_lme4R Documentation

RANSAC initial estimator for LMM

Description

RANSAC-style random subsample initial estimator for linear mixed-effects models.

Usage

ransac_lme4(
  formula,
  data,
  K = 200L,
  sub_frac = 0.5,
  scale_fn = robustbase::Qn,
  adaptive = TRUE,
  patience = 50L,
  K_min = 50L,
  tol = 0.001,
  stratify = TRUE,
  n_keep = 1L,
  seed = NULL,
  verbose = FALSE
)

Arguments

formula

model formula in lmer syntax.

data

full data frame.

K

maximum number of random subsamples (default 200). With adaptive = TRUE the search stops early once the best score plateaus; K is then an upper budget rather than a fixed count.

sub_frac

fraction of the data per subsample (default 0.5).

scale_fn

function from a numeric residual vector to a scalar scale. Default Qn.

adaptive

logical (default TRUE); stop drawing subsamples once the best score has not improved by more than tol (relative) for patience consecutive draws, after at least K_min draws. FALSE runs exactly K draws (the previous behaviour).

patience

number of consecutive non-improving draws that triggers the adaptive stop (default 50).

K_min

minimum draws before the adaptive stop can fire (default 50).

tol

relative-improvement threshold for the adaptive stop (default 1e-3).

stratify

logical (default TRUE); draw each subsample stratified by the random-effects grouping factor (the one with the most levels, parsed from the formula), taking ceiling(sub_frac * n_g) (at least one) rows within each level so every grouping level is represented. This keeps the per-subsample lmer fittable on designs with many small clusters, where plain random subsampling can leave a level empty. FALSE (or no grouping factor) falls back to simple random subsampling.

n_keep

number of distinct best-scoring candidate starts to return in $candidates (default 1). The multi-start consensus of rlmer_ransac (n_starts > 1) uses these to sample several basins of a redescending psi.

seed

optional RNG seed for reproducibility.

verbose

logical; print progress every 50 subsamples.

Details

For K random subsamples of the data, fit a classical lmer on each subsample, score by a robust scale of residuals computed on the full data, and return the lmer fit minimising that score.

The motivation is that for redescending psi-functions (e.g. lqqPsi, the recommended redescender, or the faster-redescending bisquarePsi) the rlmer optimiser benefits from a starting value close to the true parameters. A bad initial estimate can produce phony local minima (e.g. random-effects correlation pinned at +/- 1; see Koller and Stahel 2022, Section 4.4). RANSAC is a classical way of generating a high-breakdown-point initial estimate by subsampling.

Value

list with fit (best lmerMod), scale (its score), subset (its row indices), scales (length-K vector of scores; NA for draws not run under an adaptive early stop), K (the requested cap), K_used (draws actually run), n_sub, n_singular (total number of collinear candidate observations skipped by the nonsingular-subsampling draw across all subsamples; see below).

Nonsingular subsampling

With categorical predictors a rank-deficient subsample often does not make lmer error — it silently drops the aliased (all-zero) fixed-effect columns of a dropped factor level — so a degenerate candidate would otherwise enter the scale competition with the wrong number of parameters. Rather than draw and then repair, each subsample is drawn nonsingular by construction using the nonsingular-subsampling algorithm of Koller and Stahel (2017, Algorithm 1; the method behind robustbase::lmrob.control(setting = "KS2014")). The draw units (clusters when a grouping factor is available, else single observations) are randomly permuted; a Gaxpy-variant LU decomposition with partial pivoting and column skipping (implemented in C++) then walks the permuted observations and greedily selects the first p that are linearly independent, skipping any observation collinear with those already chosen. This yields a full-rank fixed-effects core whenever the full design has full column rank. Whole clusters carrying that core are the mandatory seed; further clusters are then added in the permuted order until the retained data are identifiable — (i) a full-rank fixed-effects design [guaranteed by the core], (ii) at least two observed levels of every random-effects grouping factor, and (iii) non-constant numeric random-slope variables — and finally up to the target subsample size. Because adding clusters never lowers the rank or removes a level this is monotone and terminates. n_singular counts the collinear candidate observations skipped by the LU across all draws (a measure of the collinearity encountered); it is 0 on a purely continuous, full-rank design, where the algorithm selects exactly the first p permuted observations, so the draw is a uniform random cluster subsample — statistically identical to plain random subsampling. Note that a nonsingular start does not guarantee the fit stays nonsingular through the rlmer refinement: a redescending psi can zero-weight observations back into a rank-deficient design (Koller and Stahel 2017, Remark 2), which rlmer_ransac checks for and warns about.

References

Koller, M. and Stahel, W. A. (2017) Nonsingular subsampling for regression S estimators with categorical predictors. Computational Statistics 32(2), 631–646.

Examples

  set.seed(1)
  res <- ransac_lme4(Reaction ~ Days + (Days | Subject),
                      data = sleepstudy, K = 30)
  res$scale

robustlmm documentation built on July 30, 2026, 5:11 p.m.