Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique baseline hazard for each strata #268

Merged
merged 6 commits into from
Dec 29, 2016

Conversation

CamDavidsonPilon
Copy link
Owner

New PR to replace #196

cc @jstoxrocky and @IVANBARRIENTOS

cp = CoxPHFitter(normalize=False)
cp.fit(rossi, 'week', 'arrest', strata=['race', 'paro', 'mar', 'wexp'], include_likelihood=True)
npt.assert_almost_equal(cp.baseline_cumulative_hazard_[(0, 0, 0, 0)].ix[[14, 35, 37, 43, 52]].values, [0.28665890, 0.63524149, 1.01822603, 1.48403930, 1.48403930], decimal=2)
npt.assert_almost_equal(cp.baseline_cumulative_hazard_[(0, 0, 0, 1)].ix[[27, 43, 48, 52]].values, [0.35738173, 0.76415714, 1.26635373, 1.26635373], decimal=2)
Copy link
Owner Author

@CamDavidsonPilon CamDavidsonPilon Dec 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the baseline hazards are only slightly off, and so the errors accumulate in the cumulative. I'd like to understand why my values are slightly different. @IVANBARRIENTOS, is there a way I can access the non-cumulative hazards?

Also: any others tests you would recommend?

s_0 = self.baseline_survival_
col = _get_index(X)
return pd.DataFrame(-np.dot(np.log(s_0), v.T), index=self.baseline_survival_.index, columns=col)
if self.strata:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved this logic from the predict_survival function to the more "higher up" function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

return pd.DataFrame(-np.dot(np.log(s_0), v.T), index=self.baseline_survival_.index, columns=col)
if self.strata:
cumulative_hazard_ = pd.DataFrame()
for stratum, stratified_X in X.groupby(self.strata):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cute use of groupby here

@@ -306,7 +308,7 @@ def test_both_concordance_index_function_deal_with_ties_the_same_way():
actual_times = np.array([1, 1, 2])
predicted_times = np.array([1, 2, 3])
obs = np.ones(3)
assert fast_cindex(actual_times, predicted_times, obs) == slow_cindex(actual_times, predicted_times, obs) == 1.0
assert fast_cindex(actual_times, predicted_times, obs) == slow_cindex(actual_times, predicted_times, obs) == 1.0

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all white space changes in this file

cp = CoxPHFitter(normalize=False)
cp.fit(rossi, 'week', 'arrest', strata=['race', 'paro', 'mar', 'wexp'])
npt.assert_almost_equal(cp.baseline_cumulative_hazard_[(0, 0, 0, 0)].ix[[14, 35, 37, 43, 52]].values, [0.28665890, 0.63524149, 1.01822603, 1.48403930, 1.48403930], decimal=2)
npt.assert_almost_equal(cp.baseline_cumulative_hazard_[(0, 0, 0, 1)].ix[[27, 43, 48, 52]].values, [0.35738173, 0.76415714, 1.26635373, 1.26635373], decimal=2)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the baseline hazards are only slightly off, and so the errors accumulate in the cumulative. I'd like to understand why my values are slightly different. @IVANBARRIENTOS, is there a way I can access the non-cumulative hazards?

Also: any others tests you would recommend?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think it's because my estimates of beta are slightly off, and this is just a manifestation of that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue here: #272

@CamDavidsonPilon CamDavidsonPilon force-pushed the unique_baseline_hazard_for_each_strata branch from 33f680d to 74b865d Compare December 29, 2016 16:37
@CamDavidsonPilon CamDavidsonPilon merged commit 29cc72e into master Dec 29, 2016
@CamDavidsonPilon CamDavidsonPilon deleted the unique_baseline_hazard_for_each_strata branch December 29, 2016 16:51
@ibarrien
Copy link

ibarrien commented Dec 29, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants