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$ Feb 21, 2021 at 12:53

1 Answer 1


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$ Feb 22, 2021 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$ Feb 22, 2021 at 10:44
  • $\begingroup$ Sorry I don't use Python and have no idea. $\endgroup$ Feb 22, 2021 at 19:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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