You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Name of QuantLet: ISP_lifelinesDemoPublished in: An Introduction to Statistics with PythonDescription: 'Demonstration of the package <lifelines> Based on the demo-code in http://lifelines.readthedocs.org, by Cam Davidson-Pilon'Keywords: logrank test, kaplan-meier curve Author: Thomas Haslwanter Submitted: October 31, 2015
''' Demonstration of the package "lifelines"Based on the demo-code in http://lifelines.readthedocs.org, by Cam Davidson-Pilon'''# Copyright(c) 2015, Thomas Haslwanter. All rights reserved, under the CC BY-SA 4.0 International License# Import standard packagesimportnumpyasnpimportmatplotlib.pyplotaspltfromnumpy.randomimportuniform, exponentialimportos# additional packagesfromlifelines.plottingimportplot_lifetimesimportsyssys.path.append(os.path.join('..', '..', 'Utilities'))
try:
# Import formatting commands if directory "Utilities" is availablefromISP_mystyleimportsetFontsexceptImportError:
# Ensure correct performance otherwisedefsetFonts(*options):
return# Generate some dummy datanp.set_printoptions(precision=2)
N=20study_duration=12# Note: a constant dropout rate is equivalent to an exponential distribution!actual_subscriptiontimes=np.array([[exponential(18), exponential(3)][uniform()<0.5] foriinrange(N)])
observed_subscriptiontimes=np.minimum(actual_subscriptiontimes,study_duration)
observed=actual_subscriptiontimes<study_duration# Show the datasetFonts(18)
plt.xlim(0,24)
plt.vlines(12, 0, 30, lw=2, linestyles="--")
plt.xlabel('time')
plt.title('Subscription Times, at $t=12$ months')
plot_lifetimes(observed_subscriptiontimes, event_observed=observed)
print("Observed subscription time at time %d:\n"%(study_duration), observed_subscriptiontimes)