Suppose you are interested in the Survival modelling technique Cox Proportional Hazard, where we model the hazard as:

$$ \lambda(t \vert x) = \lambda_0(t) exp (\beta x) $$

An extension of this model is time-varying covariates i.e.

$$ \lambda(t \vert x(t)) = \lambda_0(t) exp (\beta x(t)) $$

Another extension is time-dependent effects i.e.:

$$ \lambda(t \vert x) = \lambda_0(t) exp (\beta(t)x) $$

I am interested in time-varying covariates and have strong prior beliefs over the coefficients of the covariates (in the partial hazard) as well as the baseline. I have seen examples of Bayesian survival modelling (with Cox PHD) where you have time-dependent effects (i.e. a sequence of regression coefficients), see this example using PyMC3 and Python:

However, in the situation where you have time varying covariates, I am yet to find an example or implementation of this in python (or R for that matter). My question is:

  1. Is there a reason why you do not see implementations of Bayesian time-varying covariates COX PHD?
  2. If no to the above, does anyone have a good example of an implementation?

Many thanks

  • 1
    $\begingroup$ How many distinct event times are there in your data? If you happen to have a discrete time problem this is easier to handle. $\endgroup$ – Frank Harrell Feb 21 at 12:53

If you get the development version of rstanarm package, it has function called stan_surv that allows for time-varying coefficients in Bayesian survival models. Importantly, you can even model flexible baseline hazards with M and B splines. You can find out more here:



  • $\begingroup$ Thanks Brant. Do you know if this covers time varying covariates as well as time varying coefficients? $\endgroup$ – Jonny Kisch Feb 22 at 10:18
  • $\begingroup$ Seems to does...do you also happen to know if the python implementation Survivalstan has the same features developed as the R implementation with stan_surv? $\endgroup$ – Jonny Kisch Feb 22 at 10:44
  • $\begingroup$ Sorry I don't use Python and have no idea. $\endgroup$ – Brant Inman Feb 22 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.