def test_aalen_additive_fit_with_censor(self, block): n = 2500 d = 6 timeline = np.linspace(0, 70, 10000) hz, coef, X = generate_hazard_rates(n, d, timeline) X.columns = coef.columns cumulative_hazards = pd.DataFrame(cumulative_integral( coef.values, timeline), index=timeline, columns=coef.columns) T = generate_random_lifetimes(hz, timeline) T[np.isinf(T)] = 10 X["T"] = T X["E"] = np.random.binomial(1, 0.99, n) aaf = AalenAdditiveFitter() aaf.fit(X, "T", "E") for i in range(d + 1): ax = self.plt.subplot(d + 1, 1, i + 1) col = cumulative_hazards.columns[i] ax = cumulative_hazards[col].loc[:15].plot(ax=ax) ax = aaf.plot(loc=slice(0, 15), ax=ax, columns=[col]) self.plt.title("test_aalen_additive_fit_with_censor") self.plt.show(block=block) return
def test_aalen_additive_fit_with_censor(self): # this is a visual test of the fitting the cumulative # hazards. matplotlib = pytest.importorskip("matplotlib") from matplotlib import pyplot as plt n = 2500 d = 6 timeline = np.linspace(0, 70, 10000) hz, coef, X = generate_hazard_rates(n, d, timeline) X.columns = coef.columns cumulative_hazards = pd.DataFrame(cumulative_integral(coef.values, timeline), index=timeline, columns=coef.columns) T = generate_random_lifetimes(hz, timeline) X['T'] = T X['E'] = np.random.binomial(1, 0.99, n) aaf = AalenAdditiveFitter() aaf.fit(X, 'T', 'E') for i in range(d + 1): ax = plt.subplot(d + 1, 1, i + 1) col = cumulative_hazards.columns[i] ax = cumulative_hazards[col].ix[:15].plot(legend=False, ax=ax) ax = aaf.plot(ix=slice(0, 15), ax=ax, columns=[col], legend=False) plt.show()
def test_aalen_additive_fit_with_censor(self, block): # this is a visual test of the fitting the cumulative # hazards. matplotlib = pytest.importorskip("matplotlib") from matplotlib import pyplot as plt n = 2500 d = 6 timeline = np.linspace(0, 70, 10000) hz, coef, X = generate_hazard_rates(n, d, timeline) X.columns = coef.columns cumulative_hazards = pd.DataFrame(cumulative_integral(coef.values, timeline), index=timeline, columns=coef.columns) T = generate_random_lifetimes(hz, timeline) X['T'] = T X['E'] = np.random.binomial(1, 0.99, n) aaf = AalenAdditiveFitter() aaf.fit(X, 'T', 'E') for i in range(d + 1): ax = plt.subplot(d + 1, 1, i + 1) col = cumulative_hazards.columns[i] ax = cumulative_hazards[col].ix[:15].plot(legend=False, ax=ax) ax = aaf.plot(ix=slice(0, 15), ax=ax, columns=[col], legend=False) plt.show(block=block) return
def test_aalen_additive_fit_no_censor(self, block): n = 2500 d = 6 timeline = np.linspace(0, 70, 10000) hz, coef, X = generate_hazard_rates(n, d, timeline) X.columns = coef.columns cumulative_hazards = pd.DataFrame(cumulative_integral(coef.values, timeline), index=timeline, columns=coef.columns) T = generate_random_lifetimes(hz, timeline) X['T'] = T X['E'] = np.random.binomial(1, 1, n) aaf = AalenAdditiveFitter() aaf.fit(X, 'T', 'E') for i in range(d + 1): ax = self.plt.subplot(d + 1, 1, i + 1) col = cumulative_hazards.columns[i] ax = cumulative_hazards[col].loc[:15].plot(legend=False, ax=ax) ax = aaf.plot(loc=slice(0, 15), ax=ax, columns=[col], legend=False) self.plt.title("test_aalen_additive_fit_no_censor") self.plt.show(block=block) return