生存数据的右删失可视化
Right censoring visualization of survival data
我想知道是否有办法生成这样的图表
使用生存数据。例如假设我们有这个数据框
d = {'time_in_weeks': [0, 10, 20, 30, 50, 170], 'failure_status': [0, 0, 0, 0, 1, 1]}
df = pd.DataFrame(data=d)
我们如何创建后一个图表?
import seaborn as sns
import pandas as pd
d = {'time_in_weeks': [0, 10, 20, 30, 50, 170], 'failure_status': [0, 0, 0, 0, 1, 1]}
这可能是一个好的开始
df = pd.DataFrame(data=d)
df['marker'] = df['failure_status'].map({0:'o',1:'x'})
for x in df.marker.unique():
t = df.loc[df['marker']==x]
g = sns.scatterplot(data=t, x='time_in_weeks', y=t.index.tolist(), marker=x, s=100,color='black')
for index, row in df.iterrows():
g.hlines(y=index, xmin=0, xmax=row['time_in_weeks'], linewidth=2, color='black')
lifelines 内置了这个:https://lifelines.readthedocs.io/en/latest/lifelines.plotting.html#lifelines.plotting.plot_lifetimes
from lifelines.plotting import plot_lifetimes
plot_lifetimes(df['time_in_weeks'], df['failure_status'], event_observed_color="k", event_censored_color="k")
我想知道是否有办法生成这样的图表
使用生存数据。例如假设我们有这个数据框
d = {'time_in_weeks': [0, 10, 20, 30, 50, 170], 'failure_status': [0, 0, 0, 0, 1, 1]}
df = pd.DataFrame(data=d)
我们如何创建后一个图表?
import seaborn as sns
import pandas as pd
d = {'time_in_weeks': [0, 10, 20, 30, 50, 170], 'failure_status': [0, 0, 0, 0, 1, 1]}
这可能是一个好的开始
df = pd.DataFrame(data=d)
df['marker'] = df['failure_status'].map({0:'o',1:'x'})
for x in df.marker.unique():
t = df.loc[df['marker']==x]
g = sns.scatterplot(data=t, x='time_in_weeks', y=t.index.tolist(), marker=x, s=100,color='black')
for index, row in df.iterrows():
g.hlines(y=index, xmin=0, xmax=row['time_in_weeks'], linewidth=2, color='black')
lifelines 内置了这个:https://lifelines.readthedocs.io/en/latest/lifelines.plotting.html#lifelines.plotting.plot_lifetimes
from lifelines.plotting import plot_lifetimes
plot_lifetimes(df['time_in_weeks'], df['failure_status'], event_observed_color="k", event_censored_color="k")