lgspline_weibull: Fit Weibull Accelerated Failure Time Model via lgspline

View source: R/weibull_helpers.R

lgspline_weibullR Documentation

Fit Weibull Accelerated Failure Time Model via lgspline

Description

Convenience wrapper that calls lgspline with the correct family, weight, dispersion, score, and unconstrained-fit functions for Weibull accelerated failure time regression. All standard lgspline arguments (knots, penalties, constraints, parallel, etc.) are passed through.

Usage

lgspline_weibull(formula, data, status, ...)

Arguments

formula

Formula specifying the model. The response should be survival time; status is passed separately.

data

Data frame.

status

Integer vector of event indicators (1 = event, 0 = censored), same length as the number of rows in data.

...

Additional arguments passed to lgspline.

Details

Internally sets:

  • family = weibull_family()

  • unconstrained_fit_fxn = unconstrained_fit_weibull

  • glm_weight_function = weibull_glm_weight_function

  • qp_score_function = weibull_qp_score_function

  • dispersion_function = weibull_dispersion_function

  • schur_correction_function = weibull_schur_correction

  • need_dispersion_for_estimation = TRUE

  • estimate_dispersion = TRUE

  • standardize_response = FALSE

A formula interface is needed, e.g. lgspline_weibull(t, y, ...) won't work, unlike for ordinary lgspline.

Value

An object of class "lgspline".

See Also

lgspline_cox for Cox proportional hazards, weibull_family, unconstrained_fit_weibull

Examples


## Weibull AFT with a nonlinear age effect on lung cancer survival
if(requireNamespace("survival", quietly = TRUE)) {
  library(survival)
  set.seed(1234)
  lung <- na.omit(lung[, c("time", "status", "age")])
  lung$age_std <- std(lung$age)

  ## survival codes status as 1 = censored, 2 = dead
  event <- as.integer(lung$status == 2)

  ## Spline on age
  fit <- lgspline_weibull(
    time ~ spl(age_std),
    data = lung,
    status = event,
    K = 1,
    opt = FALSE,
    wiggle_penalty = 1e-4,
    flat_ridge_penalty = 1
  )
  print(summary(fit))
  plot(fit,
       show_formulas = TRUE,
       custom_response_lab = 'Survival Time',
       custom_predictor_lab = 'Standardized Age')
}


lgspline documentation built on Aug. 5, 2026, 1:10 a.m.