Skip to contents

Fits the Weibull accelerated failure time model documented in full at fast_weibull_regression_general_cpp (\(\log T_i = \eta_i + \sigma W_i\), \(\eta_i = x_i^\top\beta\), right-censoring only), via either that C++ backend (use_rcpp = TRUE, the default) or survreg with dist = "weibull" (use_rcpp = FALSE) as a fallback/cross-check implementation.

Usage

fast_weibull_regression(
  y,
  dead,
  X,
  use_rcpp = TRUE,
  estimate_only = FALSE,
  optimization_alg = "lbfgs",
  warm_start_params = NULL,
  warm_start_fisher_info = NULL
)

Arguments

y

Observed survival/censoring times (must be positive).

dead

Event indicator: 1 for an exactly observed event, 0 for right-censored (survival known only to exceed y[i]).

X

A numeric matrix of predictor variables. No intercept column is needed: one is always fitted, and a leading column of all 1s is treated as that intercept (see Details).

use_rcpp

Logical. If TRUE (default), use the optimized Rcpp implementation. If FALSE, use survreg.

estimate_only

Logical. If TRUE, skip variance-covariance matrix calculation for speed. Only has an effect when use_rcpp = TRUE.

optimization_alg

Optimization algorithm: "lbfgs" (default) or "newton_raphson". Only has an effect when use_rcpp = TRUE.

warm_start_params

Optional starting values for \([\beta, \log\sigma]\). Only has an effect when use_rcpp = TRUE.

warm_start_fisher_info

Optional initial curvature (Fisher/observed information) matrix. Only has an effect when use_rcpp = TRUE.

Value

A list containing the following components:

coefficients

A numeric vector of the estimated Weibull regression coefficients \(\hat\beta\), including the intercept.

log_sigma

The logarithm of the fitted scale parameter \(\hat\sigma\) of the Weibull AFT distribution.

vcov

The variance-covariance matrix of the estimated coefficients, or NULL if estimate_only = TRUE (Rcpp path only).

neg_log_lik

(Rcpp path only) The negative log-likelihood at the fitted parameters.

fisher_information

(Rcpp path only) The observed information matrix, or NULL if estimate_only = TRUE.

std_errs

(survival path only) The coefficient standard errors, sqrt(diag(vcov)).

Details

When use_rcpp = TRUE, an intercept column is prepended to X automatically if not already present (detected as a first column of all 1s), fitting always starts from a zero cold start (smart_cold_start = FALSE is hardcoded, regardless of whether warm_start_params is supplied), and a non-converged C++ fit is escalated to an R-level stop() rather than returned silently.

When use_rcpp = FALSE, any existing intercept column is stripped and survreg is left to add its own; remaining covariate columns are first passed through drop_linearly_dependent_cols to remove collinear columns before fitting (silently — no error or warning is raised for dropped columns). estimate_only, optimization_alg, warm_start_params, and warm_start_fisher_info have no effect on this path — survreg always computes the full variance-covariance matrix, and std_errs (from sqrt(diag(vcov))) is included only in this path's return value, not the Rcpp path's. Both non-finite coefficients and (unless estimate_only = TRUE, which is ignored on this path regardless) non-finite variance-covariance entries from survreg are escalated to an R-level stop().

See also

fast_weibull_regression_general_cpp for the full model documentation and Rcpp backend contract.

Examples

X = matrix(rnorm(500), 100, 5)
y = runif(100)
dead = rbinom(100, 1, 0.5)
fast_weibull_regression(y, dead, X)
#> $coefficients
#>  (Intercept)                                                                  
#> -0.257190691 -0.007564796 -0.041233791 -0.018122443  0.006361918  0.051750727 
#> 
#> $log_sigma
#> [1] -0.6486255
#> 
#> $vcov
#>               [,1]          [,2]          [,3]          [,4]          [,5]
#> [1,]  5.922580e-03 -0.0001332555  2.621346e-04 -0.0003411112 -5.612929e-05
#> [2,] -1.332555e-04  0.0046922603 -2.332504e-04 -0.0001433654 -1.022804e-04
#> [3,]  2.621346e-04 -0.0002332504  4.679599e-03  0.0005352842 -4.231939e-04
#> [4,] -3.411112e-04 -0.0001433654  5.352842e-04  0.0049101038 -4.236485e-04
#> [5,] -5.612929e-05 -0.0001022804 -4.231939e-04 -0.0004236485  4.888530e-03
#> [6,] -1.097273e-04  0.0006174037 -2.023683e-04  0.0005798462  7.173148e-04
#> [7,]  2.105665e-03 -0.0008134565 -8.198228e-06 -0.0007374554 -4.185187e-05
#>               [,6]          [,7]
#> [1,] -1.097273e-04  2.105665e-03
#> [2,]  6.174037e-04 -8.134565e-04
#> [3,] -2.023683e-04 -8.198228e-06
#> [4,]  5.798462e-04 -7.374554e-04
#> [5,]  7.173148e-04 -4.185187e-05
#> [6,]  6.896679e-03 -9.120758e-05
#> [7,] -9.120758e-05  1.404268e-02
#> 
#> $neg_log_lik
#> [1] 34.67196
#> 
#> $fisher_information
#>             [,1]        [,2]       [,3]       [,4]       [,5]       [,6]
#> [1,] 179.3032866   0.1480849 -10.999906   9.693391   1.549026   1.191983
#> [2,]   0.1480849 219.1811232   9.676100  10.636689   9.547981 -21.048945
#> [3,] -10.9999061   9.6760999 219.189744 -23.473870  16.191279   5.695721
#> [4,]   9.6933913  10.6366889 -23.473870 212.988333  19.978245 -21.336312
#> [5,]   1.5490263   9.5479807  16.191279  19.978245 211.448927 -24.002723
#> [6,]   1.1919833 -21.0489450   5.695721 -21.336312 -24.002723 151.336919
#> [7,] -26.3625126  13.1303728   1.190397  10.255055   1.853723  -1.603802
#>            [,7]
#> [1,] -26.362513
#> [2,]  13.130373
#> [3,]   1.190397
#> [4,]  10.255055
#> [5,]   1.853723
#> [6,]  -1.603802
#> [7,]  76.459412
#>