KM at_risk_counts intervals do not align with manually selected plot interval
See original GitHub issueI am trying to generate a K-M curve over 60 months with interval 12 (instead of 10, which is automatically selected). As demonstrated below, at_risk_counts do not align with 12 month intervals which I’ve manually set using set_xticks.
Example code is as follows:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lifelines import KaplanMeierFitter
df = pd.DataFrame({
'durations': [5, 32, 14, 55, 18, 29, 28, 39, 2, 1, 60, 7],
'events': [1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0]})
D = df['durations']
E = df['events']
kmf = KaplanMeierFitter()
kmf.fit(D, E,label="Kaplan-Meier Estimate")
ax = kmf.plot(ci_show=False, at_risk_counts=True) ## want at_risk_counts to be 12 month intervals
plt.tight_layout()
ax.set_xticks(range(0,61,12)) ## set x-axis ticks to represent 12 month intervals
ax.set_xlabel('Months')
ax.grid(b=True, axis='y')
plt.show()
I have also tried adding timeline=range(0,61,12) to kmf.fit, but this does not change the at_risk_counts interval. For ex:
kmf.fit(D, E, label="Kaplan-Meier Estimate", timeline=range(0,61,12))
ax = kmf.plot(ci_show=False, at_risk_counts=True) ## want at_risk_counts to be 12 month intervals
plt.tight_layout()
ax.set_xticks(range(0,61,12)) ## set x-axis ticks to represent 12 month intervals
ax.set_xlabel('Months')
ax.grid(b=True, axis='y')
plt.show()
Thank you in advance for any help.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Kaplan-Meier Survival Plotting Macro %NEWSURV
Confidence intervals are automatically added for graphs with no CLASS variable. Confidence intervals can be added as a filled background, as ...
Read more >lifelines Documentation - Read the Docs
We can call plot() on the KaplanMeierFitter itself to plot both the KM estimate and its confidence intervals: kmf.plot_survival_function().
Read more >sts graph, risktable(numlist) - Title Description Quick start Menu
atrisk show numbers at risk at beginning of each interval censored(single) show one hash mark at each censoring time, no matter what number...
Read more >lifelines/CHANGELOG.md at master - GitHub
Fixed an annoying bug where at_risk-table label's were not aligning properly when data spanned ... with intervals when no events would occur in...
Read more >AGENDA - KEYS Energy Services
a) Approve Resolution No. 21-01, Adopting the Monroe County and Incorporated. Municipalities Local Mitigation Strategy, 2020 Update.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @kadufendach, try this:
Hi @chrispoptic,
I’m hestitant to add a new kwarg to
plot_survival_function
- but here’s something you can try to specify the interval:Something like that?