| ransac_lme4 | R Documentation |
RANSAC-style random subsample initial estimator for linear mixed-effects models.
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
)
formula |
model formula in |
data |
full data frame. |
K |
maximum number of random subsamples (default 200). With
|
sub_frac |
fraction of the data per subsample (default 0.5). |
scale_fn |
function from a numeric residual vector to a
scalar scale. Default |
adaptive |
logical (default |
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 |
n_keep |
number of distinct best-scoring candidate starts to
return in |
seed |
optional RNG seed for reproducibility. |
verbose |
logical; print progress every 50 subsamples. |
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.
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).
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.
Koller, M. and Stahel, W. A. (2017) Nonsingular subsampling for regression S estimators with categorical predictors. Computational Statistics 32(2), 631–646.
set.seed(1)
res <- ransac_lme4(Reaction ~ Days + (Days | Subject),
data = sleepstudy, K = 30)
res$scale
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.