Announcement

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

  • Combining multiple roc curves

    Hello all,

    I have used logit for multiple roc curves and am looking for how to put them all on the same graph.

    logit death_30d scorenew if svar == 0
    lroc if svar == 1

    logit death_30d mfifive if svar == 0
    lroc if svar == 1

    logit death_30d asa_class if svar == 0
    lroc if svar == 1

    Does anyone know how to put all these graphs on the same plot?

  • #2
    Run -findit roccurve- and then install -roccurve- from ST00154. You can do your three regressions and then do out-of-sample predictions saving those results in new variables. Then -roccurve- can simultaneously calculate and plot ROC curves of the death_30d outcome against each of those predictions. It also accepts -graph twoway- options so you can customize the appearance of the graph to your taste.

    Comment


    • #3
      Originally posted by Kevin Mo View Post
      Hello all,

      I have used logit for multiple roc curves and am looking for how to put them all on the same graph.

      logit death_30d scorenew if svar == 0
      lroc if svar == 1

      logit death_30d mfifive if svar == 0
      lroc if svar == 1

      logit death_30d asa_class if svar == 0
      lroc if svar == 1

      Does anyone know how to put all these graphs on the same plot?

      I usually save lroc after each regression and then use the combine method:

      model 1
      lroc, name(graph1)

      model 1
      lroc, name(graph2)

      gr combine graph1 graph2

      Comment


      • #4
        The code in #3 will produce a graph with three panels, with one ROC curve in each. The code in #2 will produce a graph with a single panel showing all three ROC curves. Since the word "plot" is ambiguous, it is unclear which of these results the original poster had in mind.

        Comment


        • #5
          Thank you all so much for your quick responses!

          I meant that I wanted to have three lines on the same graph.

          Clyde, do you by chance have some sample code that would reflect what you said?

          Comment


          • #6
            Code:
            sysuse auto, clear
            
            logit foreign mpg if rep78 <= 3
            predict mpg_prediction if rep78 > 3
            label var mpg_prediction "Prediction by mpg"
            
            logit foreign headroom if rep78 <= 3
            predict headroom_prediction if rep78 > 3
            label var headroom_prediction "Prediction by headroom"
            
            logit foreign trunk if rep78 <= 3
            predict trunk_prediction if rep78 > 3
            label var trunk_prediction "Prediction by trunk"
            
            roccurve foreign *_prediction, title(Three Predictions of foreign)

            Comment


            • #7
              Thank you. So I have successfully gotten all three curves onto a single plot, however they connect points in a stepwise function and plot FPR x TPR:
              Click image for larger version

Name:	noname.png
Views:	1
Size:	73.2 KB
ID:	1632769



              Is there a way to connect the points on the auc graph in a straight line as well as plot sensitivity vs. 1-specificity like so? (I used the lroc function here)

              Click image for larger version

Name:	noname2.png
Views:	1
Size:	289.9 KB
ID:	1632770



              Comment


              • #8
                What they are calling TPR and FPR are, in fact, sensitivity and 1-specificity. (The terms TPR and FPR are ambiguous and should be avoided because they can refer to either these things or to the positive predictive value and 1 - negative predictive value. But that's what they use.) You can change the titling of the axesto reflect your preferred terminology with the xtitle() and ytitle() options, just as you would with any other twoway- graph.

                I don't know what to tell you about getting the straight line connection between the points. According to the help file, adding -connect(direct)- should do that. But I tried it out and it doesn't actually work. Looking at the code for roccurve.ado, I find that they say in a comment that this is something they might add in the future. So, I think the best you can do is use the -genrocvars- option and then plot the curves yourself. So something like this:

                Code:
                sysuse auto, clear
                
                logit foreign mpg if rep78 <= 3
                predict mpg_prediction if rep78 > 3
                label var mpg_prediction "Prediction by mpg"
                
                logit foreign headroom if rep78 <= 3
                predict headroom_prediction if rep78 > 3
                label var headroom_prediction "Prediction by headroom"
                
                logit foreign trunk if rep78 <= 3
                predict trunk_prediction if rep78 > 3
                label var trunk_prediction "Prediction by trunk"
                
                roccurve foreign *_prediction, nograph genrocvars
                
                label var tpr1 "mpg"
                label var tpr2 "headroom"
                label var tpr3 "trunk"
                
                
                graph twoway (connect tpr1 fpr1, sort) (connect tpr2 fpr2, sort) ///
                    (connect tpr3 fpr3, sort), xtitle("1-specificity") ytitle(sensitivity)
                Again, you can customize the appearance further to your taste using the options available for -graph twoway-. And since you are directly invoking -graph twoway- in the code, you can be sure that none of them will be ignored.

                Comment

                Working...
                X