#!/usr/bin/env python # coding: utf-8 # # # # Divorce Rates # In[1]: from lifelines.estimation import AalenAdditiveFitter import pandas as pd import numpy as np import patsy get_ipython().run_line_magic('pylab', 'inline') # In[3]: data = pd.read_csv('../lifelines/datasets/divorce.dat', sep="\s{2,10}") # In[4]: data.head(10) # In[5]: df = patsy.dmatrix('heduc + heblack + heblack:mixed + years + mixed + div -1 ', data, return_type='dataframe') # In[6]: df.head() # In[130]: aaf = AalenAdditiveFitter(fit_intercept=True, coef_penalizer=1.) # In[131]: df.columns # In[132]: timeline = np.linspace(0, 35, 1000) # In[133]: aaf.fit(df, 'years', event_col='div[T.Yes]', timeline=timeline) # In[134]: figsize(12.5, 8.5) #aaf.cumulative_hazards_.ix[:][["baseline"]].plot() #aaf.cumulative_hazards_.ix[:][["bb","bw","wb","ww"]].plot() aaf.cumulative_hazards_.plot() plt.legend(loc='upper left') # In[ ]: # In[ ]: # In[ ]: