Announcement

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

  • Display multiple ROC curves in one graph using roctab

    Hi everyone,

    I am performing multiple empirical ROC analysis stratified for sex. I would like to display the ROC curves for both sexes in one graph. I am using roctab for the ROC analysis and tried to combine the graphs by using addplot. However, I get the error message r(198) "GraphX is not a two-way plot type, Invalid syntax". Does anyone know if there is a solution to this problem?

    Thank you very much, I really appreciate your help!

  • #2
    it is not at all clear to me how you obtained the results you want to graph but one of the following may help: -roccurve- (user-written, use -search- to find and download); rocregplot (post-estimation command after -rocreg-):
    Code:
    help roccurve
    help rocregplot

    Comment


    • #3
      Hi Rich,

      thank you for the fast response. Just for clarification, I used the following syntax:

      roctab refvar classvar if sex==1, graph
      roctab refvar classvar if sex==2, graph

      and I wish to combine both of these graphs... is that possible using roctab?

      Many thanks!

      Comment


      • #4
        In the future, present a reproducible example as advised in FAQ Advice #12.

        I wish to combine both of these graphs... is that possible using roctab?
        I would say, no chance, but I stand to be corrected. However, the task is not difficult. You need to know your color combinations so as to determine what color to assign to the 45-degree line.

        Code:
        webuse hanley, clear
        gen tag= _n<52
        tempfile graph
        gen order=_n
        preserve
        roctab disease rating if tag, graph
        serset 0
        serset use, clear
        rename (__*) (se1 sp1)
        gen order=_n
        save `graph'
        restore
        merge 1:1 order using `graph', nogen
        preserve
        roctab disease rating if !tag, graph
        serset 0
        serset use, clear
        rename (__*) (se2 sp2)
        gen order=_n
        save `graph', replace
        restore
        merge 1:1 order using `graph', nogen
        twoway (scatter se1 sp1 , mcolor(red) lcolor(red) con(line)) ///
        (scatter se2 sp2 , mcolor(blue) lcolor(blue) con(line) ///
        ytitle("Sensitivity") xtitle("1 - Specificity") leg(off) ///
        ylab(0 (0.25) 1, grid) xlab(0 (0.25) 1, grid) scheme(s1color)) ///
        (scatteri 0 0 1 1, connect(line) lcolor(purple) mcolor(purple))
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.3 KB
ID:	1568023

        Last edited by Andrew Musau; 11 Aug 2020, 10:42.

        Comment


        • #5
          Alright, I am behind the times in my thinking in #4. The ability to set opacity affords us the flexibility of not having to guess color blends.

          Code:
          webuse hanley, clear
          gen tag= _n<52
          tempfile graph
          gen order=_n
          preserve
          roctab disease rating if tag, graph
          serset 0
          serset use, clear
          rename (__*) (se1 sp1)
          gen order=_n
          save `graph'
          restore
          merge 1:1 order using `graph', nogen
          preserve
          roctab disease rating if !tag, graph
          serset 0
          serset use, clear
          rename (__*) (se2 sp2)
          gen order=_n
          save `graph', replace
          restore
          merge 1:1 order using `graph', nogen
          twoway (scatter se1 sp1 , mcolor(red%50) lcolor(red%50) con(line)) ///
          (scatter se2 sp2 , mcolor(blue%50) lcolor(blue%50) con(line) ///
          ytitle("Sensitivity") xtitle("1 - Specificity") leg(off) ///
          ylab(0 (0.25) 1, grid) xlab(0 (0.25) 1, grid) scheme(s1color)) ///
          (scatteri 0 0 1 1, connect(line) lcolor(blue%50) mcolor(blue%50)) ///
          (scatteri 0 0 1 1, connect(line) lcolor(red%50) mcolor(red%50))
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	44.7 KB
ID:	1568029

          Comment

          Working...
          X