# Shape of HR after an intermediate event based on time to that event, multi-state model

**URL:** <https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707>\
**Category:** modeling strategy\
**Tags:** survival-analysis, r\
**Created:** [August 28, 2020, 8:06am UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707 "2020-08-28T08:06:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilja](https://discourse.datamethods.org/letter_avatar_proxy/v4/letter/i/8baadc/32.png) [@Ilja](https://discourse.datamethods.org/u/Ilja)\
**Post date:** [August 28, 2020, 8:06am UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/1 "2020-08-28T08:06:12Z")

</div>

Hello everyone!

This is my first post. I am a clinical oncologist and have basic knowledge in statistics and a lot of motivation to learn more. So please respond accordingly. I have searched this forum for an answer to my question but could not find it.

I currently working with epidemiology research. I have collected data for roughly 500 lymphoma patients over a 20 year span. Data include gender, date of diagnosis, age at diagnosis, date of eventual relapse, date of last follow up and status at last follow up.

I am interested to explore how the shape of hazard ratio after an intermediate event (in this case relapse) depends on the time to occurrence of this event and/or the sojourn time in this state. Obviously not all patients experience relapse and relapse timeframe differs from e.g. 1 months - 10 years after initial diagnosis. So from my understanding this is a multi state model with 3 states.

I could only find one paper addressing this issue: [https://pubmed.ncbi.nlm.nih.gov/23786493/](https://pubmed.ncbi.nlm.nih.gov/23786493/)  
As a clinician with basic programming skills in R, I could only understand the concept but I have no idea how to do this in R.

Question 1: I want to find background theory on this, e.g. book, paper  
Question 2: Can someone here open the subject and explain pros and cons of different methods in plain semi-easy statistical language  
Question 3: How can this be done in R, example code, at least how to start it.

Thank you all in advance, looking forward to a productive discussion.

---

<div class="post-metadata">

**Author:** ![albertoca](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/albertoca/32/297_2.png) [@albertoca](https://discourse.datamethods.org/u/albertoca)\
**Post date:** [August 28, 2020, 8:14am UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/2 "2020-08-28T08:14:36Z")

</div>

Hi, I’m an oncologist too. I guess you’ll get better advice here than my opinion but we did something similar last year with the flexsurv R package. Look at the plot, I think it’s just what you want.

> **[Multistate Models: Accurate and Dynamic Methods to Improve Predictions of...](https://pubmed.ncbi.nlm.nih.gov/31461750/)**
>
> Research into cancer-associated thrombosis (CAT) entails managing dynamic data that pose an analytical challenge. Thus, methods that assume proportional hazards to investigate prognosis entail a risk of misinterpreting or overlooking key traits or...

---

<div class="post-metadata">

**Author:** ![Ilja](https://discourse.datamethods.org/letter_avatar_proxy/v4/letter/i/8baadc/32.png) [@Ilja](https://discourse.datamethods.org/u/Ilja)\
**Post date:** [August 28, 2020, 8:30am UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/3 "2020-08-28T08:30:38Z")

</div>

Wow, you guys work fast here. Thank you so much.

For some reason I wasn´t able to access the full text:

# Not Found

The requested URL /HTML/sso/ejournals/login.htm&hook\_url=http://www.thieme-connect.com/products/ejournals/pdf/10.1055/s-0039-1694012.pdf was not found on this server.

Not sure what the problem is, I should have full access through my University.

---

<div class="post-metadata">

**Author:** ![albertoca](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/albertoca/32/297_2.png) [@albertoca](https://discourse.datamethods.org/u/albertoca)\
**Post date:** [August 28, 2020, 8:32am UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/4 "2020-08-28T08:32:30Z")

</div>

Look also here

> [@Hazard ratio plots with non-linear & time-varying effects in R](https://discourse.datamethods.org/t/hazard-ratio-plots-with-non-linear-time-varying-effects-in-r/1123):
>
> Good evening, I wanted to ask if someone could explain how to make in R a plot to represent a time-dependent hazard ratio with 95% CI, from a Cox model, as for example, the one I show below. I have tried hazard.ratio plot in rms or plot(cox.zph) but it is not exactly the same. Thank you very much.

---

<div class="post-metadata">

**Author:** ![Ilja](https://discourse.datamethods.org/letter_avatar_proxy/v4/letter/i/8baadc/32.png) [@Ilja](https://discourse.datamethods.org/u/Ilja)\
**Post date:** [August 28, 2020, 2:36pm UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/5 "2020-08-28T14:36:43Z")

</div>

Thanks, very nice paper.

Just want to clarify, so in the paper, “Dynamic effect of VTE”: In the log-logistic AFT models, the development of CAT shortened PFS and OS with adjusted TR of 0.72 (95% CI, 0.49–1.06)  
and 0.56 (95% CI, 0.43–0.74), respectively. Does this mean that VTE increased the hazard of mortality by 44%?

Also, I tried the R code provided in the supplement and got stuck at “Transitions-specific covariates” with a code line:

aga.ms$VTE\_td[aga.ms$trans == %] \<- &

Error: unexpected input in aga.ms$event\_td[aga.ms$trans==%] \<- &

Figure 1 in the paper, is the one I would want to re-create

I obviously used own dataset

---

<div class="post-metadata">

**Author:** ![albertoca](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/albertoca/32/297_2.png) [@albertoca](https://discourse.datamethods.org/u/albertoca)\
**Post date:** [August 28, 2020, 3:13pm UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/6 "2020-08-28T15:13:38Z")

</div>

No, it is an AFT model whose exponential coefficients should be interpreted as time ratios. It is well explained in the article. In this particular case, it means that the life span is shortened by 44% after a thrombotic event, taking into account the structure of a multi-state model (avoiding immortal time issues, etc). In the link there is a very beautiful vignette written by Chris Jackson who explains how to extract time-variant hazard ratios from this AFT model, and that is what we did.

> [@Hazard ratio plots with non-linear & time-varying effects in R](https://discourse.datamethods.org/t/hazard-ratio-plots-with-non-linear-time-varying-effects-in-r/1123/7):
>
> Thanks for the contribution. There is also an example code by Chris Jackson in this tutorial (example 2.1):

Regarding the R code, I recommend you to read and become familiar with the documentation of the mstate package in order to convert data to long format and obtain the structure of a multi-state model before fitting any model. Best.

---

<div class="post-metadata">

**Author:** ![Ilja](https://discourse.datamethods.org/letter_avatar_proxy/v4/letter/i/8baadc/32.png) [@Ilja](https://discourse.datamethods.org/u/Ilja)\
**Post date:** [August 28, 2020, 3:19pm UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/7 "2020-08-28T15:19:14Z")

</div>

Great, this is clear now. Reading this tutorial right now. Thanks you for for taking the time to answer and thank you for your patience. Best.

---

<div class="post-metadata">

**Author:** ![albertoca](https://discourse.datamethods.org/user_avatar/discourse.datamethods.org/albertoca/32/297_2.png) [@albertoca](https://discourse.datamethods.org/u/albertoca)\
**Post date:** [August 28, 2020, 3:41pm UTC](https://discourse.datamethods.org/t/shape-of-hr-after-an-intermediate-event-based-on-time-to-that-event-multi-state-model/3707/8 "2020-08-28T15:41:23Z")

</div>

This is the book I read for this:

> **[Competing Risks and Multistate Models with R | Jan Beyersmann | Springer](https://www.springer.com/gp/book/9781461420347)**
>
> This book covers competing risks and multistate models, sometimes summarized as event history analysis. These models generalize the analysis of time to a single event (survival analysis) to analysing the timing of distinct terminal events (competing...
