Announcement

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

  • Sankey diagram (dealing with non-switchers)

    Dear stata list,

    I'm trying to use sankey diagram to show the flow of treatment sequence in a large population of patients. The issue I'm struggling with is that not all patients would switch from treatment A to tratment B, some of them would remain on treatment A. In the example data I provided below, individual 1 remained on same treatment i.e. source is A and destination is A . I created a binary variable to indicate whether an individual switch to another line of treatment (nswitch=0) or remain on treatment (nswitch=1) i.e. for individual 1, nswitch=1. I added this variable (nswitch) as an option to include only those who switched. Clinically, it doesn't make sense to show that a patient switch to the same treatment but it is impoortant to show how many individuals remain on a particular treatment as well as when they switched to different treatment. Below is an example of data in which "value" represents the total number of individuals on a particular drug for each line of therapy.


    // create example data
    clear
    input studyno drugid layer value str20 source str20 destination nswitch
    1 1 1 1458 "A" "A" 1
    2 4 1 5443 "B" "C" 0
    2 52 2 1033 "C" "D" 0
    2 1449 3 420 "D" "D" 1
    3 4 1 5443 "B" "E" 0
    3 53 2 759 "E" "E" 1
    4 1449 1 3625 "D" "F" 0
    4 1449 2 860 "F" "F" 1
    5 4 1 5443 "B" "D" 0
    5 1449 2 1672 "D" "F" 0
    5 41 3 500 "F" "F" 1
    5 41 3 500 "F" "F" 1
    6 4 1 5443 "B" "B" 1
    6 4 1 5443 "B" "F" 0
    6 41 2 860 "F" "F" 1
    6 41 2 860 "F" "F" 1
    end
    label variable layer "Line of therapy"
    label variable value "number of individuals per each layer"
    label variable source "starting on treatment"
    label variable destination "switching to treatment"
    label variable nswitch "switchers; 0=switched to another treatment 1=remained on treatment"


    ssc install sankey, replace

    net install sankey, from("https://raw.githubusercontent.com/asjadnaqvi/stata-sankey/main/installation/") replace

    ssc install palettes, replace
    ssc install colrspace, replace

    ssc install schemepack, replace
    set scheme white_tableau


    graph set window fontface "Arial Narrow"

    sankey value if nswitch==0, ///
    from(source) to(destination) by(layer) sortby(value) colorby(layer) ///
    smooth(6) gap(40) recenter(top) novalues boxwid(5) ///
    xsize(1.0) ysize(1) labs(1.6) laba(0) labpos(3) lc(white) lw(0.1) offset(5) ///
    subtitle("", size(3))

    Any help/advice oh how to deal with those who remained on treatment would be much appreciated. Thank you

  • #2
    Asjad Naqvi is the author here. He's a member here, but more active, so far as I can see, on Twitter, GitHub, or Discord. If he doesn't reply, or you don't get a good answer from anybody else, I would contact him in places where he hangs out.

    Comment


    • #3
      Thanks Nick for the Tag. I did contact Dr Asjad, yesterday, via email and send a message on twitter as well. Hoping for an answer!

      Comment


      • #4
        Dear Oras Alabas, I just recieved all your messages! But please report problems on GitHub in the Issues section of the package as stated in the helpfile and elsewhere. This also allows others to see how to deal with similar problems and I can also document if enhancements are required.

        Regarding your data, you don't need to condition it. Without conditioning it shows exactly who is switching and who is not. Here is a simpler code:

        Code:
        sankey value, from(source) to(destination) by(layer) smooth(6) gap(5) boxwid(5) laba(0)
        which gives:
        Click image for larger version

Name:	test1.png
Views:	1
Size:	40.4 KB
ID:	1713941


        Given your data, this figure is fairly straightforward to interpret. If there is some issue with this, then please let me know.

        Comment


        • #5
          Dear Asjad, Thank you very much for your prompt response. As I mentiend above, clinically it doesn't make sense to show people who switched to the same treatment. For example, for treatment B there shouldn't be a switch from B to B I wanted to show that a proprtion of people remained on the same treatment and I couldn't modify the code accordingly. Similary for treatment A and treatment E (second layer), it shouldn't show the switch from A to A as it is the same treatment. Any thoughts in this regard please? Thank you
          Last edited by Oras Alabas; 17 May 2023, 07:18.

          Comment


          • #6
            Basically you are requesting a customization to the program, where non-switchers are not shown as links to a new layer but stay in place. For example, A would just show up as a box in the first layer, and B would have a larger height, with leakages to other treatments.

            The easiest thing to implement currently is to just say that if from==destination then don't draw the right hand side of the linkages. But this can yield wierd-looking graphs.
            A proper implementation implies recalculating the heights and displacements, while keeping the boxes in place. This is not so trivial to implement.

            Let me think about this!

            Comment


            • #7
              As you have explained the situation "where non-switchers are not shown as links to a new layer but stay in place" this is exactly what I'm trying to achieve. I thought to only include observations of those who switched to a different treatment to avoid switching within the same treatment (i.e. from A to A or B to B) but that doeasn't solve the problem because I also wanted to show the total number of people who remained on a particulare treatment as this is clinically important. Sure, looking forward to a solution! Thank you for your help!

              Comment


              • #8
                Thank you Asjad Naqvi for the updated Sankey found in GitHub v1.6. GitHub - asjadnaqvi/stata-sankey: A Stata package for Sankey diagrams dealing with those who remained on the same tratment. The updated sankey is exactly what I wanted. Thank you very much!

                Comment

                Working...
                X