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

tidy.survfit() could use survival:::summary.survfit() new data.frame argument #1237

Open
ThomasSoeiro opened this issue Jan 29, 2025 · 0 comments

Comments

@ThomasSoeiro
Copy link

ThomasSoeiro commented Jan 29, 2025

FYI, survival:::summary.survfit() has recently gained a data.frame argument (since therneau/survival@4a5c24e available in {survival} 3.7-0 release on 2024-06-05). tidy.survfit() may probably use that and be simplified once {survival} 3.7-0 is considered old enough.

Note that the standard errors return by survival::survfit() and survival:::summary.survfit() are different:

  • from survival::survfit():

    for a survival curve this contains standard error of the cumulative hazard or -log(survival), for a multi-state curve it contains the standard error of prev.

  • from survival:::summary.survfit():

    the standard error of the survival value.

library(survival)
fit <- survfit(Surv(time, status) ~ x, aml)

x <- broom::tidy(fit)

y <- summary(fit, censored = TRUE, data.frame = TRUE)
y <- y[c(1:5, 7, 10:9, 11)]
y$strata <- as.character(y$strata)

# from https://github.com/cran/survival/blob/36b56a5d8014d3a5ed29fb111303955e3e28f13f/R/summary.survfit.R#L187-L190
y$std.err <- y$std.err / y$surv
y[is.na(y$std.err), "std.err"] <- Inf

all.equal(x, y, check.attributes = FALSE)
# [1] TRUE
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

No branches or pull requests

1 participant