Closed sapaca closed 1 year ago
I suspect it's because you are re-assigning the kmf
variable, so the last iteration defines what kmf
is (which is a KaplanMeierFitter trained only on data where mar=1).
I suggest breaking this into something like:
kmfs = {}
for name, grouped_df in df.groupby('mar'):
kmf = KaplanMeierFitter(alpha=alpha)
kmf.fit(durations=grouped_df['week'], event_observed=grouped_df['arrest'], label=name)
kmfs[name] = kmf
And then you have access to all kfms:
print(kmfs[0]. confidence_interval_)
print(kmfs[1]. confidence_interval_)
Perfect, thank you. That works for me, I appreciate it!
For this code:
After running the fit above and executing this:
kmf.confidence_interval_
only 1 class is generated for the output table even though plotting will show the CI estimates (shaded area) for all classes in the column of interest. In the below output I would expect to see a 0_lower_0.95 and 0_upper_0.5 column as well.