I have a covariate with time-varying coefficient with two categories (lets call it T), which I have modeled using the Royston-Parmar model from flexsurv package as following.

fit <- flexsurv::flexsurvspline(Surv(time, event) ~ T+gamma1(T)+A+B,data=data,k=1,scale="hazard")

where A and B are other covariates. I know that I can get the hazard rates as predictions for a new data using


where newdata has data on the covariate levels of interest.

newdata = data.frame(A= rep(25,2),
                    T= rep(c('T1', 'T2'), each=1), B=rep(5,2))

as the hazard rates are time-varying for T1 and T2, can I calculate hazard ratios at different time points by dividing the hazard rates at those specific time points?


1 Answer 1


For those not familiar with the flexsurv package, the gamma1(T) term in the model allows for a time-varying coefficient for the covariate T as part of the Royston-Parmar regression spline estimate of hazard over time.

A hazard ratio is just that: a ratio of hazards. So if you specify covariate values and a comparison time, then the ratio of hazard values gives you the hazard ratio at that specific time. In your situation that hazard ratio will necessarily vary over time, so it's not clear how useful that hazard ratio will be. Evaluation of cumulative hazards via asking for "cumhaz" might be more informative, as it tells you the relative hazards up through that time.

  • $\begingroup$ Thanks, yes, that is what I meant (silly mistake), edited the question to reflect that. In a usual analysis, the hazard ratio at that particular timepoint is not of interest, but for this specific analysis, I do need the hazard ratio at specific time points (instantaneous not cumulative), as a cluster of events early on in one treatment arm is not really indicative of the risk and I want to look at how that risk changes over time (instantaneous at different time points, not cumulative). Appreciate your answer again, really helpful. $\endgroup$
    – lvdp
    Aug 10, 2022 at 16:30

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.