Accelerated Failure-Time Models › Visualizing Accelerated Failure-Time Models

Michael BrenndoerferOctober 26, 20265 min read
Machine Learning from ScratchAll chapters
Part 6 of 15Survival Analysis
Chapter 51Accelerated Failure-Time Models › Visualizing Accelerated Failure-Time Models
Reading section 5 of 10 · Visualizing Accelerated Failure-Time Models · 5 minSection 5 of 10 · 5 min

Section 5 of 10 · 5 min read

Accelerated Failure-Time Models › Visualizing Accelerated Failure-Time ModelsSection view · Sections in this chapter5 / 10 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

The first figure shows how a positive covariate coefficient stretches log-normal survival to the right. At any fixed survival probability, the event-time quantile is multiplied by the same factor. The second figure holds log-time location and scale fixed and changes the error distribution from normal to minimum Gumbel. Equal location and scale do not imply equal medians across these families.

PythonIn [5]
CollapseExpand
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

beta0_vis = 1.00
beta1_vis = 0.45
sigma_vis = 0.60
t_grid_vis = np.linspace(0.15, 8.0, 400)


def lognormal_survival(t, eta, sigma):
    t = np.asarray(t, dtype=float)
    if sigma <= 0 or np.any(t < 0):
        raise ValueError("Use nonnegative times and a positive log-time scale.")
    with np.errstate(divide="ignore"):
        z = (np.log(t) - eta) / sigma
    return stats.norm.sf(z)


def weibull_survival(t, eta, sigma):
    t = np.asarray(t, dtype=float)
    if sigma <= 0 or np.any(t < 0):
        raise ValueError("Use nonnegative times and a positive log-time scale.")
    with np.errstate(divide="ignore", over="ignore"):
        z = (np.log(t) - eta) / sigma
        return np.exp(-np.exp(z))


eta0_vis = beta0_vis
eta1_vis = beta0_vis + beta1_vis
surv_ln0_vis = lognormal_survival(t_grid_vis, eta0_vis, sigma_vis)
surv_ln1_vis = lognormal_survival(t_grid_vis, eta1_vis, sigma_vis)
surv_w0_vis = weibull_survival(t_grid_vis, eta0_vis, sigma_vis)
time_ratio_vis = np.exp(beta1_vis)
ConsoleOut [6]
CollapseExpand
Time ratio exp(beta1): 1.568

The time ratio is computed from the generating coefficient rather than inserted by hand, so the printed value and the horizontal stretch in the first figure are guaranteed to agree.

VisualizationOut [7]
CollapseExpand
Two decreasing log-normal survival curves, with the x equals one curve to the right of the x equals zero curve.
Log-normal AFT survival curves for a coefficient of 0.45 comparing x = 0 and x = 1. The x = 1 curve sits to the right, showing that every conditional event-time quantile is multiplied by exp(0.45), about 1.568. Both curves decrease monotonically, and the gap between them is constant on the log time scale: at any fixed survival probability the x = 1 curve lies a factor of exp(0.45) farther to the right, so the additive horizontal gap grows with time. These are illustrative model curves.
VisualizationOut [8]
CollapseExpand
Two decreasing survival curves with the log-normal curve above the Weibull curve over the displayed grid.
Comparison of log-normal and Weibull survival curves at log-time location 1 and scale 0.6. The log-normal curve stays above the Weibull curve over this plotted grid, and the two diverge with different shapes rather than merely a shift. The gap illustrates how the error distribution changes the assumed survival curve despite equal location and scale.

The first figure illustrates the time ratio. If we draw a horizontal line at any survival probability, the intersection with the x=1x=1 curve occurs at a time exp⁡(β1)\exp(\beta_1) times farther to the right than the intersection with the x=0x=0 curve. Here exp⁡(0.45)=1.568\exp(0.45)=1.568, so the entire event-time distribution is stretched by about 57 percent. The second figure shows that the Weibull and log-normal models need not agree even when we give them the same log-time location and scale. Near the middle of the distribution they can be similar, while their tails differ. A model comparison should therefore emphasize the region of the survival curve that matters for the decision, not only the overall fit near the median.

The same comparison can be expressed as a hazard ratio between the two covariate profiles. For the Weibull model the ratio is constant because the proportional hazards representation holds. For the log-normal model the ratio generally changes with time, so a single hazard ratio does not summarize the covariate effect. The following calculation reuses the fixed coefficient and scale values from the survival-curve comparison; no estimation or random sampling is involved.

PythonIn [9]
CollapseExpand
# Reuse the fixed illustrative parameters and time grid from the preceding comparison.
t_hazard_ratio = t_grid_vis[(t_grid_vis >= 0.35) & (t_grid_vis <= 6.0)]
eta_hr0 = beta0_vis
eta_hr1 = beta0_vis + beta1_vis
sigma_hr = sigma_vis

z_hr0 = (np.log(t_hazard_ratio) - eta_hr0) / sigma_hr
z_hr1 = (np.log(t_hazard_ratio) - eta_hr1) / sigma_hr

hr_lognormal = (
    stats.norm.pdf(z_hr1) / (sigma_hr * t_hazard_ratio * stats.norm.sf(z_hr1))
) / (stats.norm.pdf(z_hr0) / (sigma_hr * t_hazard_ratio * stats.norm.sf(z_hr0)))

hr_weibull = np.full_like(
    t_hazard_ratio,
    np.exp(-beta1_vis / sigma_hr),
    dtype=float,
)

hr_ylim = (
    0.0,
    1.15 * max(hr_lognormal.max(), hr_weibull.max(), 1.0),
)
VisualizationOut [10]
CollapseExpand
Weibull hazard ratio stays constant while log-normal hazard ratio changes over time.
Hazard ratio for x = 1 versus x = 0 under the fixed log-normal and Weibull specifications. The Weibull hazard ratio is constant at exp(-0.45/0.6), while the log-normal hazard ratio varies with time. This is the practical difference between a Weibull proportional hazards representation and a log-normal AFT model.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy