Cox モデルのハザード比
特許登録までの期間に関する Cox モデルのフォレストプロット(HR、95% CI、p 値付き)。

Cox 比例ハザードモデルは、各共変量がイベントの瞬間的なリスクを何倍にするかを推定します。ここでの「リスク」は登録される確率なので、ハザード比が 1 を超えれば登録が 速い ことを意味します。各行は ハザード比(HR)とその 95% 信頼区間を対数スケールで示しているため、半分になる場合と2倍になる場合は、HR = 1 の基準線から等しい距離に位置します。右側の表には、論文に掲載されるフォレストプロットと同様に数値を再掲しています。
設定は Vorreuther & Warin (2021, Data in Brief) で、中国の医薬品産業における特許の関連性と登録の速さに関するデータセットです。ここでのデータは説明のために シミュレーション したもので、論文のデータや結果ではありません。医薬品の特許出願 400 件を出願から登録まで月単位で追跡し、請求項の数、出願人の種類、出願人の過去の特許との Jaccard 関連度を共変量としています。モデルは lifelines.CoxPHFitter で当てはめ、サブタイトルにはコンコーダンス指数とモデル全体の尤度比検定を示しています。
コードおよび図中のテキストは英語です。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from lifelines import CoxPHFitter
# Simulated data, set in the context of Vorreuther & Warin (2021) [vorreuther2021]
# Data: months from filing to grant of 400 patent applications (shared generator)
rng = np.random.default_rng(2021)
n = 400
df = pd.DataFrame({"foreign": rng.integers(0, 2, n), "university": (rng.random(n) < 0.25).astype(int),
"claims": rng.poisson(12, n), "relatedness": rng.beta(2, 4, n).round(2)})
lp = 0.6 * df.foreign - 0.04 * (df.claims - 12) + 2.0 * (df.relatedness - 0.33) - 0.35 * df.university
grant = 40 * rng.weibull(2, n) * np.exp(-lp / 2) # Weibull PH: higher lp, faster grant
cens = rng.uniform(24, 96, n) # end of observation window
df["months"], df["granted"] = np.minimum(grant, cens).round(1), (grant <= cens).astype(int)
# Cox model: claims per 10, relatedness per 0.1 so that hazard ratios are readable
X = df.assign(claims=df.claims / 10, relatedness=df.relatedness * 10)
cph = CoxPHFitter().fit(X, duration_col="months", event_col="granted")
lr = cph.log_likelihood_ratio_test()
# Tidy the summary: HR, 95% CI, p-value
labels = {"foreign": "Foreign applicant", "university": "University applicant",
"claims": "Claims (per 10)", "relatedness": "Relatedness (per 0.1 Jaccard)"}
res = cph.summary.rename(columns={"exp(coef)": "hr", "exp(coef) lower 95%": "low",
"exp(coef) upper 95%": "high"})
res = res.sort_values("hr")
y = np.arange(len(res))
colors = np.where(res.p < 0.05, np.where(res.hr > 1, "#FF3B30", "#007AFF"), "#AEAEB2")
fig, (ax, tab) = plt.subplots(1, 2, figsize=(9, 4.8), sharey=True,
gridspec_kw=dict(width_ratios=[3, 1.3]))
# Forest: CI whiskers and point estimates on a log axis
ax.axvline(1, color="#8E8E93", lw=1, ls="--", zorder=1)
ax.hlines(y, res.low, res.high, color=colors, lw=2.5, zorder=2)
ax.scatter(res.hr, y, s=80, marker="s", color=colors, edgecolor="white", lw=1.2, zorder=3)
ax.set_xscale("log")
ax.set_xticks([0.4, 0.6, 1, 1.5, 2.5], ["0.4", "0.6", "1", "1.5", "2.5"])
ax.minorticks_off()
ax.set_xlim(0.26, 3)
ax.set_yticks(y, [labels[t] for t in res.index])
ax.grid(axis="x"); ax.grid(axis="y", visible=False)
ax.set_xlabel("Hazard ratio (log scale)")
ax.text(0.98, -0.6, "faster grant", ha="right", color="#FF3B30", fontsize=9,
transform=ax.get_yaxis_transform())
ax.text(0.02, -0.6, "slower grant", ha="left", color="#007AFF", fontsize=9,
transform=ax.get_yaxis_transform())
# Table: HR [95% CI] and p-value
for yi, (_, r) in zip(y, res.iterrows()):
p = "< .001" if r.p < 0.001 else f"{r.p:.3f}".lstrip("0")
tab.text(0.22, yi, f"{r.hr:.2f}", va="center", ha="right", fontsize=10, color="#1D1D1F")
tab.text(0.27, yi, f"[{r.low:.2f}, {r.high:.2f}]", va="center", fontsize=10, color="#6E6E73")
tab.text(1, yi, p, va="center", ha="right", fontsize=10,
color="#1D1D1F" if r.p < 0.05 else "#8E8E93",
fontweight="semibold" if r.p < 0.05 else "normal")
tab.text(0.22, len(res) - 0.3, "HR", ha="right", fontsize=9.5, color="#6E6E73", fontweight="semibold")
tab.text(0.27, len(res) - 0.3, "95% CI", fontsize=9.5, color="#6E6E73", fontweight="semibold")
tab.text(1, len(res) - 0.3, "p", ha="right", fontsize=9.5, color="#6E6E73", fontweight="semibold")
tab.set(xlim=(0, 1), ylim=(-1, len(res)))
tab.axis("off")
ax.set_title("What speeds up or slows down a patent grant?", pad=26)
ax.text(0, 1.02, f"Cox PH · n = {n} applications (simulated), {df.granted.sum()} grants · C = "
f"{cph.concordance_index_:.2f} · LR χ²({lr.degrees_freedom:.0f}) = {lr.test_statistic:.1f}, "
f"p < .001", 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. - Vorreuther & Warin (2021), patent velocity in China's pharmaceutical industry. Vorreuther, C. M., & Warin, T. (2021). Patent relatedness and velocity in the Chinese pharmaceutical industry: A dataset of Jaccard similarities. Data in Brief, 35, 106814. https://doi.org/10.1016/j.dib.2021.106814
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). Cox hazard ratios. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/survival/cox-hazard-ratios/
@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}
}生存時間分析のその他のグラフ
カプラン・マイヤー曲線
特許の出願から登録までの期間、国内出願人と外国出願人の比較 — ログランク検定とリスク集合の表付き。
survminer::ggsurvplot(risk.table = TRUE)累積ハザード
4 つの市場グループにおける医薬品発売の Nelson–Aalen 累積ハザード(95% 帯付き)。
survminer::ggsurvplot(fun = "cumhaz")調整済み生存曲線
関連度の 4 つの水準について Cox モデルで予測した特許登録までの期間(他の共変量は平均値)。
survminer::ggadjustedcurves()