Exemplo n.º 1
0
 def test_naf_plotting_with_custom_colours(self, block):
     data1 = np.random.exponential(5, size=(200, 1))
     data2 = np.random.exponential(1, size=(500))
     naf = NelsonAalenFitter()
     naf.fit(data1)
     ax = naf.plot(color="r")
     naf.fit(data2)
     naf.plot(ax=ax, c="k")
     self.plt.title('test_naf_plotting_with_custom_coloirs')
     self.plt.show(block=block)
     return
Exemplo n.º 2
0
 def test_naf_plot_cumulative_hazard(self, block):
     data1 = np.random.exponential(5, size=(200, 1))
     naf = NelsonAalenFitter()
     naf.fit(data1)
     ax = naf.plot()
     naf.plot_cumulative_hazard(ax=ax, ci_force_lines=True)
     self.plt.title(
         "I should have plotted the same thing, but different styles + color!"
     )
     self.plt.show(block=block)
     return
Exemplo n.º 3
0
 def test_naf_plotting_slice(self, block):
     data1 = np.random.exponential(5, size=(200, 1))
     data2 = np.random.exponential(1, size=(200, 1))
     naf = NelsonAalenFitter()
     naf.fit(data1)
     ax = naf.plot(ix=slice(0, None))
     naf.fit(data2)
     naf.plot(ax=ax, ci_force_lines=True, iloc=slice(100, 180))
     self.plt.title('test_naf_plotting_slice')
     self.plt.show(block=block)
     return
# In[23]:

get_ipython().magic(u'R p <- plot.ly("https://plot.ly/~rmdk/185/cumulativehazard-vs-time/")')
# pass object to python kernel
get_ipython().magic(u'R -o p')

# Render HTML
HTML(p[0])


# ### Using Python

# In[26]:

from lifelines.estimation import NelsonAalenFitter

naf = NelsonAalenFitter()
naf.fit(T, event_observed=C)

naf.plot(title='Nelson-Aalen Estimate')


# In[27]:

naf.plot(ci_force_lines=True, title='Nelson-Aalen Estimate')
py_p = plt.gcf()

pyplot(py_p, legend=False)

Exemplo n.º 5
0
def test_exponential_data_sets_fit():
    N = 20000
    T, C = exponential_survival_data(N, 0.2, scale=10)
    naf = NelsonAalenFitter()
    naf.fit(T, C).plot()
    plt.title("Should be a linear with slope = 0.1")
Exemplo n.º 6
0
 def test_smoothing_hazard_ties_all_events_observed(self):
     T = np.random.binomial(20, 0.7, size=300)
     naf = NelsonAalenFitter()
     naf.fit(T)
     naf.smoothed_hazard_(1.)
Exemplo n.º 7
0
 def test_smoothing_hazard_ties(self):
     T = np.random.binomial(20, 0.7, size=300)
     C = np.random.binomial(1, 0.8, size=300)
     naf = NelsonAalenFitter()
     naf.fit(T, C)
     naf.smoothed_hazard_(1.)
Exemplo n.º 8
0
 def test_iloc_slicing(self, waltons_dataset):
     naf = NelsonAalenFitter().fit(waltons_dataset['T'])
     assert naf.cumulative_hazard_.iloc[0:10].shape[0] == 10
     assert naf.cumulative_hazard_.iloc[0:-1].shape[0] == 32
Exemplo n.º 9
0
 def test_censor_nelson_aalen(self, sample_lifetimes):
     T, C = sample_lifetimes
     naf = NelsonAalenFitter(nelson_aalen_smoothing=False)
     naf.fit(T, C)
     npt.assert_almost_equal(naf.cumulative_hazard_.values, self.nelson_aalen(T, C))