調整済み生存曲線

関連度の 4 つの水準について Cox モデルで予測した特許登録までの期間(他の共変量は平均値)。

調整済み生存曲線

ハザード比は感覚的にとらえにくいものですが、生存曲線ならわかりやすくなります。ここでは当てはめた Cox 比例ハザードモデルを用いて、出願人の過去の特許との関連度だけが異なり、他のすべての共変量は標本平均に固定した仮想的な出願について、曲線全体を 予測 しています。曲線間の横方向の開きは、関連度の効果を登録までの待ち月数に置き換えたものです。

設定は Vorreuther & Warin (2021, Data in Brief) で、中国の医薬品産業における特許の関連性と登録の速さに関するデータセットです。ここでのデータは説明のために シミュレーション したもので、論文のデータや結果ではありません。医薬品の特許出願 400 件で、関連度は 0 から 1 の Jaccard 類似度で測っています。モデルは lifelines.CoxPHFitter で 4 つの共変量すべてを用いて当てはめ、曲線は predict_survival_function() によるものです。参考として、標本全体で観測されたカプラン・マイヤー曲線を灰色で描いています。

コードおよび図中のテキストは英語です。

adjusted-survival.py · 53 行
ダウンロード GitHub
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from lifelines import CoxPHFitter, KaplanMeierFitter
# 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)

cph = CoxPHFitter().fit(df, duration_col="months", event_col="granted")

# Hypothetical applications: everything at the mean, relatedness varies
levels = [0.1, 0.3, 0.5, 0.7]
profiles = pd.DataFrame([df.drop(columns=["months", "granted"]).mean()] * len(levels))
profiles["relatedness"] = levels
surv = cph.predict_survival_function(profiles, times=np.arange(0, 73))
colors = plt.cm.Blues(np.linspace(0.4, 0.95, len(levels)))

fig, ax = plt.subplots(figsize=(8, 5))

# Observed Kaplan–Meier curve of the whole sample, for reference
km = KaplanMeierFitter().fit(df.months, df.granted)
ax.step(km.survival_function_.index, km.survival_function_.iloc[:, 0], where="post",
        color="#AEAEB2", lw=1.5, ls="--", label=f"Observed Kaplan–Meier, all {n} applications")

# Model-predicted curves, with the predicted median time to grant in the legend
for col, r, c in zip(surv.columns, levels, colors):
    s = surv[col]
    med = s.index[(s <= 0.5).argmax()]
    ax.step(s.index, s, where="post", color=c, lw=2.2,
            label=f"relatedness = {r:.1f}  ·  median {med:.0f} months")
ax.axhline(0.5, color="#C7C7CC", lw=1, zorder=0)
ax.legend(loc="upper right")

hr = np.exp(0.1 * cph.params_["relatedness"])
lo, hi = np.exp(0.1 * cph.confidence_intervals_.loc["relatedness"])
p = cph.summary.loc["relatedness", "p"]
p_txt = "p < .001" if p < 0.001 else f"p = {p:.3f}"
ax.set(xlim=(0, 72), ylim=(0, 1.01), xticks=range(0, 73, 12),
       xlabel="Months since filing", ylabel="Predicted probability still pending")
ax.yaxis.set_major_formatter(plt.matplotlib.ticker.PercentFormatter(1, decimals=0))
ax.set_title("Applications related to earlier patents are granted sooner, all else equal", pad=26)
ax.text(0, 1.02, f"Cox PH, other covariates at their mean  ·  HR per 0.1 relatedness = "
        f"{hr:.2f} [{lo:.2f}, {hi:.2f}], {p_txt}  ·  n = {n} (simulated)",
        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). Adjusted survival curves. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/survival/adjusted-survival/

@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}
}

生存時間分析のその他のグラフ