Announcement

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

  • How can I overlay Weibull survival curves and Kaplan-Meier curves?

    Dear Statalist users,

    I am trying to plot a Weibull survival curve together with a Kaplan Meier curve but I have not been able to find a solution.

    The plot I would like to produce would be something similar to what stcoxkm does.

    I have been trying to use the addplot option, without success.

    Code:
    sts graph, by(groupvar)
    streg groupvar var1 var2 var3 var4 var5, distribution(weibull)  
    stcurve, survival at1(groupvar=1) at2(groupvar=2) ylabels(0 0.25 0.5 0.75 1)
    I would like to put both graphs together.

    Any suggestions? Thank you in advance.





  • #2
    You can always recreate these graphs yourself. However, at a minimum, you need to provide a data example and show each of the graphs separately. Then someone can show a way to overlay them.

    Comment


    • #3
      Example data:
      Code:
      sysuse cancer , clear
      streset , exit(time 20)
      replace drug = 2 if drug == 3
      Below is one solution saving the Weibul survival from stcurve to a mata matrix which is plottet with the sts graph, addplot() option:
      Code:
      ********************************************************************************
      * Weibull streg and stcurve
      ********************************************************************************
       
      preserve
      
          streg  i.drug , dist(weibull) 
          serset clear 
          stcurve, survival at1(drug=1) at2(drug=2) name(weibul, replace) 
      
          ****************************************************************************
          * save the stcurve data to a mata matrix to be added to the sts gr plot
          ****************************************************************************
      
          serset set 0
          serset use , clear 
      
          set obs `= _N + 1 '
      
          foreach v of varlist _surv* {
      
              replace `v' = 1 if mi(`v')
          } 
      
          rename __* t
          replace t = 0 if mi(t)
          sort t
      
          putmata s = ( _surv* t ) , replace
      
          ****************************************************************************
      
      restore
      
      ********************************************************************************
      * sts graph , addplot()
      ********************************************************************************
      
      sts graph , by(drug) name(km, replace) ///
          addplot( line matamatrix(s) ) leg(off) ///
          risktable ///
          title("Survival") ylab(,angle(h)) 
      
      * redefine line colors
          
      local col1 "blue"
      local col2 "red"
      
      gr_edit .plotregion1.plot1.style.editstyle line(color(`col1'))  
      gr_edit .plotregion1.plot3.style.editstyle line(color(`col1'*.25)) 
      gr_edit .plotregion1.plot2.style.editstyle line(color(`col2'))  
      gr_edit .plotregion1.plot4.style.editstyle line(color(`col2'*.25))     
      
      *******************************************************************************

      Comment


      • #4
        Thank you very much!! This was very helpful

        Comment

        Working...
        X