当前位置: 首页>>代码示例>>Python>>正文


Python estimation.KaplanMeierFitter类代码示例

本文整理汇总了Python中lifelines.estimation.KaplanMeierFitter的典型用法代码示例。如果您正苦于以下问题:Python KaplanMeierFitter类的具体用法?Python KaplanMeierFitter怎么用?Python KaplanMeierFitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了KaplanMeierFitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_kmf_with_risk_counts

 def test_kmf_with_risk_counts(self, block):
     data1 = np.random.exponential(10, size=(100))
     kmf = KaplanMeierFitter()
     kmf.fit(data1)
     kmf.plot(at_risk_counts=True)
     self.plt.title("test_kmf_with_risk_counts")
     self.plt.show(block=block)
开发者ID:DGaffney,项目名称:lifelines,代码行数:7,代码来源:test_plotting.py

示例2: score

def score(T_actual, labels, E_actual):
    '''
    Return a score based on grouping
    '''
    scores = []
    labels = labels.ravel()
    for g in ['high', 'mid', 'low']:
        members = labels == g
        
        if np.sum(members) > 0:
            kmf = KaplanMeierFitter()
            kmf.fit(T_actual[members],
                    E_actual[members],
                    label='{}'.format(g))
            
            # Last survival time
            if np.sum(E_actual[members]) > 0:
                lasttime = np.max(T_actual[members][E_actual[members] == 1])
            else:
                lasttime = np.nan
        
            # End survival rate, median survival time, member count, last event
            subscore = (kmf.survival_function_.iloc[-1, 0],
                        median_survival_times(kmf.survival_function_),
                        np.sum(members),
                        lasttime)
        else:
            # Rpart might fail in this respect
            subscore = (np.nan, np.nan, np.sum(members), np.nan)
            
        scores.append(subscore)
    return scores
开发者ID:spacecowboy,项目名称:article-annriskgroups-source,代码行数:32,代码来源:AnnVariables.py

示例3: test_passing_in_left_censorship_creates_a_cumulative_density

 def test_passing_in_left_censorship_creates_a_cumulative_density(self, sample_lifetimes):
     T, C = sample_lifetimes
     kmf = KaplanMeierFitter()
     kmf.fit(T, C, left_censorship=True)
     assert hasattr(kmf, 'cumulative_density_')
     assert hasattr(kmf, 'plot_cumulative_density_')
     assert not hasattr(kmf, 'survival_function_')
开发者ID:nerdless,项目名称:lifelines,代码行数:7,代码来源:test_estimation.py

示例4: test_stat_error_is_raised_if_too_few_early_deaths

 def test_stat_error_is_raised_if_too_few_early_deaths(self):
     observations = np.array([1,  1,  1, 22, 30, 28, 32, 11, 14, 36, 31, 33, 33, 37, 35, 25, 31,
                              22, 26, 24, 35, 34, 30, 35, 40, 39,  2])
     births = observations - 1
     kmf = KaplanMeierFitter()
     with pytest.raises(StatError):
         kmf.fit(observations, entry=births)
开发者ID:nerdless,项目名称:lifelines,代码行数:7,代码来源:test_estimation.py

示例5: test_show_censor_with_discrete_date

 def test_show_censor_with_discrete_date(self, block):
     T = np.random.binomial(20, 0.1, size=100)
     C = np.random.binomial(1, 0.8, size=100)
     kmf = KaplanMeierFitter()
     kmf.fit(T, C).plot(show_censors=True)
     self.plt.title('test_show_censor_with_discrete_date')
     self.plt.show(block=block)
     return
开发者ID:DGaffney,项目名称:lifelines,代码行数:8,代码来源:test_plotting.py

示例6: test_show_censor_with_index_0

 def test_show_censor_with_index_0(self, block):
     T = np.random.binomial(20, 0.9, size=100)  # lifelines should auto put a 0 in.
     C = np.random.binomial(1, 0.8, size=100)
     kmf = KaplanMeierFitter()
     kmf.fit(T, C).plot(show_censors=True)
     self.plt.title('test_show_censor_with_index_0')
     self.plt.show(block=block)
     return
开发者ID:DGaffney,项目名称:lifelines,代码行数:8,代码来源:test_plotting.py

示例7: test_flat_style_no_censor

 def test_flat_style_no_censor(self, block):
     data1 = np.random.exponential(10, size=200)
     kmf = KaplanMeierFitter()
     kmf.fit(data1, label='test label 1')
     ax = kmf.plot(flat=True, censor_styles={'marker': '+', 'mew': 2, 'ms': 7})
     self.plt.title('test_flat_style_no_censor')
     self.plt.show(block=block)
     return
开发者ID:DGaffney,项目名称:lifelines,代码行数:8,代码来源:test_plotting.py

示例8: test_kmf_minimum_observation_bias

def test_kmf_minimum_observation_bias():
    N = 250
    kmf = KaplanMeierFitter()
    T, C = exponential_survival_data(N, 0.1, scale=10)
    B = 0.01 * T
    kmf.fit(T, C, entry=B)
    kmf.plot()
    plt.title("Should have larger variances in the tails")
开发者ID:DGaffney,项目名称:lifelines,代码行数:8,代码来源:test_generate_datasets.py

