# Sampling data from a Cox proportional hazard model [duplicate]

Is it possible to simulate event time T from a distribution that depends on two variables A and Z but the hazard function conditioning on A only follows a proportional hazards model?

• Does this answer your question? How to simulate survival times using true base line hazard function. For the effect of A you can just multiply the cumulative hazard function by the HR. For the effect of Z, you just need to estimate separate strata if there is no proportional hazard. Feb 26, 2021 at 16:47

It's not completely clear how your variable Z comes into the event-time model, but simulation should be straightforward. Parametric PH models would probably be simplest, as they are based on well known probability distributions. If you insist on a Cox model, however, functions like survfit() in R can also generate survival curves as a function of time and covariate values. With specified values of $$A$$ and $$Z$$ and a survival function $$S(t|A,Z)$$, you can use sampling from a uniform distribution to sample from the cumulative distribution of event times $$F(t|A,Z)=1-S(t|A,Z)$$, as for any 1-dimensional probability distribution. You will, however, need to decide how to handle late event times if you use a Cox model for which the last time point isn't an event.