-
Notifications
You must be signed in to change notification settings - Fork 28
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
predict.flexsurvreg #39
Comments
The typical functionality of predict is the same as what summary.flexsurvreg already does, except it returns a simple vector instead of a dataframe or list of dataframes. In order to avoid duplicate code, I think the best way to do this might be to take the existing code for summary, use it to write a predict method which returns a simple vector, then call predict from summary to add the predicted values to the dataframe(s). |
I've written a function for generating predictions from https://github.com/jwdink/tidysurv/blob/master/R/flexsurv-helpers.R It's probably lacking in some important functionality, but thought I'd share in case its helpful. |
Any thoughts/progress on this? I'd like to make |
I'll happily add this to play nicely with a tidyverse package! What would you need it to do? Would predicted means (as And what should be the returned format? A simple vector if no SEs are requested, or a matrix for multiple quantiles? What about with SEs? Would it have to return Ideologically I prefer to present CIs than SEs, but I can add SEs as well if that's what people want. |
Excellent!
Use "response" for for the mean response and "percentile" for others. Is there a parameter for the percentile in the
Yeah, that's not obvious (and we are coming up with a standard in tidymodels/parsnip#41). I'd say to keep everything in a data frame. For simple mean predictions, I would suggest having a column named Put the standard error in I'm not sure about the percentiles. Ideally, |
How about a list column? Basically, you can add a data frame column (more easily with tibbles) that contains each subject-specific data frame. It's pretty easy to adapt your current data structure to that (code below). You can still easily get to the single, stacked data frame easily (see the code at the end). Here's an example using one of the models in data(ovarian)
fitg <- flexsurvreg(formula = Surv(futime, fustat) ~ age, data = ovarian, dist="gengamma")
preds <- summary(fitg, newdata = ovarian[1:2, "age", drop = FALSE], t = c(100, 200, 300))
# set the names
preds <- lapply(preds, setNames, c(".time", ".pred", ".pred_lower", ".pred_upper"))
library(tibble)
preds <- tibble(.pred = preds)
preds
# if someone wants a single data frame, they could just:
tidyr::unnest(preds) |
I've uploaded a work in progress on As I understand it, your suggestion was to return a data frame with I'm not sure about having "prediction intervals" for this kind of model. |
The notion of prediction intervals would be complex here and I don't know of any censored regression packages that do that so I wouldn't worry about it. You could do it with Bayesian models really easily but otherwise it can be difficult to compute.
Based some feedback that we've gotten, I think that the optimal structure would be a list column of data frames (or tibbles). For the quantile code, that would look like:
Similar for probabilities, the columns would be > tidy_preds
# A tibble: 2 x 1
.pred
<list>
1 <tibble [3 × 4]>
2 <tibble [3 × 4]>
> tidy_preds$.pred[[1]]
# A tibble: 3 x 4
.time .pred .pred_lower .pred_upper
<dbl> <dbl> <dbl> <dbl>
1 100 0.799 0.484 0.966
2 200 0.485 0.128 0.806
3 300 0.278 0.0123 0.663 Always returning Looking at the Would we still use the
Yes please! How much would you want to use our prediction specification? It's not finalized yet but I feel pretty solid about what is in there. There are generally good ideas but we aren't trying to coerce people. |
Hi @chjackson, Any interest in resurrecting this issue? I would be interested in helping out and could start working on a PR. I am an avid user of the I also wanted to check whether you would be interested in a PR which would add a function for estimating cumulative incidence in the presence of competing-risks when modeling cause-specific hazards with flexible survival models ( Let me know! |
Thanks - happy for you to work on this. I've updated the current source a bit to make the TODOs clearer. I think the main thing left to do is to create those list columns when there's multiple predictions, and write examples that demonstrate how users can deal with them. Someone fluent in tidyverse would be appreciated for that. I'm actively working on multi-state model stuff at the moment. The package already has some functions in this area, but anything that enhances it would be welcome. Happy to discuss in another issue. |
Great to hear! I've got a deadline this Friday for one of my doctoral projects thats currently occupying most of my time. I am planning to spend some time this weekend to read over the relevant source code and get more familiar with what exactly needs to be done. I can start a new issue once I've got a better grasp on what the next steps might look like and we can discuss things further, if that works for you. I look forward to helping out in any way I can. |
@chjackson This can be closed, I think. Up to you. |
General function to return predictions, either corresponding to the observed data, or to a user-supplied "newdata". Should behave similarly to other predict methods in base R and common packages. Could return predictions as linear predictors for the location parameter, or on the scale of the response, e.g. mean or median survival.
The text was updated successfully, but these errors were encountered: