Comments (6)
I see you using the summary.flexsurvreg
method for predictions (both here and in the package source code). You may wish to use predict.flexsurvreg
which I've implemented to be very tidy-friendly.
Lines 53 to 61 in 14acd77
from censored.
Here's some code to get probability estimates from the survival
package (verified against flexsurv
):
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.
from censored.
thanks @mattwarkentin ! 🙌
from censored.
That's great. Would you like to do a PR for that?
(We ask them for this a while back I think)
from censored.
I'm not sure what you mean. A PR for this package or a PR for {flexsurv}
?
The predict.flexsurvreg
method has been available in the dev version since 2020-06-10 and on CRAN since flexsurv
version 2.0 (2021-02-22), I believe.
from censored.
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.
from censored.
Related Issues (20)
- Use cli errors HOT 1
- Use rlang type-checkers
- `predict()` on a glmnet workflow with a model formula fails HOT 5
- Simplify structure of survival prob predictions for `decision_tree(engine = "rpart")` HOT 1
- Simplify structure of survival prob predictions for `rand_forest(engine = "aorst")` HOT 2
- glmnet and sparse matrices HOT 2
- Enable `multi_predict()` for `type = "time"` for glmnet models HOT 2
- `survival_prob_orsf()` should take a parnip model HOT 2
- update tests for `aorsf` version 0.1.2 HOT 4
- `multi_predict()` for `mboost` models
- Update `.filter_eval_time()` HOT 1
- Harmonize input for `survival_prob_*()` and `surival_time_*()` functions HOT 1
- tune_grid() and tune_bayes() do not work with censored HOT 4
- Enable predictions with `type = "time"` for aorsf HOT 1
- Release censored 0.3.0 HOT 1
- `coxnet_train()` struggles with large number of predictors
- Test flexsurv engine against flexsurv output instead of rms
- Release censored 0.3.1 HOT 1
- survival 3.7-0 breaks censored HOT 1
- Release censored 0.3.2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from censored.