I'm trying to find a method to detect local maximum points for hazard function (plotted using lifelines library).
Lifelines library gives you the ability to plot visually the hazard function ( plot.hazard() ) but - as said - it's only the visual representation of the funcion and not the function itself. This means that you can't, apparently, pass this function as an argument to methods (i.e: find_peaks from scipy.signals library).
I'm wondering if anyone has a solution to detect those, please find below how I've calculated my hazard function (plot on the far right where I've highlighted the local max):
fig, (ax1, ax2, ax3) = plt.subplots(1, 3,figsize=(18,8))
km.fit(duration, event_observed = event)
kap = km.plot_survival_function(ax=ax1,legend="")
kap.set_title("Kaplan-Meier",fontsize=15)
na.fit(duration, event_observed = event)
na1 = na.plot_cumulative_hazard(ax=ax2,legend="",color="green")
na1.set_title("Cumulative Hazard",fontsize=15)
bandwidth = 5
na2 = na.plot_hazard(ax=ax3,xlim=(0,200),ylim=(0,0.03),bandwidth=bandwidth,color="orange",legend="")
na2.set_title("Hazard Function",fontsize=15)
ax3.set_xlabel('timeline',fontsize = 10)
plt.grid(linestyle="-.", color='grey')
Thanks to anyone who will help me.
Stefano
Something like
na.smoothed_hazard_(bandwidth)
.