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
Return correct standard errors in tidy.survfit()
#1162
base: main
Are you sure you want to change the base?
Conversation
…lity with objects reformulated by `survfit0()`
Thanks for the PR! I'm seeing
in tests. Looks like this may be related to 03a4662—could you address that failure? |
…lity with objects reformulated by `survfit0()`
Welcome! I addressed the failure, and also made this a bit more robust by using the same conditional statement as survival does to check if the standard errors need to be fixed. Should be good now. |
Alright, got it. Thanks again for putting this together! After sitting with this for a bit, I think our best move here is to better document the current output. While the current output takes a moment of pause to interface with (and is certainly documented incorrectly), it is true to survival's implementation, and transitioning to a mix-and-match of slots of both the original object and its summary feels like a lateral move in terms of clarity/safety. At another point in the package's lifecycle, I may have considered adding a Would you be up for updating that documentation? |
I'm up for updating the documentation. You're right that that would be more consistent with the information stored in
However, I think this will lead to real errors in practice, as people generally assume the standard error next to an estimate to correspond to that estimate, not a different estimate that isn't shown. As an alternative, would it be possible to add some sort of |
A |
tidy.survfit()
currently returns standard errors for the cumulative hazard instead of the survival probability. This PR fixes this so that standard errors for the survival probability are returned. This makes the output consistent withsummary.survfit
.Here's a blog post covering the sneaky behaviour of standard errors in
survival
. The short version is thatfit$std.err
(whichtidy.survfit()
currently uses) returns the standard errors for the cumulative hazard, whereassummary(fit)$std.err
returns the standard errors for the survival probabilities.Created on 2023-06-03 with reprex v2.0.2
Edit
After using this on some examples, I think it's better to calculate manually instead of using
summary()
; otherwise you get an error when using survfit objects that have been reformulated withsurvfit0()
due to incompatible numbers of rows.I've updated the PR to use the calculations done in the survival package instead of
summary()
like in the reprex above.For reference, here are the relevant line in survival's source code.
survfit
:https://github.com/therneau/survival/blob/e8de7b732daa9a82c1ceaad93fd68ee7545c7736/R/survfitms.R#L178
survfitms
:https://github.com/therneau/survival/blob/e8de7b732daa9a82c1ceaad93fd68ee7545c7736/R/survfitms.R#L375