繪製共變數對生存的影響
有兩位受刑人正在候補出獄。你想用剛剛擬合好的 CoxPHFitter 模型來預測他們的再次被逮捕時間(time-to-arrest)的生存函式。兩人的共變數如下:
| Name | fin | age | wexp | mar | paro | prio |
|---|---|---|---|---|---|---|
| Jack | 0 | 35 | 0 | 1 | 1 | 3 |
| Marie | 1 | 22 | 0 | 0 | 0 | 0 |
請使用 cph 將 Jack 與 Marie 的生存曲線與基準生存曲線並排繪出。已為你載入擬合完成的模型 cph。
CoxPHFitter 類別已匯入,matplotlib.pyplot 模組已以 plt 匯入。pandas 與 numpy 分別以 pd、np 匯入。
本練習屬於課程
Python 的存活分析
練習說明
- 使用
.plot_partial_effects_on_outcome()指定 Jack 與 Marie 的共變數值(見上表),並繪出他們的生存曲線。 - 顯示圖表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot partial effects
cph.____(covariates=____,
values=____)
# Show plot
plt.show()