Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting hazard ratios by time

    Hi,

    I have some time-to-event data for two interventions and would like to plot the hazard ratio for two interventions over time.

    For example, using the hip fracture data used by Cleves, Gould & Marchenko in their book "An Introduction to Survival Analysis Using Stata" (3rd Edition), I can graph the smoothed hazards over time for each of two groups (protect = 1 & protect = 0) as follows:
    Code:
    use http://www.stata-press.com/data/cggm3/hip2, clear
    sts graph, hazard by (protect)
    Is there a command that I could use to plot the ratio of the hazards for protect = 1 and protect = 0 over time (i.e., a plot with Hazard ratio on the y-axis and Analysis time on the x-axis)?

  • #2
    There isn't a changing HR over time for your treatment group as you have described it. The is a single, constant HR over all analysis time. This is the meaning of proportional hazards in such a model. The baseline hazards may change but their ratio is constant.

    Comment


    • #3
      Thank you for taking the time to respond, Leonardo. The example I gave does not reflect my actual data. In my dataset, the baseline hazards change over time and the hazard ratio is not constant over time (i.e., the proportional hazards assumption is violated). I'm sorry that I may not have worded my question as well as I could have - perhaps another way of wording my question might be - is it possible to get the values of the (smoothed) hazards for each of the interventions at equivalent time points so I can produce a plot with the ratio of the hazards on the y-axis and time on the x-axis (such that if the ratio of the hazards was constant over time [which is not the case with the actual data but may be the case with the hip fracture data], then, the plot would be of a horizontal line)?

      Comment


      • #4
        You can save the data and perform any manipulations that you need.

        Code:
        use http://www.stata-press.com/data/cggm3/hip2, clear
        set scheme s1color
        sts graph, hazard by(protect) title("sts graph command") ///
        saving(gr1, replace)
        
        *SAVING DATA AND USING TWOWAY
        sts graph, hazard by(protect) outfile(mydata, replace)
        use mydata, clear
        separate hazard, by(protect) veryshortlabel
        tw (line hazard? _t , sort title("twoway command") xtitle("analysis time") ///
        leg(order(1 "protect = 0" 2 "protect = 1")) saving(gr2, replace))
        
        *COMBINE GRAPHS
        gr combine gr1.gph gr2.gph
        Res.:
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	52.2 KB
ID:	1683291

        Last edited by Andrew Musau; 25 Sep 2022, 13:53.

        Comment


        • #5
          Thank you very much, Andrew. This is exactly what I needed - the outfile option (which I had not known I could use after sts graph) gives me the values of the hazards at each time point and, from those, I can do the manipulations necessary to produce a smooth curve ratio of the hazards and plot them as a two-way graph (with the ratio of the hazards on the y-axis and time on the x-axis). Again, thank you for taking the time to provide a very helpful response.

          Comment

          Working...
          X