lgspline_cox: Fit Cox Proportional Hazards Model via lgspline

View source: R/cox_helpers.R

lgspline_coxR Documentation

Fit Cox Proportional Hazards Model via lgspline

Description

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

Usage

lgspline_cox(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 = cox_family()

  • unconstrained_fit_fxn = unconstrained_fit_cox

  • glm_weight_function = cox_glm_weight_function

  • qp_score_function = cox_qp_score_function

  • dispersion_function = cox_dispersion_function

  • schur_correction_function = cox_schur_correction

  • need_dispersion_for_estimation = FALSE

  • estimate_dispersion = FALSE

  • standardize_response = FALSE

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

Value

An object of class "lgspline".

Examples


## Cox PH 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_cox(
    time ~ spl(age_std),
    data = lung,
    status = event,
    opt = FALSE,
    K = 1
  )
  print(summary(fit))
  plot(fit,
       show_formulas = TRUE,
       custom_response_lab = 'HR',
       custom_predictor_lab = 'Standardized Age',
       ylim = c(0, 5))

}


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