All of our preprocessing and analysis can be reproduced by running our scripts which can be found in our Github repository located here. The code for generating the visualizations and site html is available here.
In order to focus our data visualization tool on the most commonly used opiates in palliative care, at the outset, we removed several medications that seemed less relevant to palliative care; see our Data Sources page to recover these fields. We then transformed each non-morphine medication to morphine equivalence, using the morphine milligram equivalent factors available from the Centers for Disease Control.
For each of the three figures in the statistical summaries section, we first cube-rooted the data, so that large countries did not dominate the rest. For the histogram, we added pseudocounts for the statistics involving relative change, to avoid dividing by zero. Specifically, we added 1e-3 mg per person to the numerator and denominator of the ratios.
For the local trends, we fitted a local ridge regression for each country-drug pair. This provides a collection of slopes t for each timepoint in that series; we called this value the “local slope.” Similarly, the model provides a fitted response y[t] at each timepoint; we called this the “local average.”
For the MDS, we represented each country-drug pair by the concatenation of its (cube-rooted) original series and its (cube-rooted) differenced series. A euclidean distance was used to define the distance between the resulting representations.