I have been using the methods outlined in: Bender, Ralf, Thomas Augustin, and Maria Blettner, "Generating survival times to simulate Cox proportional hazards models," Statist. Med. 24: 1713–1723 (2005) to generate survival times from a dataset.
After building the Cox model, I specify a 'baseline patient' and use survfit
to estimate the cumulative baseline hazard function:
tmpdf <- data.frame(
age = mean(pdata$age),
o2_listing = 0,
group = "A",
func_status = median(pdata$func_status),
bmi_listing = mean(pdata$bmi),
pa_mean = mean(pdata$pa_mean),
reg_height = mean(pdata$reg_height),
pcw = mean(pdata$pcw),
ventilator = "N",
pros_inhale = 0,
egfr = mean(pdata$egfr),
gender = "F"
)
rc <- cph() # Model excluded for this post
sv <- survfit(rc, newdata = tmpdf)
I then use nls
to calculate the shape (v
) and scale(l
) parameters from the cumulative baseline hazard function:
c_haz <- sv$cumhaz
sv_t <- sv$time
fit <- nls(c_haz ~ l * sv_t^v, algorithm="port", start=list(l=1, v=1))
l <- coef(fit)[1]
v <- coef(fit)[2]
I can then use the techniques from (R. Bender 2005) to generate random survival times for each patient in the dataset. The calculation involves each patient's linear predictor (sometimes referred to as xb
or xbeta
in the code).
I can generate survival times by plugging each patient's xbeta
into the formula, however when comparing the real survival curve (black) to the simulated curve (blue) you can see the simulation overestimates survival:
I can also calculate the xbeta
for the reference patient:
reference_xb <- unname(predict(rc, newdata=tmpdf, type="lp"))
I can then subtract this reference_xb
from each patient's xbeta
, however this results in underestimating the survival:
However, if I take each patient's xbeta
, subtract the reference patient's reference_xb
and also subtract the population mean xbeta
the curve fits very well:
I have two main questions:
1 - Is my reasoning/methodology for generating survival times correct? (i.e. will the survival times generated from simulation be representative of the population being simulated?)
2 - I understand why it is necessary to subtract the reference patient's xbeta
, but why is it necessary to also subtract the mean xbeta
of the population?
survfit()
with respect to categorical predictors in producing baseline hazards changed in version 3.2-9, and I wonder if there's something going on with that. Also, if you're forcing this into a Weibull distribution anyway, is there some reason why you don't just usesurvreg()
from the start? $\endgroup$flexsurvreg()
and theweibullPH
distribution, the parameters it calculates are quite close to the ones I get withnls
but I could be convinced to redo the work usingsurvreg()
if it makes simulating survival times easier. $\endgroup$real_pop <- survfit(Surv(pdata$waittime, pdata$death_cens) ~ 1)
but I have also experimented with adding variables to the RHS for examplereal_pop <- survfit(Surv(pdata$waittime, pdata$death_cens) ~ pdata$age >= 55)
This results in two curves, but I still have to subtract both the patientxbeta
and population meanxbeta
for both the 'real' and simulated curves to line up. $\endgroup$