Announcement

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

  • Changing colour in scatter plot

    Hi I'm plotting deviance residuals following a survival analysis

    I would like to change the colour for those that have suffered a failure vs those who haven't, similar to this

    Click image for larger version

Name:	Screenshot 2023-10-02 at 11.16.34.png
Views:	1
Size:	173.4 KB
ID:	1728768


    Up to now I have managed to do the following

    Code:
    stcox var1 var2 var3
    predict mg, mgale
    predict xb 
    predict dev, deviance
    scatter dev xb || lfit dev _t
    However I don't know how to insert a colour option for those who have failed / those who have been censored...

  • #2
    Code:
    sysuse cancer, clear
    stcox i.drug age
    predict dev, deviance
    separate dev, by(_d)
    label var dev0 "censored"
    label var dev1 "died"
    scatter dev0 dev1 _t || lfit dev _t,  ///
      legend(order(1 2)) ytitle(deviance residual)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	83.0 KB
ID:	1728771
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks for this
      However with the code you supplied in post 2 I get this graph

      Click image for larger version

Name:	Screenshot 2023-10-02 at 13.04.55.png
Views:	1
Size:	414.8 KB
ID:	1728776

      However when I change the code to:
      Code:
       
       stcox var1 var2 var3 predict dev, deviance separate dev, by(_d)  label var dev0 "censored"  label var dev1 "died" predict xb  scatter dev0 dev1 xb _t || lfit dev _t,  ///   legend(order(1 2)) ytitle(deviance residual)
      I get the following graph:
      Click image for larger version

Name:	Screenshot 2023-10-02 at 13.04.35.png
Views:	1
Size:	407.5 KB
ID:	1728777

      Where blue = censore, red = died

      Why don't I get the scatter dots with your code? The line of best fit with your code seems steeper compared to my code I edited her...

      Also why are mine seem to be clustered all in the region of <5?
      Not sure if this would be in your remit but,
      I also seem to get a downward trend line, but shouldn't the line be at 0 indicating a good fit as per Colletts book?

      Attached Files

      Comment


      • #4
        Maarten Buis appreciate your thoughts on this …

        Comment

        Working...
        X