累积风险
四组市场中新药上市的 Nelson–Aalen 累积风险,附 95% 置信带。

累积风险 H(t) 将事件的瞬时风险随时间累加;它是“迄今为止累积的风险”,并通过 S(t) = exp(−H(t)) 与生存函数相联系。与生存曲线不同,它不以 1 为上界,其斜率就是风险本身——直线意味着风险恒定,向上弯曲的曲线则意味着风险随时间增长。
背景为 Hadengue、de Marcellis-Warin 和 Warin (2015, Management international),研究制药行业的逆向创新与逆向技术转移。此处数据为说明用途的模拟数据,并非论文的数据或结果:400 个药品–市场组合,以年计量从药品在全球首次获批到在某一市场上市的时间,分为四组市场。观察结束时尚未上市的药品作删失处理。曲线来自 lifelines.NelsonAalenFitter,副标题报告四组之间的 log-rank 检验(multivariate_logrank_test)。横轴截止于 6 年,此后上市最快的几组中仍处于风险中的药品太少。
代码及图中文字均为英文。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from lifelines import NelsonAalenFitter
from lifelines.statistics import multivariate_logrank_test
# Simulated data, set in the context of Hadengue, de Marcellis-Warin & Warin (2015) [hadengue2015]
# Data: years from first approval to launch, 100 drugs in each of four market groups
rng = np.random.default_rng(2015)
rates = {"United States": 0.5, "Western Europe": 0.33, "Japan": 0.22, "China": 0.12} # launches per year
df = pd.concat([pd.DataFrame({"market": m, "launch": rng.weibull(1.3, 100) / r}) for m, r in rates.items()])
cens = rng.uniform(2, 10, len(df)) # end of observation for each drug
df["years"], df["launched"] = np.minimum(df.launch, cens), (df.launch <= cens).astype(int)
colors = ["#007AFF", "#34C759", "#FF9500", "#FF3B30"]
fig, ax = plt.subplots(figsize=(8, 5))
# Nelson–Aalen estimate with 95% CI, one curve per market group, first 6 years, while enough drugs remain at risk
for g, c in zip(rates, colors):
d = df[df.market == g]
naf = NelsonAalenFitter().fit(d.years, d.launched, label=g)
H, ci = naf.cumulative_hazard_[g].loc[:6].copy(), naf.confidence_interval_.loc[:6].copy()
H.loc[6], ci.loc[6] = H.iloc[-1], ci.iloc[-1]
ax.step(H.index, H, where="post", color=c, lw=2, label=f"{g} (n = {len(d)}, {d.launched.sum()} launches)")
ax.fill_between(ci.index, ci.iloc[:, 0], ci.iloc[:, 1], step="post", color=c, alpha=0.13, lw=0)
# Log-rank test across market groups
lr = multivariate_logrank_test(df.years, df.market, df.launched)
p_txt = "p < .001" if lr.p_value < 0.001 else f"p = {lr.p_value:.3f}"
ax.legend(loc="upper left")
ax.set(xlabel="Years since first approval anywhere", ylabel="Cumulative hazard of launch H(t)",
xlim=(0, 6), xticks=range(7), ylim=(0, None))
ax.set_title("Nelson–Aalen cumulative hazard of launch for four market groups", pad=26)
ax.text(0, 1.02, f"Nelson–Aalen with 95% CI · log-rank χ²({lr.degrees_of_freedom}) = "
f"{lr.test_statistic:.1f}, {p_txt} · n = {len(df)} drug–market pairs (simulated), "
f"{df.launched.sum()} launches", transform=ax.transAxes, fontsize=9.5, color="#6E6E73")
plt.show()
图表使用了可选的 PyStatlas 样式:添加 plt.style.use("pystatlas.mplstyle") 即可完全还原其外观。
数据来源
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - Hadengue, de Marcellis-Warin & Warin (2015), reverse innovation in pharmaceuticals. Hadengue, M., de Marcellis-Warin, N., & Warin, T. (2015). Reverse innovation and reverse technology transfer: From made in China to discovered in China in the pharmaceutical sector. Management international, 19(4), 49–69. https://doi.org/10.7202/1043076ar
The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.
这些示例用于说明统计方法。除条目另有说明外,其数值均为模拟数据,图表标题描述的是该图在这些模拟数据中呈现的内容——既不是所引论文的结论,也不是作者对实质问题的立场。关于结果、背景和数据,请以此处引用的论文为准。
如何引用
PyStatlas 由 Thierry Warin 创建并维护。如果它对你的工作有所帮助,敬请引用。
Warin, T. (2026). Cumulative hazard. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/survival/cumulative-hazard/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}