Announcement

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

  • Help with restricting axis/analysis on Kaplan Meier survival curves

    Using Stata version 13.1 on Windows 7 am I am trying to draw a variety of Kaplan Meier curves.


    Code:
    . stset Lengthofadmission, fail(Outcome)
    
         failure event:  Outcome != 0 & Outcome < .
    obs. time interval:  (0, Lengthofadmission]
     exit on or before:  failure
    
    ------------------------------------------------------------------------------
          562  total observations
            4  event time missing (Lengthofadmission>=.)            PROBABLE ERROR
            1  observation ends on or before enter()
    ------------------------------------------------------------------------------
          557  observations remaining, representing
          486  failures in single-record/single-failure data
       380066  total analysis time at risk and under observation
                                                  at risk from t =         0
                                       earliest observed entry t =         0
                                            last observed exit t =      1227
    Code:
    sts graph, xtitle(Length of admission(days)) by(Group) risktable(, order(1 " Group 1" 2 "Group 2") rowtitle(, justification(left))) legend(order(1 "Group 1" 2 "Group 2"))
    Please see full data set graph attached
    Click image for larger version

Name:	Full data set.png
Views:	1
Size:	14.1 KB
ID:	1329811

    I would like to restrict analysis to outcome at 90 days. I recoded the data so that anyone with an admission length greater than 90 days had an admission of 90 days.

    Code:
     stset Lengthofadmission, fail(Outcome)
    
         failure event:  Outcome != 0 & Outcome < .
    obs. time interval:  (0, Lengthofadmission]
     exit on or before:  failure
    
    ------------------------------------------------------------------------------
          562  total observations
            4  event time missing (Lengthofadmission>=.)            PROBABLE ERROR
            1  observation ends on or before enter()
    ------------------------------------------------------------------------------
          557  observations remaining, representing
          486  failures in single-record/single-failure data
        42348  total analysis time at risk and under observation
                                                  at risk from t =         0
                                       earliest observed entry t =         0
                                            last observed exit t =        90
    Code:
    sts graph, xtitle(Length of admission(days)) by(Group) risktable(, order(1 " Group 1" 2 "Group 2") rowtitle(, justification(left))) legend(order(1 "Group 1" 2 "Group 2"))
    This graph looks more like I would expect but I don't know why it returns to 0 at 90 days. Click image for larger version

