
Robust Parametric Survival Regression (AFT) with Warm-Start and Random-Restart Fallback
Source:R/helper_robust_regression.R
robust_survreg_with_surv_object.RdFits a parametric accelerated-failure-time (AFT) survival regression via
survreg on surv_object ~ . over the columns of
cov_matrix_or_vector, with two layers of robustness against
survreg's well-known sensitivity to starting values and
near-collinear design matrices:
Preprocessing: near-collinear columns of the design matrix are dropped first via
drop_highly_correlated_colsthendrop_linearly_dependent_cols, before any fitting is attempted.Warm start (Weibull only): when
dist = "weibull", a fast closed-form-gradient Weibull fit (fast_weibull_regression) is attempted first; if it succeeds and returns a finite log-likelihood, its coefficients and \(\log(\hat\sigma)\) are passed tosurvregas theinitvector, which typically converges to the true MLE in a singlesurvregcall. If this warm-started fit is unavailable, fails, or producesNAcoefficients, fitting falls through to the general random-restart loop below (for all otherdistvalues, this warm start is skipped entirely).Random-restart loop: starting from an all-zero
initvector,survregis called repeatedly (perturbinginitby an independent standard-normal jitter,init + rnorm(length(init)), after every failed attempt) until a fit with noNAcoefficients is obtained ornum_max_iterattempts are exhausted, at which pointNULLis returned. The jitter is drawn from its own seeded stream:jitter_seedplus a fixed internal offset whenjitter_seedis given (EDI's inference and design classes pass theirset_seed()/ design seed), otherwise a fixed internal seed. The caller's.Random.seedis saved before the first jitter and restored on exit, so the fit is deterministic for given data andjitter_seedand does not consume or advance the caller's random-number stream.
survreg.control(maxiter = 100, rel.tolerance = 1e-9, outer.max = 10) is
used throughout (tighter than survreg's own defaults) to reduce the
chance of a spuriously "converged" fit at a poor optimum.
Usage
robust_survreg_with_surv_object(
surv_object,
cov_matrix_or_vector,
dist = "weibull",
num_max_iter = 50,
jitter_seed = NULL
)Arguments
- surv_object
The survival object (built from the response vector and censoring vector via
Surv).- cov_matrix_or_vector
The design matrix (or a single covariate vector) of predictors, excluding the intercept (one is added by the internal
~ .formula).- dist
The parametric AFT distribution family passed to
survreg(default"weibull"); only"weibull"triggers the closed-form warm start.- num_max_iter
Maximum number of random-restart attempts if the (possibly warm-started) direct fit fails or does not converge (default 50).
- jitter_seed
Optional integer seed for the random-restart jitter (default
NULL). When supplied, the jitter stream is seeded fromjitter_seedplus a fixed internal offset, so the samejitter_seedgives the same fit; whenNULL, a fixed internal seed is used. Either way the caller's.Random.seedis left unchanged.
Value
The fitted survreg model object, or NULL if no
attempt converged to a fit with no NA coefficients within num_max_iter tries.
Examples
X = matrix(rnorm(500), 100, 5)
y = runif(100)
dead = rbinom(100, 1, 0.5)
surv = survival::Surv(y, dead)
robust_survreg_with_surv_object(surv, X)
#> Call:
#> survival::survreg(formula = surv_reg_formula, data = cov_matrix_or_vector_data_frame,
#> dist = dist, init = init_vals, control = survival::survreg.control(maxiter = 100,
#> rel.tolerance = 1e-09, outer.max = 10))
#>
#> Coefficients:
#> (Intercept) X1 X2 X3 X4 X5
#> -0.23587225 0.01851938 -0.02591413 0.02361645 -0.04202910 0.06757437
#>
#> Scale= 0.5602244
#>
#> Loglik(model)= -41.3 Loglik(intercept only)= -42.1
#> Chisq= 1.64 on 5 degrees of freedom, p= 0.896
#> n= 100