示例9: test_kmf_left_censorship_stats

    def test_kmf_left_censorship_stats(self):
        # from http://www.public.iastate.edu/~pdixon/stat505/Chapter%2011.pdf
        T = [3, 5, 5, 5, 6, 6, 10, 12]
        C = [1, 0, 0, 1, 1, 1,  0,  1]
        kmf = KaplanMeierFitter()
        kmf.fit(T, C, left_censorship=True)

        actual = kmf.cumulative_density_[kmf._label].values 
        npt.assert_almost_equal(actual, np.array([0, 0.437500, 0.5833333, 0.875, 0.875, 1]))
开发者ID:nerdless,项目名称:lifelines,代码行数:9,代码来源:test_estimation.py

示例10: test_negative_times_still_plots

 def test_negative_times_still_plots(self, block):
     n = 40
     T = np.linspace(-2, 3, n)
     C = np.random.randint(2, size=n)
     kmf = KaplanMeierFitter()
     kmf.fit(T, C)
     ax = kmf.plot()
     self.plt.title('test_negative_times_still_plots')
     self.plt.show(block=block)
     return
开发者ID:DGaffney,项目名称:lifelines,代码行数:10,代码来源:test_plotting.py

示例11: test_kmf_survival_curve_output_against_R

    def test_kmf_survival_curve_output_against_R(self):
        df = load_g3()
        ix = df['group'] == 'RIT'
        kmf = KaplanMeierFitter()

        expected = np.array([[0.909, 0.779]]).T
        kmf.fit(df.ix[ix]['time'], df.ix[ix]['event'], timeline=[25, 53])
        npt.assert_array_almost_equal(kmf.survival_function_.values, expected, decimal=3)

        expected = np.array([[0.833, 0.667, 0.5, 0.333]]).T
        kmf.fit(df.ix[~ix]['time'], df.ix[~ix]['event'], timeline=[9, 19, 32, 34])
        npt.assert_array_almost_equal(kmf.survival_function_.values, expected, decimal=3)
开发者ID:nerdless,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例12: test_shifting_durations_doesnt_affect_survival_function_values

    def test_shifting_durations_doesnt_affect_survival_function_values(self):
        T = np.random.exponential(10, size=100)
        kmf = KaplanMeierFitter()
        expected = kmf.fit(T).survival_function_.values

        T_shifted = T + 100
        npt.assert_almost_equal(expected, kmf.fit(T_shifted).survival_function_.values)

        T_shifted = T - 50
        npt.assert_almost_equal(expected[1:], kmf.fit(T_shifted).survival_function_.values)

        T_shifted = T - 200
        npt.assert_almost_equal(expected[1:], kmf.fit(T_shifted).survival_function_.values)
开发者ID:nerdless,项目名称:lifelines,代码行数:13,代码来源:test_estimation.py

示例13: test_kmf_confidence_intervals_output_against_R

    def test_kmf_confidence_intervals_output_against_R(self):
        # this uses conf.type = 'log-log'
        df = load_g3()
        ix = df['group'] != 'RIT'
        kmf = KaplanMeierFitter()
        kmf.fit(df.ix[ix]['time'], df.ix[ix]['event'], timeline=[9, 19, 32, 34])

        expected_lower_bound = np.array([0.2731, 0.1946, 0.1109, 0.0461])
        npt.assert_array_almost_equal(kmf.confidence_interval_['KM_estimate_lower_0.95'].values,
                                      expected_lower_bound, decimal=3)

        expected_upper_bound = np.array([0.975, 0.904, 0.804, 0.676])
        npt.assert_array_almost_equal(kmf.confidence_interval_['KM_estimate_upper_0.95'].values,
                                      expected_upper_bound, decimal=3)
开发者ID:nerdless,项目名称:lifelines,代码行数:14,代码来源:test_estimation.py

示例14: test_seaborn_doesnt_cause_kmf_plot_error

    def test_seaborn_doesnt_cause_kmf_plot_error(self, block, kmf, capsys):
        import seaborn as sns

        df = load_waltons()

        T = df['T']
        E = df['E']

        kmf = KaplanMeierFitter()
        kmf.fit(T, event_observed=E)
        kmf.plot()

        self.plt.title('test_seaborn_doesnt_cause_kmf_plot_error')
        self.plt.show(block=block)
        _, err = capsys.readouterr()
        assert err == ""
开发者ID:springcoil,项目名称:lifelines,代码行数:16,代码来源:test_plotting.py

示例15: test_flat_style_and_marker

 def test_flat_style_and_marker(self, block):
     data1 = np.random.exponential(10, size=200)
     data2 = np.random.exponential(2, size=200)
     C1 = np.random.binomial(1, 0.9, size=200)
     C2 = np.random.binomial(1, 0.95, size=200)
     kmf = KaplanMeierFitter()
     kmf.fit(data1, C1, label='test label 1')
     ax = kmf.plot(flat=True, censor_styles={'marker': '+', 'mew': 2, 'ms': 7})
     kmf.fit(data2, C2, label='test label 2')
     kmf.plot(ax=ax, censor_styles={'marker': 'o', 'ms': 7}, flat=True)
     self.plt.title("testing kmf flat styling + marker")
     self.plt.show(block=block)
     return
开发者ID:DGaffney,项目名称:lifelines,代码行数:13,代码来源:test_plotting.py


注:本文中的lifelines.estimation.KaplanMeierFitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。