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. It is assumed that an intercept column (e.g., a column of ones) is already included in X if desired.

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.25712014 -0.05180349  0.00232033  0.03204039 -0.07087349  0.05393320 
#> 
#> $log_sigma
#> [1] -0.4688806
#> 
#> $vcov
#>               [,1]          [,2]          [,3]          [,4]          [,5]
#> [1,]  0.0072970814 -0.0005479250 -0.0003415879 -0.0005742440 -6.794803e-04
#> [2,] -0.0005479250  0.0058404677 -0.0006178678 -0.0003544705  1.226805e-03
#> [3,] -0.0003415879 -0.0006178678  0.0071200631  0.0005456755 -6.119900e-04
#> [4,] -0.0005742440 -0.0003544705  0.0005456755  0.0099778787  2.939109e-03
#> [5,] -0.0006794803  0.0012268052 -0.0006119900  0.0029391087  8.609676e-03
#> [6,] -0.0001926449  0.0002999779  0.0005989535 -0.0007670957 -5.026937e-04
#> [7,]  0.0019525627 -0.0007368812 -0.0003228431  0.0005836071 -4.858994e-05
#>               [,6]          [,7]
#> [1,] -0.0001926449  1.952563e-03
#> [2,]  0.0002999779 -7.368812e-04
#> [3,]  0.0005989535 -3.228431e-04
#> [4,] -0.0007670957  5.836071e-04
#> [5,] -0.0005026937 -4.858994e-05
#> [6,]  0.0068831226  4.018023e-04
#> [7,]  0.0004018023  1.258517e-02
#> 
#> $neg_log_lik
#> [1] 41.98694
#> 
#> $fisher_information
#>            [,1]       [,2]       [,3]       [,4]        [,5]       [,6]
#> [1,] 145.592232   9.991640   6.448593   7.753833   8.0926514   5.838238
#> [2,]   9.991640 182.294002  13.982372  13.640696 -29.3843381 -10.036237
#> [3,]   6.448593  13.982372 145.302751 -11.988361  12.1582286 -13.788772
#> [4,]   7.753833  13.640696 -11.988361 115.065946 -40.8655795  10.887367
#> [5,]   8.092651 -29.384338  12.158229 -40.865580 136.1285357   5.861823
#> [6,]   5.838238 -10.036237 -13.788772  10.887367   5.8618231 149.138951
#> [7,] -22.352596   9.056519   4.588708  -6.553123  -0.4306934  -7.090897
#>             [,7]
#> [1,] -22.3525956
#> [2,]   9.0565191
#> [3,]   4.5887081
#> [4,]  -6.5531229
#> [5,]  -0.4306934
#> [6,]  -7.0908967
#> [7,]  84.1031560
#>