
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 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.
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
)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).
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.12930510 -0.04882018 0.06032909 0.02179087 0.03177262 0.03758216
#>
#> Scale= 0.6189695
#>
#> Loglik(model)= -43.6 Loglik(intercept only)= -44.2
#> Chisq= 1.06 on 5 degrees of freedom, p= 0.957
#> n= 100