如何解决Kaplan Meier Curve 未显示删失数据的刻度
我正在用 python 绘制 Kaplan Meier 曲线。我的 KMC 很好,但它没有在我的数据中显示右删失案例的刻度。我尝试了很多来显示刻度,这是我为此编写的代码。我不知道为什么他们没有出现。如果有人可以帮助找出问题及其解决方法,我将不胜感激。这是我的图 https://ibb.co/bPfFMxY
非常感谢!
Python 代码:
def draw_KMC():
# In actual code file,here are some code lines before drawing the KMC but for the sake of simplicity I am not adding those
# ---- First Curve
legend_label_1 = "Category A"
kmf_1 = KaplanMeierFitter()
kmf_1.fit(durations = survival_times_A,event_observed=events_A,label=legend_label_A)
# ---- Second Curve
legend_label_2 = "Category B"
kmf_2 = KaplanMeierFitter()
kmf_2.fit(durations = survival_times_B,event_observed=events_B,label=legend_label_B)
# ---- Third Curve
legend_label_3 = "Category C"
kmf_3 = KaplanMeierFitter()
kmf_3.fit(durations = survival_times_C,event_observed=events_C,label=legend_label_C)
ax = plt.subplot(111)
plt.yticks(np.arange(0.0,1.1,0.1),['0','10','20','30','40','50','60','70','80','90','100'])
kmf_1.plot(ax=ax,show_censors=True,ci_show=False,censor_styles={"marker": "|","ms":
6} )
kmf_2.plot(ax=ax,"ms":
6})
kmf_3.plot(ax=ax,"ms": 6})
plt.xlabel('Months since the completion date',fontsize=12)
plt.ylabel('Proportion of studies w.r.t categories (%)')
plt.grid(True)
from lifelines.plotting import add_at_risk_counts
add_at_risk_counts(kmf_1,kmf_2,kmf_3,ax=ax)
plt.show()
我什至尝试用 kmf.plot_survival_function () 替换 kmf.plt() ,但它没有任何区别,也没有刻度出现审查数据。
解决方法
我试图在本地重现您的问题,但没有看到您观察到的行为。你可以试试下面的简化代码:
survival_times_A = [10.9,15.5,20.3,25.6,30.8]
events_A = [True,False,True,True]
legend_label_A="test"
# In actual code file,here are some code lines before drawing the KMC but for the sake of simplicity I am not adding those
# ---- First Curve
legend_label_1 = "Category A"
kmf_1 = KaplanMeierFitter()
kmf_1.fit(durations = survival_times_A,event_observed=events_A,label=legend_label_A)
ax = plt.subplot(111)
plt.yticks(np.arange(0.0,1.1,0.1),['0','10','20','30','40','50','60','70','80','90','100'])
kmf_1.plot(ax=ax,show_censors=True,ci_show=False,censor_styles={"marker": "o","ms":
60} )
plt.xlabel('Months since the completion date',fontsize=12)
plt.ylabel('Proportion of studies w.r.t categories (%)')
plt.grid(True)
from lifelines.plotting import add_at_risk_counts
add_at_risk_counts(kmf_1,ax=ax)
plt.show()
可能发生的情况是,您有太多的数据点,以至于审查标记被“挤压”掉了。
另外,您能告诉我们您使用的是什么版本的 lifelines
吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。