Accelerated Failure-Time Models › Visualizing Accelerated Failure-Time Models
Machine Learning from ScratchAll chapters 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
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]Expand
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]Expand
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]Expand

VisualizationOut [8]Expand

The first figure illustrates the time ratio. If we draw a horizontal line at any survival probability, the intersection with the curve occurs at a time times farther to the right than the intersection with the curve. Here , 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]Expand
# 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]Expand

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!