In [1]:
import os
#os.chdir('/Users/q6600sl/IPython_NB')
from lifemodels import s_models
%matplotlib inline
In [2]:
#Read the data
original_df = pd.read_csv('/Users/q6600sl/Downloads/SP_12-22-15.txt', sep=' ')
#1st step: create a survival object
surv_df = s_models.survt_df(original_df)
In [3]:
original_df.head()
Out[3]:
In [4]:
gp3_fit = s_models.distfit_df(surv_df, 'gp3')
In [5]:
gp3_fit.mdl_all_free
Out[5]:
In [6]:
gp3_fit.var
Out[6]:
.logq() method.logq(key, q), key is genotype here. q is that target % of death. q is default to 50%, therefore by default it returns the estimate for medium lifespan.
.logq() method and .logq_nc() method are similar: the latter ignores the Makehamm term, if there is one.
In [7]:
(gp3_fit.logq('Mut-1'), gp3_fit.logq_nc('Mut-1'))
Out[7]:
In [8]:
medium_df = pd.DataFrame({'With_C' : map(gp3_fit.logq, gp3_fit.mdl_all_free.index),
'Without_C': map(gp3_fit.logq_nc, gp3_fit.mdl_all_free.index)},
index=gp3_fit.mdl_all_free.index)
np.exp(medium_df)
Out[8]:
In [9]:
ax = medium_df.plot(kind='bar', alpha=0.5)
ax.set_ylim(3, 4.5)
right_y = ax.twinx()
right_y.set_ylim(3, 4.5)
_ = right_y.set_yticklabels(map('{:.2f}'.format, np.exp(right_y.get_yticks())))
ax.set_ylabel('Medium survival time in log(days)')
right_y.set_ylabel('Medium survival time in days')
plt.title('Medium lifespan estimated based on Gompertz Makeham Model', y=1.05)
Out[9]:
In [10]:
(gp3_fit.logm('Mut-1'), gp3_fit.logm_nc('Mut-1'))
Out[10]:
In [11]:
gp3_fit.logt_var('Mut-1', 3.9)
Out[11]:
In [12]:
f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(16, 5))
plot_par = {'logy' : True,
'alpha': 0.5,
'color': list('BBBBBR')}
np.exp(gp3_fit.mdl_all_free).ix[:, 'alpha'].plot(kind='bar', ax=ax1, **plot_par)
np.exp(gp3_fit.mdl_all_free).ix[:, 'beta'].plot(kind='bar', ax=ax2, **plot_par)
np.exp(gp3_fit.mdl_all_free).ix[:, 'c'].plot(kind='bar', ax=ax3, **plot_par)
ax1.set_title(r'Gompertz $\alpha$')
ax2.set_title(r'Gompertz $\beta$')
ax3.set_title(r'Gompertz $C$')
plt.suptitle('Gompertz Makeham Model parameter estimates', fontsize=16, y=0.99)
Out[12]:
In [13]:
f, axes = plt.subplots(2, 3, figsize=(14, 8), sharex=True, sharey=True)
axes = axes.ravel()
for ax, key in zip(axes, gp3_fit.mdl_all_free.index.tolist()):
gp3_fit.plot(key, np.linspace(0,80,100),ax,'hzd')
ax.set_ylim((-8,1))
ax.set_title(key)
plt.suptitle('log-harzard plot', fontsize=20)
Out[13]:
In [14]:
f, axes = plt.subplots(2, 3, figsize=(14, 8), sharex=True, sharey=True)
axes = axes.ravel()
for ax, key in zip(axes, gp3_fit.mdl_all_free.index.tolist()):
gp3_fit.plot(key, np.linspace(0,80,100),ax,'sf')
ax.set_ylim((-0.01,1.01))
ax.set_title(key)
plt.suptitle('survival plot', fontsize=20)
Out[14]:
In [ ]: