-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
n.risk
at time == 0
is not correct when nlevels(strata) > 1
in fortify.survfit(*, surv.connect = TRUE)
#229
Comments
n.risk
value for time == 0
is not correct when length(strata) > 1
in fortify.survfit()
.n.risk
value for time == 0
is not correct when nlevels(strata) > 1
in fortify.survfit()
.
n.risk
value for time == 0
is not correct when nlevels(strata) > 1
in fortify.survfit()
.n.risk
at time == 0
is not correct when nlevels(strata) > 1
in fortify.survfit(*, surv.connect = TRUE)
Hi @terrytangyuan, |
Please submit a PR with additional test cases. Thanks! |
FYI, I've just realized that a much better fix would be to use library(survival)
fit <- survfit(Surv(time, status) ~ x, aml)
summary(fit, times = 0)
# Call: survfit(formula = Surv(time, status) ~ x, data = aml)
#
# x=Maintained
# time n.risk n.event survival std.err lower 95% CI upper 95% CI
# 0 11 0 1 0 1 1
#
# x=Nonmaintained
# time n.risk n.event survival std.err lower 95% CI upper 95% CI
# 0 12 0 1 0 1 1
# Edit: Also note that the standard errors return by
# get the fix from https://github.com/sinhrks/ggfortify/pull/230
remotes::install_github("sinhrks/ggfortify@5de6565")
library(survival)
fit <- survfit(Surv(time, status) ~ x, aml)
x <- ggfortify:::fortify.survfit(fit, surv.connect = TRUE)
y <- rbind(
summary(fit, times = 0, data.frame = TRUE),
summary(fit, censored = TRUE, data.frame = TRUE)
)
levels(y$strata) <- sub("x=", "", levels(y$strata), fixed = TRUE)
# 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[names(x)])
# [1] TRUE |
System information
Describe the problem
n.risk
attime == 0
is not correct whennlevels(strata) > 1
infortify.survfit(*, surv.connect = TRUE)
.Source code / logs / plots
The issue is from:
ggfortify/R/fortify_surv.R
Line 65 in 5ed9524
Maybe it can be changed to
d[d$time == ave(d$time, d$strata, FUN = min), ]
.And then this will need to be simplified:
ggfortify/R/fortify_surv.R
Lines 73 to 79 in 5ed9524
The text was updated successfully, but these errors were encountered: