unconstrained_fit_weibull: Unconstrained Weibull Accelerated Failure Time Model...

View source: R/weibull_helpers.R

unconstrained_fit_weibullR Documentation

Unconstrained Weibull Accelerated Failure Time Model Estimation

Description

Estimates parameters for an unconstrained Weibull accelerated failure time (AFT) model supporting right-censored survival data.

This both provides a tool for actually fitting Weibull AFT Models, and boilerplate code for users who wish to incorporate Lagrangian multiplier smoothing splines into their own custom models.

Usage

unconstrained_fit_weibull(
  X,
  y,
  LambdaHalf,
  Lambda,
  keep_weighted_Lambda,
  family,
  tol = 1e-08,
  K,
  parallel,
  cl,
  chunk_size,
  num_chunks,
  rem_chunks,
  order_indices,
  weights,
  status
)

Arguments

X

Design matrix of predictors

y

Survival/response times

LambdaHalf

Square root of penalty matrix (\boldsymbol{\Lambda}^{1/2})

Lambda

Penalty matrix (\boldsymbol{\Lambda})

keep_weighted_Lambda

Flag to retain weighted penalties

family

Distribution family specification

tol

Convergence tolerance (default 1e-8)

K

Number of partitions minus one (K)

parallel

Flag for parallel processing

cl

Cluster object for parallel computation

chunk_size

Processing chunk size

num_chunks

Number of computational chunks

rem_chunks

Remaining chunks

order_indices

Observation ordering indices

weights

Optional observation weights

status

Censoring status indicator (1 = event, 0 = censored) Indicates whether an event of interest occurred (1) or the observation was right-censored (0). In survival analysis, right-censoring occurs when the full survival time is unknown, typically because the study ended or the subject was lost to follow-up before the event of interest occurred.

Details

Estimation Approach: The function employs a two-stage optimization strategy for fitting accelerated failure time models via maximum likelihood:

1. Outer Loop: Estimate Scale Parameter (sigma) using Brent's method

2. Inner Loop: Estimate Regression Coefficients (given sigma) using damped Newton-Raphson.

Note: the score and information inside the Newton-Raphson are both scaled by \sigma^2 (i.e., both omit the 1/\sigma and 1/\sigma^2 prefactors respectively). Since the Newton-Raphson step is \mathbf{G}u = (\mathbf{X}^{\top}\mathbf{W}\mathbf{X})^{-1} \mathbf{X}^{\top}\mathbf{v}, the \sigma^2 factors cancel and the step remains correct.

Value

Numeric column vector of unconstrained coefficient estimates for the Weibull AFT model.

Examples


## Simulate survival data with covariates
set.seed(1234)
n <- 1000
t1 <- rnorm(n)
t2 <- rbinom(n, 1, 0.5)

## Generate survival times with Weibull-like structure
lambda <- exp(0.5 * t1 + 0.3 * t2)
yraw <- rexp(n, rate = 1/lambda)

## Introduce right-censoring
status <- rbinom(n, 1, 0.75)
y <- ifelse(status, yraw, runif(length(yraw), 0, yraw))
df <- data.frame(y = y, t1 = t1, t2 = t2)

## Fit model using lgspline with Weibull AFT unconstrained estimation
model_fit <- lgspline(y ~ spl(t1) + t2,
                      df,
                      unconstrained_fit_fxn = unconstrained_fit_weibull,
                      family = weibull_family(),
                      need_dispersion_for_estimation = TRUE,
                      dispersion_function = weibull_dispersion_function,
                      glm_weight_function = weibull_glm_weight_function,
                      schur_correction_function = weibull_schur_correction,
                      status = status,
                      opt = FALSE,
                      K = 1)

## Print model summary
summary(model_fit)


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