Generating data from KM curves I have some survival data from different cohorts and can fit Kaplan Meier curves and cox proportional hazard models. I want to be able to simulate data that resembles the data found in say the KM curves.  What I would like to know is there any way to simulate data from the KM curves or the cox proportional hazard model?
 A: Certainly. 
Remember that the KM curves are estimates of the survival function, ie $\hat S_{km}(t)$. As such, you can simulate draws from this distribution by using the inverse survival function, i.e. 
$u_i \sim $ uniform(0,1)
$T_i = S_{km}^{-1}(u_i)$
Then $T_i$ will be distributed according the distribution in the KM curve. Note that the KM curve will be a discrete distribution, while the original data generating process may be continuous. Also, this does not take into account the uncertainty in the KM curves. 
Here's how one could do this in R: 
library(survival)
y <- rexp(100)
isCen <- y > 2
y[isCen] <- 2
fit <- survfit(Surv(y, !isCen) ~ 1 )
quantile(fit, probs = runif(1) )$quantile

Very technically speaking, a Cox-PH model does not necessarily include an estimated baseline survival distribution, which is required to sample from. However, this can be easily remedied by using the KM curves as the baseline survival estimate. Of course, the following method can be used for any proportional hazards model and baseline survival estimate.
From here, we use the relation that if $\eta_i = X^T \beta$ (i.e. the linear predictor for subject i), the estimated proportional hazards survival curve will be $S(t | \eta_i)$ = $S_o(t)^{\exp(\eta_i)}$ where $S_o(t)$ is the baseline survival curve. 
Being extra clever, we can then see that
$S^{-1}(u | \eta_i) = S_o^{-1}(u^{\exp(-\eta_i)})$
So given $\hat S_o^{-1}$ and $\eta_i$, we can take draws via
$u_i \sim$ uniform(0,1)
$T_i = \hat S_o^{-1}(u^{\exp(-\eta_i)})$
A: @CliffAB has provided a very good answer (+1).  Let me add a couple of additional possibilities:  


*

*You can try various parametric survival models to see if you can find a distribution that is a reasonable fit.  Then you can sample from that distribution using standard techniques.  (For a simple example of generating censored survival data from a Weibull distribution, see my answer here: How to simulate censored data.)  

*You can also bootstrap your data, which will take your sample distributions as estimates of the population distributions.  This will be more informative if your samples are larger and better behaved.  (The results here should be essentially the same as @CliffAB's strategy.  That is, this gives you another way of understanding the strategy he suggested.)  

