Non-proportional Weibull hazard model with heaviside functions I am trying to model a non-constant (and non-linear) hazard ratio  between two groups (Group A and Group B), assuming that the baseline hazard for one of the groups can be described with the Weibull hazard function. I suppose that using heaviside functions to estimate non-proportional hazards (i.e. assume that hazard ratios between two groups remain constant only within of separate time intervals) would be a good and relatively simple solution to solve the problem with the selected parametric failure (survival) model. 
However, I haven't seen any examples in the literature how to do it. May I ask to suggest references or examples (would be great if someone would give an example by using "R") how to perform such study? Many thanks for all suggestions, and apologize if this question was asked before (but I was not able find it)!
 A: Say that you have K intervals where you want to keep the hazard ratio constant. Denote the hazard in group A is $\lambda(t) e^{\beta(t)}$ and in group B $\lambda(t)$. In this case you can write 
$$\beta(t)=\beta_1 1(t<t_1) + \beta_2 1(t_1<t_2) + ...$$ so you would have $K$ coefficients to estimate in the end.
Then: for the chosen intervals delimited by $t_1 ... t_K$ put the data in the (tstart, tstop, event) format with cuts at $t_1 ... t_K$. 
For example if an individual has the event at time $\tau$ which falls in the interval $[t_k, t_k+1)$ then his data would look like 
(0, t_1, 0), 
(t_1, t_2, 0) ... 
(t_k, \tau, 1). 
Then you'll need a column enum to indicate which interval we are in. For group B, this will be 0. For group A, (0, t_1, 0) has 1, (t_1, t_2, 0) has 2, etc. Then you can run your regression model with +factor(enum). The estimated regression coefficients would then be the log hazard ratios for the intervals you selected. 
Note that you should make sure that in each interval there are enough events in both group A and group B in order to be able to compare the two groups. 
