chjackson / flexsurv

The flexsurv R package for flexible parametric survival and multi-state modelling
http://chjackson.github.io/flexsurv/
53 stars 28 forks source link

Sampling survival probabilities #38

Open jrdnmdhl opened 7 years ago

jrdnmdhl commented 7 years ago

Would be useful to have a way to generate a set of survival probabilities based on drawing a new set of parameters from mvnorm. This can effectively be done right now by taking either the lower or upper bound of the following:

testit = flexsurvreg(Surv(rectime,censrec)~group,data=bc,dist="weibull")
summary(testit, t=c(500,100),type="survival",ci=0.5,B=1,tidy=T)

But producing it this way is a bit of a kluge, so it would be good to have a more direct way of generating this.

chjackson commented 7 years ago

Does this do what you want, or do I misunderstand? This gives a sample of 10 alternative values for the 365-day survival probability, based on 10 random draws from the asymptotic normal distribution of the parameter estimates.

testit <- flexsurvreg(Surv(rectime,censrec)~group,data=bc,dist="weibull")
pars <- normboot.flexsurvreg(testit, B=10, newdata=list(group="Medium"))
testit$dfns$p(365, pars[,1], pars[,2], lower.tail=FALSE)
jrdnmdhl commented 7 years ago

The goal here is to produce survival probabilities at arbitrary times, but based on a single draw from the distribution of parameters. This might be necessary, for example, to run a single simulation of a probabilistic sensitivity analysis in a partitioned survival model, To slightly modify your example:

testit <- flexsurvreg(Surv(rectime,censrec)~group,data=bc,dist="weibull")
pars <- normboot.flexsurvreg(testit, B=1, newdata=list(group="Medium"))
testit$dfns$p(seq(from=0, to=1000, by=100), pars[,1], pars[,2], lower.tail=FALSE)

To have this functionality packaged as an S3 generic, like summary.flexsurvreg, would be useful.

chjackson commented 7 years ago

OK - I think it would be a worthwhile enhancement to summary.flexsurvreg to have the option to return a sample of B values for any required summary statistic, rather than a point estimate or a CI.

t-patton commented 4 years ago

Along similar lines to the comment by jrdnmdhl, is there any way that the pmatrix.fs() command can be adapted to draw from the distribution of parameters, in the case of a multistate model, for the purposes of a probabilistic sensitivity analysis?

chjackson commented 4 years ago

@t-patton The code for pmatrix.fs actually does this sampling if you request a confidence interval. It calls the function bootci.fmsm, which draws a sample, calculates the P matrix (or some other function) and takes their quantiles to get the confidence interval. You may be able to tweak these functions to get what you want - but I agree a user interface would be nice.

kkmann commented 1 year ago

Would be great to extend this (essentially parametric bootstrap?) to sim.fmsm and simulate.flexsurvreg - I think at the moment they do not consider parameter uncertainty, right? Edit: So, to generate predictions under paramter uncertainty, one would currently have to use boot or rsample packages to bootstrap the fitting itself. Quite expensive.