Announcement

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

  • Plotting prediction with confidence intervals

    Hi Statalisters,

    A bit rusty with my plotting, I cannot find how to solve a simple problem.
    I tried to recreate an example plot from a Stata help file:

    Code:
    webuse brcancer
    stset rectime, failure(censrec = 1)
    stpm2 hormon, scale(hazard) df(4) eform
    predict s, survival ci
    then I tried to plot the predicted values that were output (s, s_lci, s_uci) as follows, but I get a messy plot:

    Code:
    . twoway (line s _t, sort) (line s_lci _t, sort lpattern(dash)) (line s_uci _t, sort lpattern(dash))
    
    . twoway (line s _t) (line s_lci _t, lpattern(dash)) (line s_uci _t, lpattern(dash))


    Could you please point me to where I am missing?

    Thanks very much for your attention!
    G Kassler
    Stata BE ver 17
    MacOS Ventura

  • #2
    Is there just a single predicted value for each distinct survival time?

    Comment


    • #3
      Hi Nick,
      Thank you for responding to my query.
      Yes, single line per id and single failure in this Stata dataset.

      stset confirms:
      Code:
      299  failures in single-record/single-failure data
      Very good point as in the data I am analyzing, I have two competing risks and two lines per id.

      for my data I guess I could just derive a different prediction for each competing risk and use a tempfile for that?
      Back to the example data, the plot is looking like below with and without the sorting option (hope it attaches ok, but running the code will recreate it)

      thanks again Nick for your help!
      Attached Files
      Stata BE ver 17
      MacOS Ventura

      Comment


      • #4
        The problem is that you are plotting predicted survival against _t, and for some values of _t the prediction is for hormon==0 and for some it is for hormon==1. This is, I believe, what Nick was getting at. Your second attempt has the additional problem that the data are not sorted by time.

        The following will give you something that looks better (I just added an if qualifier to your code).

        Code:
        twoway (line s _t, sort) (line s_lci _t, sort lpattern(dash)) (line s_uci _t, sort lpattern(dash)) if hormon==1
        You might also wish to try something like this:

        Code:
        twoway (rarea s_lci s_uci _t, sort color(blue%25)) (line s _t, sort) if hormon==1
        You may wish to use the if qualifier with the predict, rather than the plot, statement. Also, consider plotting for a temporary time variable rather than the entire data set. See https://pclambert.net/software/stpm2/stpm2_timevar/ for examples of both.

        Comment


        • #5
          Thanks so much, Paul, I hadn't thought of separating the values of hormon, makes sense now! Thanks so much for the option of the area graph, looks great!
          Stata BE ver 17
          MacOS Ventura

          Comment

          Working...
          X