Survival Variable Selection with Censored Data

Python · R · Part 10 of the variable-selection arc — time-to-event outcomes

Overview

Part 10 of the variable-selection arc: time-to-event outcomes. The last outcome type brings a complication no earlier notebook faced — censoring. When a study ends, many patients are still alive: we know only that their survival time exceeds their follow-up, not what it is. A selection method must use that partial information correctly or it will be badly biased. The classic testbed is the Mayo Clinic PBC data (primary biliary cirrhosis): 276 patients, 16 candidate covariates, only 40% observed deaths. The famous Mayo "natural history" model, built by painstaking stepwise selection, kept exactly five — bilirubin, albumin, age, edema, prothrombin time. Can Bayesian variable selection recover them? We fit a Weibull proportional-hazards model with a spike-and-slab prior (Part 1's method extended to censored data), cross-checked against PyMC and R's BMA::bic.surv (model averaging over Cox models).

logL=i[δi(logα+(α1)logti+ηi)tiαeηi],ηi=β0+xiβ\log L = \sum_i\Big[\,\delta_i\big(\log\alpha + (\alpha-1)\log t_i + \eta_i\big) - t_i^{\alpha}e^{\eta_i}\,\Big], \qquad \eta_i = \beta_0 + x_i'\beta

Weibull proportional hazards, and how censoring enters

A Weibull proportional-hazards model with hazard h(tx)=αtα1exp(β0+xβ)h(t\mid x)=\alpha t^{\alpha-1}\exp(\beta_0+x'\beta), an event indicator δi\delta_i (1 = death observed, 0 = censored) and follow-up tit_i. In the log-likelihood the cumulative-hazard term tiαeηit_i^\alpha e^{\eta_i} is subtracted for every subject, while only an observed death adds the log-hazard — which is exactly how a censored patient contributes "survived at least this long" (logS(ti)=tiαeηi\log S(t_i)=-t_i^\alpha e^{\eta_i}) rather than "died at tit_i". A spike-and-slab prior sits on the coefficients as before. The Weibull likelihood is not conjugate, so β\beta (and the baseline β0,α\beta_0,\alpha) are updated by adaptive random-walk Metropolis with the spike/slab prior variance set by the current γ\gamma — but the selection step is unchanged from Part 1: γjβj\gamma_j\mid\beta_j is a Bernoulli from the spike/slab density ratio, because that conditional never sees the likelihood. So the whole apparatus is Part-1 SSVS with a Metropolis coefficient move and a survival log-likelihood. Strongly right-skewed labs are log-transformed and all covariates standardized. Engine: a self-contained survsel.py.

Results

The Mayo model, recovered. The from-scratch Weibull-PH search selects all five factors of the hand-built Mayo natural-history model — bilirubin (inclusion 1.00), age, edema, albumin and prothrombin time (the last just over the line at 0.52) — alongside histologic stage and urinary copper, both established PBC markers. The search found the accepted prognostic set from a Bayesian posterior, censoring and all, and the Kaplan–Meier curves confirm it: split by bilirubin tertile or by edema, the observed survival curves separate dramatically. A famous null result: treatment (D-penicillamine) has inclusion ≈ 0.10 — not selected — matching the trial's conclusion that the drug did not improve survival; selection correctly declines an ineffective covariate. Three engines, one prognostic set: the from-scratch Weibull-PH SSVS, PyMC's version, and R's bic.surv (which averages over Cox models) select the same core six — bilirubin, age, edema, albumin, copper and histologic stage — with prothrombin time right on the selection boundary (in for the Weibull at 0.52, just shy for PyMC at ≈0.47 and Cox BMA at 0.41). That a fully parametric Weibull and a semiparametric Cox agree on which covariates matter confirms the selection is a property of the proportional-hazards structure, not the baseline-hazard form. Censoring, handled cleanly: with 60% of times censored, the cumulative-hazard term does the work — a censored patient contributes the probability of surviving past their follow-up, and the selection is unbiased for it (treating censored times as deaths would corrupt every inclusion probability). This completes the arc's outcome types — continuous, counts and tables, multivariate time series, binary, and now time-to-event — the same spike-and-slab idea traveling to each by swapping in the appropriate likelihood, with the inclusion step untouched.

Notebooks

Downloads

References