Name:	90 days.png
Views:	1
Size:	12.9 KB
ID:	1329809

    Following advice previously posted Following previous advice (http://www.stata.com/statalist/archi.../msg00229.html, http://www.stata.com/manuals13/g-2graphtwoway.pdf, http://www.stata.com/manuals13/ststs.pdf#ststs) and using the full dataset I have tried using -sts gen- to generate the full curve and then tried plotting the days of interest using a standard twoway graph.

    I have tried the following to generate the twoway graph
    Code:
    sts gen surv=s
    Code:
    line surv _t, xscale(range(0 90))
    Click image for larger version

Name:	twoway.png
Views:	1
Size:	13.7 KB
ID:	1329810

    Please can you advise
    Claire

  • #2
    I recoded the data so that anyone with an admission length greater than 90 days had an admission of 90 days. ...
    This graph looks more like I would expect but I don't know why it returns to 0 at 90 days.
    What you did is specify that everybody achieved the failure endpoint at 90 days: so Stata acknowledged that by showing you a non-failure rate of 0 at 90 days. What I think you meant to do was censor everybody at 90 days.

    Comment


    • #3
      Hi,

      I think you are missing out on using -tmax()- in the sts graph. Would be helpful if you could provide some working example, but here is something that should give you what you are after. I've also created this from -stcox-:

      This should get you about 90% of the way - if you want to predict following -stcox- you will need to tweak the graph so it starts from 100% (or 1)

      clear
      sysuse cancer
      drop if drug==3
      qui stset st,failure(di)
      sum age
      gen meanage=age-r(mean)
      stcox drug, basesurv(baseline_drug) strata(drug) nolog
      gen s1=baseline_drug if drug==1
      label var s1 "Placebo"
      gen s2=baseline_drug if drug==2
      label var s2 "Drug X"

      sort _t
      #delim ;
      twoway (line s1 _t if _t<25, connect(stairstep))
      (line s2 _t if _t<25, connect(stairstep)),
      legend(rows(1)) title("Survival at average age")
      xtitle("analysis time") name(Restricted, replace) ;

      #delim ;
      twoway (line s1 _t, connect(stairstep))
      (line s2 _t , connect(stairstep)),
      legend(rows(1)) title("Survival at average age")
      xtitle("analysis time") name(All, replace) ;

      #delim cr

      sts graph, by(drug) tmax(25) name(cox_restricted, replace)
      sts graph, by(drug) name(cox_all, replace)

      gr combine Restricted All cox_restricted cox_all

      Is this what you were hoping for?
      Last edited by Tim Evans; 08 Mar 2016, 15:49.

      Comment


      • #4
        The predicted curves now start from 1 with this code.


        clear
        sysuse cancer
        drop if drug==3
        qui stset st,failure(di)
        sum age
        gen meanage=age-r(mean)
        stcox drug, basesurv(baseline_drug) strata(drug) nolog
        gen s1=baseline_drug if drug==1
        label var s1 "Placebo"
        gen s2=baseline_drug if drug==2
        label var s2 "Drug X"

        local new = _N + 1
        set obs `new'
        replace _t = 0 if _t==.
        foreach v of varlist s1 s2{
        replace `v' = 1 if _t==1
        }


        sort _t
        #delim ;
        twoway (line s1 _t if _t<25, connect(stairstep))
        (line s2 _t if _t<25, connect(stairstep)),
        legend(rows(1)) title("Survival at average age")
        xtitle("analysis time") name(Restricted, replace) ;

        #delim ;
        twoway (line s1 _t, connect(stairstep))
        (line s2 _t , connect(stairstep)),
        legend(rows(1)) title("Survival at average age")
        xtitle("analysis time") name(All, replace) ;

        #delim cr

        sts graph, by(drug) tmax(25) name(cox_restricted, replace)
        sts graph, by(drug) name(cox_all, replace)

        gr combine Restricted All cox_restricted cox_all



        Attached Files

        Comment


        • #5
          Thank you for your replies Clyde and Tim.

          I think Clyde is right and that I want to censor my data at 90 days. Can you censor continuous variables (Length of admission)? Having had a look this morning I have found that _d after stset tells you which variables have been censored. In my case it looks like Outcome has been censored. What should my stset code be in order to censor the data for 90 days? If this is not the right way to censor my data what should I be doing?

          Claire

          Comment


          • #6
            Claire, if you are not trying to achieve the result in my example, why do you want observations to stop at 90 days? What are you trying to say?

            Perhaps if the chart where you go to 0 is what you are after, perhaps you could replace the value for those of >90 days to 91 days and then use tmax(90)?


            i.e.:

            sysuse cancer, clear
            drop if drug==3
            g studytime1 = studytime
            replace studytime1 =16 if studytime>15
            stset studytime1,failure(di)
            sts graph, by(drug) tmax(15)


            You could actually run this without the -tmax()- option and it shouldnt make a difference in this example.
            Last edited by Tim Evans; 09 Mar 2016, 08:08.

            Comment


            • #7
              Tim, I appreciate your help but I don't understand what you have asked me to do.

              I think I have done it
              Code:
              stset Lengthofadmission, fail(Outcome) exit(Lengthofadmission==90)
              Click image for larger version

Name:	Censored graph.png
Views:	1
Size:	10.8 KB
ID:	1330064

              Thanks to you both for your help
              Claire

              Comment


              • #8
                Claire,

                I think what you have now is probably the preferable way of doing it!

                Tim

                Comment

                Working...
                X