I'm currently analysing some patient data, looking at patterns of medication use. Patients start on one of several drugs, then either stay on that drug, switch to a different drug, or stop all medication. Over time, some patients have built a long sequence of different medications. I've coded in the gaps (periods of no medication). Data is:
PatientID is the unique patient reference number. DrugID is the drug they are prescribed. PtDrugRef is their _n (sorted by the date they started the drug) and AnalysisGroup is either 1 or 2 based on a sociodemographic feature we are investigating.
Data is in long format.
What I'd like to do is generate a Sankey plot or Alluvial plot (I've generated the data and exported it to graph separately), but I'd also like to know if the two groups (1 and 2) have a different sequence.
It looks like sq will help with this, but I'm at a loss as to how to create the two matrices needed to compare to each other.
Is sq the right toolset to help with this? Is groups(5) reasonable, or should the data be split by AnalysisGroup here?
Is corrsqm then right to use, and how do I create the two matrices it wants (one for AnalysisGroup==1 and one for AnalysisGroup==2) ?
Thanks in advance.
| PatientID | DrugID | PtDrugRef | AnalysisGroup |
| 1 | 1 | 1 | 1 |
| 1 | 8 | 2 | 1 |
| 1 | 3 | 3 | 1 |
| 2 | 1 | 2 | 2 |
Data is in long format.
What I'd like to do is generate a Sankey plot or Alluvial plot (I've generated the data and exported it to graph separately), but I'd also like to know if the two groups (1 and 2) have a different sequence.
It looks like sq will help with this, but I'm at a loss as to how to create the two matrices needed to compare to each other.
Code:
sqset DrugID PatientID PtDrugRef sqom, sadi(oma) sqclusterdat clustermat wardslinkage SQdist, name(myname) add cluster generate cluster = groups(5) sqclusterdat, return keep(cluster myname*)
Is corrsqm then right to use, and how do I create the two matrices it wants (one for AnalysisGroup==1 and one for AnalysisGroup==2) ?
Thanks in advance.
