-
Notifications
You must be signed in to change notification settings - Fork 12
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
Make sure all models can handle out of domain survival probability predictions #10
Comments
Here's some code to get probability estimates from the library(survival)
library(flexsurv) # <- test against this
l_norm <- survreg(Surv(futime, fustat) ~ ecog.ps + rx, ovarian, dist = "lognormal")
l_norm_2 <- flexsurvreg(Surv(futime, fustat) ~ ecog.ps + rx, data = ovarian, dist = "lnorm")
para_survival <- function(object, time, location, scale = object$scale, ...) {
distr <- object$dist
tibble::tibble(
.time = time,
.prob_survival = 1 - psurvreg(time, location, distribution = distr, scale, ...)
)
}
para_hazard <- function(object, time, location, scale = object$scale, ...) {
distr <- object$dist
prob <-
dsurvreg(time, location, scale, distribution = distr, ...) /
(1 - psurvreg(time, location, distribution = distr, scale, ...))
tibble::tibble(
.time = time,
.prob_hazard = prob
)
}
surv_via_survival <- para_survival(l_norm, time = 1:300, predict(l_norm, head(ovarian, 1), type = "lp"))
surv_via_flexsurv <- summary(l_norm_2, newdata = head(ovarian, 1), type = "survival", t = 1:300)[[1]]
all.equal(surv_via_flexsurv$est, surv_via_survival$.prob_survival, tol = .0001)
haz_via_survival <- para_hazard(l_norm, time = 1:300, predict(l_norm, head(ovarian, 1), type = "lp"))
haz_via_flexsurv <- summary(l_norm_2, newdata = head(ovarian, 1), type = "hazard", t = 1:300)[[1]]
all.equal(haz_via_flexsurv$est, haz_via_survival$.prob_hazard, tol = .0001) I'll put this in a PR soon. |
I see you using the Lines 53 to 61 in 14acd77
|
thanks @mattwarkentin ! 🙌 |
That's great. Would you like to do a PR for that? (We ask them for this a while back I think) |
I'm not sure what you mean. A PR for this package or a PR for The |
This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue. |
No description provided.
The text was updated successfully, but these errors were encountered: