Jekyll2022-02-05T19:00:11+00:00http://dannyjnwong.github.io/feed.xmlDanny WongThis is a blog with .Rmd posts knitted into .md files and rendered with Jekyll.Pandemic Pandemonium2020-11-06T00:00:00+00:002020-11-06T00:00:00+00:00http://dannyjnwong.github.io/Pandemic-Pandemonium<p>What a whirlwind few months it has been since I last <a href="https://dannyjnwong.github.io/UK-COVID-19-Cases/">blogged in March 2020</a>. Back then, the COVID-19 cases were just starting to rise in the UK, following the trends from Italy. Little did we know how rapidly things would escalate, and within a couple of weeks of my post, the UK entered into lockdown as patients with COVID-19 started flooding through the hospital doors.</p>
<h2 id="falling-ill-during-the-first-wave">Falling ill during the first wave</h2>
<p>I was caught up with all the events, beginning to intubate a few patients in the emergency department before our hospital started instituting measures to cope with the influx. It’s easy to look back with the benefit of hindsight now, but back then things were extremely confusing and frightening. The first patient I intubated was very unwell and desaturated so quickly after induction of anaesthesia that I was forced to bag them up again, despite the fact we were told to avoid doing so as much as possible.</p>
<p>Soon after those first few days however, I quickly fell ill myself, and tested positive for COVID-19. My wife also fell ill, and it wasn’t clear whether I caught it from my patient interactions at work, or through my wife, who similarly had seen patients in her GP practice with symptoms. More likely than not though, the personal protective equipment (PPE) that I had access to as a hospital anaesthetist meant that I was far better protected than she was, and she was probably the one that caught it and passed it to me.</p>
<p>The next few weeks were really a blur, were holed up at home, in bed horizontal for most of the time. Our appetites were absent, not least because we couldn’t taste anything we ate, but also just that we didn’t have the hunger to eat anything. The tickly dry cough at the back of our throats was constant. Those things we could bear with. What was really difficult to tolerate was the near-constant fevers that went away for short bursts when the paracetamol was working, only to come back again like clockwork once the doses ran out of effect. On one of those blurry days I managed to secure a swab test at a drive-through test centre to get myself tested for the virus, this was before the days routine government testing was available to the general public, and so they had to be rationed to health workers via their occupational health service. The test was unsurprisingly positive.</p>
<p>I had 10 days of fevers and shakes, while my wife had 14. We dumped our kids (aged 5 and 3) in front of the television for most days, and took turns lying down on the sofa next to them when the fevers were more bearable. We took to staggering our paracetamol doses in order that we weren’t both febrile while having to look after the kids. Those were some bad days. We had both lost about 5kg in weight (don’t worry, we have since put them back on), and desaturated to 92% on air (wife is a GP so we have a pulse oximeter at home), but managed to avoid having to go into hospital for oxygen therapy. The kids themselves were also fortunately well for the most part, with the older one only having a mild temperature for 2 days, and the younger one completely unscathed.</p>
<p>As my symptoms eventually resolved, I couldn’t help but feel guilty that I was stuck at home while the news of what was happening in hospital filtered through via email and WhatsApp. We sorted out amongst a group of trainees and consultants a plan for redeploying staff to ICU, and I did what I could at home online via my computer, including using my knowledge of R to write some code to assign people to emergency rota slots based on their rankings of those slots. I had also started coming up with the design for the <a href="https://intubatecovid.org/">intubateCOVID</a> project with a bunch of colleagues at Guy’s and St Thomas’ just prior to going off sick, so kept working at it to try and gather some data to answer the question of what risks of transmission we as healthcare workers interacting with symptomatic patients were facing. Finally, I was checking the statistics of case numbers so frequently every day that I decided I should write an <a href="https://dannyjnwong.shinyapps.io/COVID/">R Shiny app to act as my own dashboard of what was going on</a>.</p>
<h2 id="returning-to-work">Returning to work</h2>
<p>When I was eventually well enough again to go back to work, some 3 weeks after first becoming symptomatic with a fever, I was redeployed to the emergency labour ward rota from the theatre anaesthetic on-call rota. While much of the elective surgical work was suspended during the lockdown, pregnant women were still needing to deliver babies safely. I returned to a world which I scarcely recognised. Processes had changed, and wearing PPE all the time became the norm.</p>
<p>After a few weeks in Labour Ward, I was then rotated to ICU to help with the efforts there, while some of my colleagues who had been redeployed there earlier in the pandemic could come out and decompress. I won’t dwell on my time in ICU, there were many sad stories, and some more uplifting ones, but nothing I will write could do ever justice to the events that happened there, and many others would’ve written better accounts of what it was like in ICU during the first wave.</p>
<h2 id="trying-to-move-whilst-stuck-in-treacle">Trying to move whilst stuck in treacle</h2>
<p>During the lockdown, everyone’s plans were up-ended. Including my plans to finally undergo my PhD viva exam. I had submitted my thesis in January to the examiners and the viva was planned for March, delayed till May, and then further delayed till June 26th. Lockdown restrictions were still in place when the final viva date was looming, and so we decided to conduct it all via Zoom, like many of the other activities people now do in this new normal life. Thank goodness I passed. I couldn’t bear with another postponement and it felt good that something in life was progressing at least, even if everything else in the world remained on hold. The examiners’ comments were useful and I spent the next month correcting the thesis to quickly finalise the PhD. If anybody is interested it’s now available <a href="https://discovery.ucl.ac.uk/id/eprint/10108589/">here at the UCL thesis repository</a>, or <a href="https://www.researchgate.net/publication/343968739_Postoperative_critical_care_resource_availability_patient_risk_and_other_factors_influencing_referral_and_admission">here on ResearchGate</a>. I’ve also decided to share the underlying code for the entire thesis <a href="https://github.com/dannyjnwong/PhD_Thesis">here on GitHub</a>.</p>
<p>While many kids around the country were isolated at home with their parents as schools were shut, fortunately my kids’ school remained open for key workers such as my wife and I. This was an absolute Godsend, and I couldn’t imagine juggling home schooling, going into hospital to face COVID-19 and also having to finish off the PhD corrections, day-in-day-out. I have huge respect to the teachers and other staff who kept their gates open for those of us who needed their help to continue doing our work on the frontline. In many ways, the pandemic has shown that essential workers aren’t just those of us who work in healthcare, but also include teachers, maintenance staff, delivery workers, etc.</p>
<h2 id="looking-forward">Looking forward</h2>
<p>We can probably conclude now that 2020 is a washout. It will be a big asterisk in history, and will mark itself in most people’s memories as a terrible year. As I write this, the cases are again rising exponentially across the UK and much of Western Europe, and pressures are starting again to build in the health service. Another lockdown is imminent, and I think it’s a question of when and not whether it will happen. I am worried, as many others probably are, about the future. We can only hope it gets better soon.</p>
<h2 id="addendum-6th-november-2020">Addendum: 6th November 2020</h2>
<p>When I started writing this post on the morning of 29th October 2020, I was feeling in a reflective mood as I received a call from my dad that my grandfather was unwell and took a turn for the worst in hospital. He had been admitted to hospital the night before in Malaysia, having spiked a temperature and become short of breath. He was COVID-19 swab negative, and had right lower lobe consolidation essentially had an aspiration pneumonia. He was 94 and had a long list of comorbidities and had not been well for a year or two, bouncing in and out of hospital with recurrent pneumonias. By now he was bed-bound and had such a poor swallow that he was receiving nasogastric feeding and being kept nil by mouth: it wasn’t a good quality-of-life by any measure.</p>
<p>My dad told me my grandfather had deteriorated and was now on intensive care and was receiving non-invasive ventilation. He was clearly not doing well. Despite the NIV, he was not improving and was clearly suffering. Over a Zoom videocall, with over twenty people on the line, we discussed with the ICU physician and a collective decision was made that we should withdraw treatment. He died about two or three hours later.</p>
<p>The pandemic meant that none of us abroad were able to attend the funeral in Malaysia. Again I had to participate in the funeral events remotely via Zoom over the weekend that followed. Is there anything more emblematic of 2020?</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.25
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.2 magrittr_1.5 tools_3.5.2 stringi_1.1.7
## [5] stringr_1.4.0 xfun_0.10 packrat_0.4.9-3 evaluate_0.14</code></pre></figure>Danny WongWhat a whirlwind few months it has been since I last blogged in March 2020. Back then, the COVID-19 cases were just starting to rise in the UK, following the trends from Italy. Little did we know how rapidly things would escalate, and within a couple of weeks of my post, the UK entered into lockdown as patients with COVID-19 started flooding through the hospital doors.intubateCOVID2020-07-02T00:00:00+00:002020-07-02T00:00:00+00:00http://dannyjnwong.github.io/intubateCOVID<p><img src="https://lirp-cdn.multiscreensite.com/4345920a/dms3rep/multi/opt/Screenshot+2020-04-14+at+21.34.08-480w.png" alt="intubateCOVID logo" /></p>
<p>I was a co-investigator for the <a href="https://www.intubatecovid.org/info">intubateCOVID project</a>, a user-reported registry of COVID-19 intubations and subsequent COVID-19 related outcomes in healthcare workers worldwide.</p>
<p>The incidence of COVID-19 in healthcare workers is thought to be higher than the general population. This incidence may be higher in healthcare workers who have been exposed to high viral loads while undertaking aerosol-generating procedures, such as tracheal intubation. There was previously no large-scale data on the association between airway management and the development of COVID-19. Our aims for the registry were:</p>
<ol>
<li>To ascertain the incidence of airway managers and assistants who develop COVID-19 in the weeks following an airway management episode.</li>
<li>To document associations of risk factors with COVID-19.</li>
<li>To examine the use of personal protective equipment (PPE) during airway management of COVID-19 patients.</li>
<li>To allow healthcare professionals to track their airway management activity</li>
<li>To assess the demographic of airway managers.</li>
<li>To allow local, national and international reporting of airway management activity and provide information to support policymakers.</li>
</ol>
<p>We have thus far received data from over 2000 users working at over 600 hospitals in 30 countries:</p>
<div class="u_1805219057 dmRespRow hide-for-small" id="1805219057"> <div class="dmRespColsWrapper" id="1948072698"> <div class="dmRespCol large-12 medium-12 small-12 u_1513530463" id="1513530463"> <div data-element-type="html" class="dmCustomHtml u_1626932494" id="1626932494"> <iframe src="https://dannyjnwong.github.io/assets/others/intubateCOVID_flexdashboard_map.html" width="1000px" height="700px" frameborder="0" scrolling="yes" allowfullscreen=""></iframe>
</div>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.25
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.2 magrittr_1.5 tools_3.5.2 stringi_1.1.7
## [5] stringr_1.4.0 xfun_0.10 packrat_0.4.9-3 evaluate_0.14</code></pre></figure>
</div></div></div>Danny WongUK COVID-19 Cases2020-03-07T00:00:00+00:002020-03-07T00:00:00+00:00http://dannyjnwong.github.io/UK-COVID-19-Cases<p>COVID-19 is dominating the news, and since a fair number of patients who have tested positive for the virus are being cared for in the hospital I work at, I’ve been following the news intently. As expected, the <code class="language-plaintext highlighter-rouge">R</code> community have been at the cutting edge of research in this area and there’s now a <code class="language-plaintext highlighter-rouge">coronavirus</code> package released by <a href="https://github.com/RamiKrispin">Rami Krispin</a> that provides tidy data for all the cases worldwide pulled from the <a href="https://github.com/CSSEGISandData/COVID-19">Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository</a>.</p>
<p>I thought I’d have a look at the data myself.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1">#Load the required libraries</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">coronavirus</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">lubridate</span><span class="p">)</span><span class="w">
</span><span class="c1">#Load the data</span><span class="w">
</span><span class="n">coronavirus</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">coronavirus</span><span class="w">
</span><span class="n">head</span><span class="p">(</span><span class="n">coronavirus</span><span class="p">)</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## # A tibble: 6 x 7
## Province.State Country.Region Lat Long date cases type
## <chr> <chr> <dbl> <dbl> <date> <int> <chr>
## 1 "" Japan 36 138 2020-01-22 2 confirmed
## 2 "" South Korea 36 128 2020-01-22 1 confirmed
## 3 "" Thailand 15 101 2020-01-22 2 confirmed
## 4 Anhui Mainland China 31.8 117. 2020-01-22 1 confirmed
## 5 Beijing Mainland China 40.2 116. 2020-01-22 14 confirmed
## 6 Chongqing Mainland China 30.1 108. 2020-01-22 6 confirmed</code></pre></figure>
<p>I was particularly interested in seeing the rate of increase in the cumulative number of cases confirmed within the UK. There was some debate on Twitter as to whether the confirmed case numbers looked to be following an exponential rise or not.</p>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">UM CorVid19 cases double every 2 days. So 100+ today. 200 sat 400 mon 3200 in 8 days. 200,000 in a couple of weeks. 5-10% need ICU = 10-20k: 2-4x number of UK ICU beds, which are already full. Do your bit. Wash hands. Self isolate.</p>— Hugh Montgomery (@hugh_montgomery) <a href="https://twitter.com/hugh_montgomery/status/1235754637191524352?ref_src=twsrc%5Etfw">March 6, 2020</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>Let’s see what it looks like when the UK numbers are plotted out over time.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">coronavirus</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">filter</span><span class="p">(</span><span class="n">Country.Region</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"UK"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">filter</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"confirmed"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">mutate</span><span class="p">(</span><span class="n">cumul_freq</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">cumsum</span><span class="p">(</span><span class="n">cases</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">mutate</span><span class="p">(</span><span class="n">date</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ymd</span><span class="p">(</span><span class="n">date</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">ggplot</span><span class="p">(</span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">date</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cumul_freq</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Date"</span><span class="p">,</span><span class="w">
</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Cases"</span><span class="p">,</span><span class="w">
</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Cumulative frequency of confirmed cases"</span><span class="p">,</span><span class="w">
</span><span class="n">subtitle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Data from the 2019 Novel Coronavirus Visual Dashboard\nJohns Hopkins University Center for Systems Science and Engineering (JHU CSSE)"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">scale_x_date</span><span class="p">(</span><span class="n">labels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">scales</span><span class="o">::</span><span class="n">date_format</span><span class="p">(</span><span class="s2">"%d-%m-%Y"</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">theme_classic</span><span class="p">()</span></code></pre></figure>
<p><img src="/figures/2020-03-07-UK-COVID-19-Cases/unnamed-chunk-8-1.png" alt="center" /></p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1">#ggsave("updated_plot1.png", dpi = 300, height = 5, width = 8)</span></code></pre></figure>
<p>Certainly looks like it’s rising at what looks like an exponential rate at this early stage. The data from this source is updated daily, but there is a lag and the last entry was dated 6 March 2020, the news today (7 March 2020) seems to suggest we have actually exceeded 200 cases.</p>
<p>I’m slightly worried…</p>
<h2 id="edited-09-march-2020">Edited 09 March 2020</h2>
<p>I decided to refresh the numbers a bit with more recent data and also look at the curves for some of the other European countries with similar GDPs to the UK.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">coronavirus</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">group_by</span><span class="p">(</span><span class="n">Country.Region</span><span class="p">,</span><span class="w"> </span><span class="n">Province.State</span><span class="p">,</span><span class="w"> </span><span class="n">type</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">mutate</span><span class="p">(</span><span class="n">cumul_freq</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">cumsum</span><span class="p">(</span><span class="n">cases</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">mutate</span><span class="p">(</span><span class="n">date</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">ymd</span><span class="p">(</span><span class="n">date</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">filter</span><span class="p">(</span><span class="n">Country.Region</span><span class="w"> </span><span class="o">%in%</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="s2">"Germany"</span><span class="p">,</span><span class="w"> </span><span class="s2">"UK"</span><span class="p">,</span><span class="w"> </span><span class="s2">"France"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Italy"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Spain"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Netherlands"</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">filter</span><span class="p">(</span><span class="n">date</span><span class="w"> </span><span class="o">></span><span class="w"> </span><span class="n">ymd</span><span class="p">(</span><span class="s2">"2020-02-01"</span><span class="p">))</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">rename</span><span class="p">(</span><span class="n">Country</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Country.Region</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">filter</span><span class="p">(</span><span class="n">type</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="s2">"confirmed"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">ggplot</span><span class="p">(</span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">date</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">cumul_freq</span><span class="p">,</span><span class="w"> </span><span class="n">col</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Country</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">geom_line</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Date"</span><span class="p">,</span><span class="w">
</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Cases"</span><span class="p">,</span><span class="w">
</span><span class="n">title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Cumulative frequency of confirmed cases by country"</span><span class="p">,</span><span class="w">
</span><span class="n">subtitle</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Data from the 2019 Novel Coronavirus Visual Dashboard\nJohns Hopkins University Center for Systems Science and Engineering (JHU CSSE)"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">scale_x_date</span><span class="p">(</span><span class="n">labels</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">scales</span><span class="o">::</span><span class="n">date_format</span><span class="p">(</span><span class="s2">"%d-%m-%Y"</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">theme_classic</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">theme</span><span class="p">(</span><span class="n">legend.position</span><span class="o">=</span><span class="s2">"bottom"</span><span class="p">)</span></code></pre></figure>
<p><img src="/figures/2020-03-07-UK-COVID-19-Cases/unnamed-chunk-9-1.png" alt="center" /></p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1">#ggsave("updated_plot2.png", dpi = 300, height = 5, width = 8)</span></code></pre></figure>
<p>It looks like the case numbers are all following an exponential function…</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18363)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.25 lubridate_1.7.4 forcats_0.3.0
## [4] stringr_1.3.1 dplyr_0.8.0.1 purrr_0.2.5
## [7] readr_1.1.1 tidyr_0.8.1 tibble_2.1.1
## [10] ggplot2_3.0.0 tidyverse_1.2.1 coronavirus_0.1.0.9000
##
## loaded via a namespace (and not attached):
## [1] progress_1.2.0 tidyselect_0.2.5 xfun_0.10
## [4] haven_1.1.2 lattice_0.20-38 colorspace_1.3-2
## [7] gganimate_1.0.5 utf8_1.1.4 rlang_0.3.4
## [10] pillar_1.3.1 glue_1.3.0 withr_2.1.2
## [13] tweenr_1.0.1 modelr_0.1.2 readxl_1.1.0
## [16] plyr_1.8.4 munsell_0.5.0 gtable_0.2.0
## [19] cellranger_1.1.0 rvest_0.3.2 evaluate_0.14
## [22] labeling_0.3 fansi_0.4.0 highr_0.7
## [25] broom_0.5.0 Rcpp_1.0.1 backports_1.1.2
## [28] scales_1.0.0 magick_2.2 jsonlite_1.5
## [31] farver_1.0 hms_0.4.2 packrat_0.4.9-3
## [34] digest_0.6.16 stringi_1.1.7 grid_3.5.2
## [37] cli_1.1.0 tools_3.5.2 magrittr_1.5
## [40] lazyeval_0.2.1 crayon_1.3.4 pkgconfig_2.0.2
## [43] xml2_1.2.0 prettyunits_1.0.2 assertthat_0.2.0
## [46] httr_1.3.1 rstudioapi_0.7 R6_2.2.2
## [49] nlme_3.1-137 compiler_3.5.2</code></pre></figure>Danny WongCOVID-19 is dominating the news, and since a fair number of patients who have tested positive for the virus are being cared for in the hospital I work at, I’ve been following the news intently. As expected, the R community have been at the cutting edge of research in this area and there’s now a coronavirus package released by Rami Krispin that provides tidy data for all the cases worldwide pulled from the Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus repository.Trainees and Rotas: an Assignment Problem2020-01-31T00:00:00+00:002020-01-31T00:00:00+00:00http://dannyjnwong.github.io/Trainees-and-Rotas-an-Assignment-Problem<p>I saw this tweet last night on Twitter:</p>
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">The worst solution is:<br /><br />Line A - Person 1<br /> B - 2<br /> C - 8<br /> D - 6<br /> E - 4<br /> F - 3<br /> G - 7<br /> H - 5<br /><br />This has a mean choice of 6.5 out of 8. <br /><br />What's the best combination? <a href="https://t.co/HKPrn5MizT">https://t.co/HKPrn5MizT</a> <a href="https://t.co/ZeWnCVmHhC">pic.twitter.com/ZeWnCVmHhC</a></p>— Graham McCracken (@grahamccracken) <a href="https://twitter.com/grahamccracken/status/1222933576347504642?ref_src=twsrc%5Etfw">January 30, 2020</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p><a href="https://twitter.com/grahamccracken">Graham McCracken</a> raised a problem that is frequently encountered by hospital consultants and junior doctors who are in charge of the rota: fairly assigning rota slots to trainees according to their preferences. Of course this is essentially an example of the <a href="https://en.wikipedia.org/wiki/Assignment_problem">Assignment Problem</a>.</p>
<p>So I decided to have a go at solving this problem using the <code class="language-plaintext highlighter-rouge">lpSolve</code> package in <code class="language-plaintext highlighter-rouge">R</code>.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1"># Load library</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">lpSolve</span><span class="p">)</span><span class="w">
</span><span class="c1"># Set up the Trainees' preferences</span><span class="w">
</span><span class="n">prefT</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">matrix</span><span class="p">(</span><span class="nf">c</span><span class="p">(</span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w"> </span><span class="m">1</span><span class="p">,</span><span class="w">
</span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w">
</span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w">
</span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w">
</span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w">
</span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w">
</span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">2</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">6</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w">
</span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">5</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">,</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="m">7</span><span class="p">,</span><span class="w"> </span><span class="m">3</span><span class="p">,</span><span class="w"> </span><span class="m">4</span><span class="p">),</span><span class="w">
</span><span class="n">nrow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="n">ncol</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">8</span><span class="p">,</span><span class="w"> </span><span class="n">byrow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">TRUE</span><span class="p">,</span><span class="w">
</span><span class="n">dimnames</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">list</span><span class="p">(</span><span class="nb">LETTERS</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="m">8</span><span class="p">],</span><span class="w">
</span><span class="m">1</span><span class="o">:</span><span class="m">8</span><span class="p">))</span><span class="w">
</span><span class="n">prefT</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## 1 2 3 4 5 6 7 8
## A 1 1 1 1 1 1 1 1
## B 2 6 2 2 2 2 2 2
## C 3 8 8 6 5 6 7 8
## D 4 5 7 3 7 8 6 3
## E 5 4 3 7 3 4 5 6
## F 6 3 6 5 4 3 4 5
## G 7 2 4 8 6 5 8 7
## H 8 7 5 4 8 7 3 4</code></pre></figure>
<p>After loading up the <code class="language-plaintext highlighter-rouge">lpSolve</code> package, we set up the Trainees’ (numbered 1 to 8) preferences (<code class="language-plaintext highlighter-rouge">prefT</code>) for particular rota lines (A to H) in a matrix. After we have set up the preferences, we can use the <code class="language-plaintext highlighter-rouge">lp.assign()</code> function to perform the match.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1"># Run the assignment</span><span class="w">
</span><span class="n">matching</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">lp.assign</span><span class="p">(</span><span class="n">prefT</span><span class="p">)</span><span class="w">
</span><span class="n">matching</span><span class="o">$</span><span class="n">solution</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
## [1,] 0 0 0 0 0 0 0 1
## [2,] 0 0 0 0 1 0 0 0
## [3,] 1 0 0 0 0 0 0 0
## [4,] 0 0 0 1 0 0 0 0
## [5,] 0 0 1 0 0 0 0 0
## [6,] 0 0 0 0 0 1 0 0
## [7,] 0 1 0 0 0 0 0 0
## [8,] 0 0 0 0 0 0 1 0</code></pre></figure>
<p>The <code class="language-plaintext highlighter-rouge">lp.assign()</code> returns the solution of the match as a matrix. There should be more than 1 permutation of the solution available but in this instance, the function only returns one permutation. We can then view the result.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1"># Make a dataframe of the results in a human interpretable format</span><span class="w">
</span><span class="n">Rota</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">rownames</span><span class="p">(</span><span class="n">prefT</span><span class="p">)</span><span class="w">
</span><span class="n">ix</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="nf">round</span><span class="p">(</span><span class="n">matching</span><span class="o">$</span><span class="n">solution</span><span class="w"> </span><span class="o">%*%</span><span class="w"> </span><span class="nf">seq_len</span><span class="p">(</span><span class="n">ncol</span><span class="p">(</span><span class="n">prefT</span><span class="p">)))</span><span class="w">
</span><span class="n">Trainee</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">colnames</span><span class="p">(</span><span class="n">prefT</span><span class="p">)[</span><span class="n">ifelse</span><span class="p">(</span><span class="n">ix</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">0</span><span class="p">,</span><span class="w"> </span><span class="kc">NA</span><span class="p">,</span><span class="w"> </span><span class="n">ix</span><span class="p">)]</span><span class="w">
</span><span class="n">Preference</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">t</span><span class="p">(</span><span class="n">prefT</span><span class="p">)[</span><span class="nf">as.logical</span><span class="p">(</span><span class="n">t</span><span class="p">(</span><span class="n">matching</span><span class="o">$</span><span class="n">solution</span><span class="p">))]</span><span class="w">
</span><span class="n">results</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">data.frame</span><span class="p">(</span><span class="n">Rota</span><span class="p">,</span><span class="w"> </span><span class="n">Trainee</span><span class="p">,</span><span class="w"> </span><span class="n">Preference</span><span class="p">)</span><span class="w">
</span><span class="c1"># Print the results dataframe</span><span class="w">
</span><span class="n">knitr</span><span class="o">::</span><span class="n">kable</span><span class="p">(</span><span class="n">results</span><span class="p">)</span></code></pre></figure>
<table>
<thead>
<tr>
<th style="text-align: left">Rota</th>
<th style="text-align: left">Trainee</th>
<th style="text-align: right">Preference</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">A</td>
<td style="text-align: left">8</td>
<td style="text-align: right">1</td>
</tr>
<tr>
<td style="text-align: left">B</td>
<td style="text-align: left">5</td>
<td style="text-align: right">2</td>
</tr>
<tr>
<td style="text-align: left">C</td>
<td style="text-align: left">1</td>
<td style="text-align: right">3</td>
</tr>
<tr>
<td style="text-align: left">D</td>
<td style="text-align: left">4</td>
<td style="text-align: right">3</td>
</tr>
<tr>
<td style="text-align: left">E</td>
<td style="text-align: left">3</td>
<td style="text-align: right">3</td>
</tr>
<tr>
<td style="text-align: left">F</td>
<td style="text-align: left">6</td>
<td style="text-align: right">3</td>
</tr>
<tr>
<td style="text-align: left">G</td>
<td style="text-align: left">2</td>
<td style="text-align: right">2</td>
</tr>
<tr>
<td style="text-align: left">H</td>
<td style="text-align: left">7</td>
<td style="text-align: right">3</td>
</tr>
</tbody>
</table>
<p>As you can see, 1 Trainee received their 1st choice, 2 received their 2nd choices, and the remaining 5 received their 3rd choices. This gives a mean preference ranking of 2.5 for this solution, which is the best result if you were to try every single permutation of Rota and Trainee there is available. For 8 Rota lines and 8 Trainees, the number of possible permutations would be 8! = 40320.</p>
<p>Also, in this example we have 8 trainees for 8 rota lines, but we could presumably also reformulate it for fewer trainees if there are rota gaps.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17763)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] lpSolve_5.6.15 knitr_1.25
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.2 magrittr_1.5 htmltools_0.3.6 tools_3.5.2
## [5] Rcpp_1.0.1 rmarkdown_1.16 stringi_1.1.7 highr_0.7
## [9] digest_0.6.16 stringr_1.3.1 xfun_0.10 packrat_0.4.9-3
## [13] evaluate_0.14</code></pre></figure>Danny WongI saw this tweet last night on Twitter:Data Science for Doctors Abbreviated 1-Day Course2019-07-24T00:00:00+00:002019-07-24T00:00:00+00:00http://dannyjnwong.github.io/Data-Science-for-Doctors-Abbreviated-1-Day-Course<p>It’s been a while since I’ve blogged. Life has become a little bit more hectic as I’ve returned to clinical training from my 3-year period Out-of-Programme doing Research… As some people might know, through my involvement with the <a href="http://dannyjnwong.github.io/Data-Science-Breakfast-Club/">Data Science Breakfast Club</a>, I’ve been <a href="http://datascibc.org/Data-Science-for-Docs/">teaching the basics of coding in R</a> to novice researchers, concentrating on an audience of clinicians with expertise in various specialties (primarily anaesthetists) but with little or no experience in coding or data analysis.</p>
<p>To date, we have run the course about 6 times, and usually the course has been conducted over 2 days. The course has been immensely popular, the last couple of times we ran it, it sold out within a week of advertising (20 attendees usually).</p>
<p>The course has also since been ported across to the <a href="https://www.ucl.ac.uk/school-life-medical-sciences/about-slms/office-vice-provost-health/academic-careers-office/career-schemes/clinician-coders">UCL Clinician Coders</a> scheme, and there’s also talk about making it a formal training programme for other organisations looking to increase the research capacity in the UK for healthcare data.</p>
<p>As part of the evolution of these courses, we delivered a one-day version at Guy’s Hospital to a group of 15 anaesthetists, who were really interested in picking up some data analysis basics, but weren’t able to find the time to commit to 2 days away from clinical practice. Many thanks to <a href="https://twitter.com/DrArunSahni">Arun Sahni</a> and <a href="https://twitter.com/jbedford84">James Bedford</a> for helping me to run this version of the course — without the high ratio of faculty to students, this course would never be able to run!</p>
<p>I think it is important to open up participation to a wider audience, and some people might be interested enough to get a taste of coding but can only find time in their busy schedules for one full day. So I ported the presentations into a seried of 6 lectures. Heavily borrowing from the material that my friends and I in the Data Science Breakfast Club created over the last 3 or 4 years. Special thanks to <a href="https://twitter.com/drstevok">Steve Harris</a>, <a href="https://twitter.com/DocEd">Ed Palmer</a>, <a href="https://twitter.com/aalhindawi">Ahmed Al-Hindawi</a>, <a href="https://twitter.com/FinnCatling">Finn Catling</a>, and <a href="https://twitter.com/irish_italiano">Paolo Perella</a>, who have all contributed to the development of the 2-day course material over this period.</p>
<p>In the spirit of open collaboration, I feel that this abbreviated 1-day course could easily be taught in other hospitals and therefore I want to share the content with anybody who might be interested.</p>
<p>The course agenda is below, and links to the slides are included, each lesson is 1 hour long, and there’s an hour-long break for lunch built in:</p>
<ol>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/01-lesson-01-r-for-newbies_slide.html">Basics of R</a> (09:00-10:00)</li>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/02-lesson-02-excel-hell-slide.html">Spreadsheet tips</a> (10:00-11:00)</li>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/03-lesson-03-getting-data-into-r-slides.html">Getting data into R</a> (11:00-12:00)</li>
<li><em>Lunch break! (12:00-13:00)</em></li>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/04-lesson-04-data-wrangling_slide.html">Basic data wrangling</a> (13:00-14:00)</li>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/05-lesson-05-just-enough-statistics-slides.html">Real simple stats</a> (14:00-15:00)</li>
<li><a href="https://dannyjnwong.github.io/assets/others/datascibc_slides/06-lesson-06-ggplot2.html">Data visualisation with ggplot2</a> (15:00-16:00)</li>
</ol>
<p>When and if I get the time, I’ll put this all on a Github repo with the data files and <code class="language-plaintext highlighter-rouge">.Rmd</code> files used to make the slides.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17763)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.20
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.2 magrittr_1.5 tools_3.5.2 stringi_1.1.7
## [5] stringr_1.3.1 packrat_0.4.9-3 evaluate_0.11</code></pre></figure>Danny WongIt’s been a while since I’ve blogged. Life has become a little bit more hectic as I’ve returned to clinical training from my 3-year period Out-of-Programme doing Research… As some people might know, through my involvement with the Data Science Breakfast Club, I’ve been teaching the basics of coding in R to novice researchers, concentrating on an audience of clinicians with expertise in various specialties (primarily anaesthetists) but with little or no experience in coding or data analysis.Sharing data alongside code2019-02-23T00:00:00+00:002019-02-23T00:00:00+00:00http://dannyjnwong.github.io/Sharing-data-alongside-code<p>Earlier this month the second paper from <a href="http://dannyjnwong.github.io/SNAP-2-EPICCS/">SNAP-2: EPICCS</a> was published <a href="https://bjanaesthesia.org/article/S0007-0912(19)30011-X/fulltext">online in the BJA</a>, looking at the postoperative critical are capacities in the UK, Australia and New Zealand<sup id="fnref:reference" role="doc-noteref"><a href="#fn:reference" class="footnote" rel="footnote">1</a></sup>. The paper highlights the differences in available critical care resources in the three countries as well as differences in staffing levels in general surgical wards, and the presence of high-acuity care areas outside of ICUs and HDUs where higher risk patients get sent to for postoperative recovery.</p>
<p>As I <a href="http://dannyjnwong.github.io/Sharing-code-whats-the-point/">have done</a> <a href="https://github.com/dannyjnwong/SNAP2_Cancellations">in the past</a>, I’ve again shared the code for this latest paper in a <a href="https://github.com/dannyjnwong/SNAP2_Org_Survey">GitHub repository</a> for the sake of reproducibility. However on this occasion, I have gone a couple of steps further and shared the data that was used in the analyses in the repository alongside the code, which allows the entire manuscript and analyses to be reproduced in full. Previously this has been difficult to achieve because of patient-level identifiable information contained within the datasets used in previous papers. I have also included the data within the <a href="https://github.com/dannyjnwong/HSRC"><code class="language-plaintext highlighter-rouge">HSRC</code> package</a>, which also contains some risk prediction functions I had <a href="http://dannyjnwong.github.io/Calculating-perioperative-risks-with-R/">previously written</a>.</p>
<p>This time, as the data analysed pertained to individual hospital responses to an organisational survey, the confidentiality issues are much less of a concern. I have still anonymised the dataset such that hospital names, individual critical care and high-acuity care unit names have been replaced by ID codes. If anyone should want to reuse the data for analysis, it could be done via forking the <a href="https://github.com/dannyjnwong/SNAP2_Org_Survey">manuscript repository</a> or installing the <code class="language-plaintext highlighter-rouge">HSRC</code> package (installation instructions <a href="https://github.com/dannyjnwong/HSRC">here</a>). Alternatively if anyone wishes to link the organisational data to other datasets, I could provide the de-anonymised dataset on request.</p>
<p>In the future, I hope to be able to provide even patient-level data for re-analysis, and may use packages such as <a href="https://github.com/SurgicalInformatics/encryptr"><code class="language-plaintext highlighter-rouge">encryptr</code></a> which <a href="https://twitter.com/ewenharrison?lang=en">Ewen Harrison</a> and co from the <a href="https://github.com/SurgicalInformatics">Surgical Informatics</a> group at the University of Edinburgh have created, which allows authors to encrypt specific variables/columns which are deemed to be directly identifiable. This approach however does not solve the issue of indirect re-identification by inference.</p>
<p>Other solutions for sharing data which also look promising go down another route of actually creating simulated datasets based on the covariance structure of the original dataset (an approach I mentioned very briefly in the closing paragraph of <a href="http://dannyjnwong.github.io/Sharing-code-whats-the-point/">my previous post</a>), and there seem to be packages that do this including <a href="https://www.rdatagen.net/page/simstudy/"><code class="language-plaintext highlighter-rouge">simstudy</code></a>, and <a href="https://cran.r-project.org/web/packages/synthpop/index.html"><code class="language-plaintext highlighter-rouge">synthpop</code></a>.</p>
<p>I personally feel that journals would do well to provide some guidance as to which approach towards datasharing would be best going into the future. The benefits of sharing both the data and code behind academic papers in medicine would be huge: at the very least it would 1) help to identify fraudulent research of the sort <a href="https://onlinelibrary.wiley.com/doi/10.1111/anae.14584">recently uncovered by Paul Myles et al</a>, and <a href="https://onlinelibrary.wiley.com/doi/full/10.1111/anae.13938">John Carlisle</a> in recent years; 2) encourage post-publication review and study replication; and 3) provide education for future researchers planning on utilising similar research methods.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.2 (2018-12-20)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.20
##
## loaded via a namespace (and not attached):
## [1] compiler_3.5.2 magrittr_1.5 tools_3.5.2 yaml_2.2.0
## [5] stringi_1.1.7 stringr_1.3.1 evaluate_0.11</code></pre></figure>
<div class="footnotes" role="doc-endnotes">
<ol>
<li id="fn:reference" role="doc-endnote">
<p>Wong DJN, Popham S, Wilson AM, Barneto LM, Lindsay HA, Farmer L, et al. Postoperative critical care and high-acuity care provision in the United Kingdom, Australia, and New Zealand. British Journal of Anaesthesia. 2019; Available from: http://www.sciencedirect.com/science/article/pii/S000709121930011X <a href="#fnref:reference" class="reversefootnote" role="doc-backlink">↩</a></p>
</li>
</ol>
</div>Danny WongEarlier this month the second paper from SNAP-2: EPICCS was published online in the BJA, looking at the postoperative critical are capacities in the UK, Australia and New Zealand1. The paper highlights the differences in available critical care resources in the three countries as well as differences in staffing levels in general surgical wards, and the presence of high-acuity care areas outside of ICUs and HDUs where higher risk patients get sent to for postoperative recovery. Wong DJN, Popham S, Wilson AM, Barneto LM, Lindsay HA, Farmer L, et al. Postoperative critical care and high-acuity care provision in the United Kingdom, Australia, and New Zealand. British Journal of Anaesthesia. 2019; Available from: http://www.sciencedirect.com/science/article/pii/S000709121930011X ↩Sharing code, what’s the point?2018-10-01T00:00:00+00:002018-10-01T00:00:00+00:00http://dannyjnwong.github.io/Sharing-code-whats-the-point<p>I’ve recently had the great fortune of publishing a <a href="https://bjanaesthesia.org/article/S0007-0912(18)30565-8/fulltext">paper</a> which had significant interest from the general news media, it even managed to get picked up by the <a href="https://www.bbc.co.uk/news/health-45432538">BBC</a>, <a href="https://www.theguardian.com/society/2018/sep/07/nhs-cancels-14-of-operations-at-last-minute-research-finds?CMP=Share_iOSApp_Other">The Guardian</a> and all the major newspapers in the UK!</p>
<p>As per usual, I’ve shared the source code for the analysis publicly, this time electing to serve it up on <a href="https://github.com/dannyjnwong/SNAP2_Cancellations">GitHub as a repository</a>, including both the manuscript as an <code class="language-plaintext highlighter-rouge">.Rmd</code> file and having the data wrangling and modelling code as a chunk located at the start of the <code class="language-plaintext highlighter-rouge">.Rmd</code> file, as well as the knitted <code class="language-plaintext highlighter-rouge">.html</code> version of the manuscript output to allow people to visualise what would happen if they knitted the document in <code class="language-plaintext highlighter-rouge">R</code>, IF they had the raw data at hand.</p>
<p>Which brings me to the two points of my post. Firstly, I cannot share the raw data in public, because it contains too much sensitive personal information and sensitive information about individual hospitals in the UK who contributed data. There could be unscrupulous individuals who might be able to identify patients within the data and link it to other bits of publicly available data, which is a big nono. Secondly, even as I share this code, people within my field of research don’t have the necessary skills to do anything with it.</p>
<p>Currently in the clinical research world, we are facing a big headache. On one hand we want transparency in research in order to tackle the problems of unreproducible research, and much commentary has been written about the <a href="https://www.nature.com/news/over-half-of-psychology-studies-fail-reproducibility-test-1.18248">reproducibility crisis affecting science</a>. The assertion is that we want to be able to understand how research teams arrive at their findings, and showing the working behind the statistical analyses in order to ensure that findings are real and replicable, and not merely spurious. On the other hand, we need to ensure that confidentiality of individual patients is maintained, especially in the case of large epidemiological studies where patients may not necessarily have given their consent in sharing their data.</p>
<p>Even if the data was shared alongside my code, there may not be enough people out there who could read or understand the code. In Health Services Research (my area of clinical research), there have been some studies into which software packages are most widely used. In <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3205033/">one study</a> looking at the US literature, “Stata and SAS were overwhelmingly the most commonly used software applications employed (in 46.0% and 42.6% of articles respectively).” And while the popularity of <code class="language-plaintext highlighter-rouge">R</code> is <a href="https://stackoverflow.blog/2017/10/10/impressive-growth-r/">rising</a>, very few consumers of research (as opposed to producers of research) would ever know how to code in <code class="language-plaintext highlighter-rouge">R</code>. This means that the code that is shared would barely ever be read by anybody.</p>
<p>So is there any point in me sharing my code? I guess my answer would have to be principled if not pragmatic. I hope that by sharing my code, someone who comes to repeat my studies in the future can do so without having to reinvent the wheel again from scratch, and perhaps that someone can take my work and build upon it. Also it is an opportunity for a hypothetical future person to look at and offer up suggestions to my code to help me improve, or to serve as a teaching point. There may be a future world where lots more researchers would switch to using <code class="language-plaintext highlighter-rouge">R</code> or where more consumers of research would become comfortable with reading code. Indeed we are encouraging that future by <a href="http://datascibc.org/Data-Science-for-Docs/">teaching as many people</a> as possible the basics of R and reproducible research.</p>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Successful first day of our Data Science for Doctors course September 2018 edition. 20 more people who have been introduced to the world of <a href="https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw">#rstats</a>, to go forth into the <a href="https://twitter.com/hashtag/NHS?src=hash&ref_src=twsrc%5Etfw">#NHS</a> and academic world! <a href="https://twitter.com/datascibc?ref_src=twsrc%5Etfw">@datascibc</a></p>— Danny Wong 黄永年 (@dannyjnwong) <a href="https://twitter.com/dannyjnwong/status/1045337362853744640?ref_src=twsrc%5Etfw">September 27, 2018</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Day 2 of our Data Science for Doctors course at <a href="https://twitter.com/RCoANews?ref_src=twsrc%5Etfw">@RCoANews</a>! The students are learning to visualise data! <a href="https://t.co/yN72L8aqJU">pic.twitter.com/yN72L8aqJU</a></p>— Danny Wong 黄永年 (@dannyjnwong) <a href="https://twitter.com/dannyjnwong/status/1045598915846918144?ref_src=twsrc%5Etfw">September 28, 2018</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>However, there remains a lot of work to do in the area of improving research reproducibility. We need to come up with some solutions to at least share simulated toy data examples in order for third parties to run the code in order to fully appreciate it in its entirety. Just looking at the code and working it out in our heads doesn’t allow the code to be fully dissected independently. We also need to encourage journals to recruit editorial board members who have some coding ability, and encourage keen coders to provide code reviews for submitted journal papers. Until that happens, we should encourage people to post their code online and reward authors for doing so by pushing them to cite their code as evidence of scientific output.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.5.1 (2018-07-02)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.20
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.18 rstudioapi_0.7 bindr_0.1.1 magrittr_1.5
## [5] tidyselect_0.2.4 munsell_0.5.0 colorspace_1.3-2 R6_2.2.2
## [9] rlang_0.2.2 stringr_1.3.1 plyr_1.8.4 dplyr_0.7.6
## [13] tools_3.5.1 grid_3.5.1 gtable_0.2.0 yaml_2.2.0
## [17] lazyeval_0.2.1 assertthat_0.2.0 tibble_1.4.2 anomalize_0.1.1
## [21] crayon_1.3.4 bindrcpp_0.2.2 purrr_0.2.5 ggplot2_3.0.0
## [25] evaluate_0.11 glue_1.3.0 stringi_1.1.7 compiler_3.5.1
## [29] pillar_1.3.0 scales_1.0.0 pkgconfig_2.0.2</code></pre></figure>Danny WongI’ve recently had the great fortune of publishing a paper which had significant interest from the general news media, it even managed to get picked up by the BBC, The Guardian and all the major newspapers in the UK!DiagrammeR for vector diagrams2018-06-12T00:00:00+00:002018-06-12T00:00:00+00:00http://dannyjnwong.github.io/DiagrammeR-for-vector-diagrams<p>I’ve previously shown how we can use the <code class="language-plaintext highlighter-rouge">DiagrammeR</code> package to draw <a href="http://dannyjnwong.github.io/STROBE-CONSORT-Diagrams-in-R/">STROBE/CONSORT diagrams in R</a>. But the package has far more capabilities than that! I’m using it to draw some figures in my MPhil to PhD Upgrade Report and will eventually use it in my thesis.</p>
<p>Here is an example of how useful it can be:</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">library</span><span class="p">(</span><span class="n">DiagrammeR</span><span class="p">)</span><span class="w"> </span><span class="c1">#To draw the diagram</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">DiagrammeRsvg</span><span class="p">)</span><span class="w"> </span><span class="c1">#To convert it to an SVG</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">rsvg</span><span class="p">)</span><span class="w"> </span><span class="c1">#To convert the SVG into a PNG</span><span class="w">
</span><span class="n">Pathway_diagram_enhanced</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">grViz</span><span class="p">(</span><span class="s2">"
digraph dot {
graph [layout = dot]
node [shape = rectangle,
style = filled,
color = white,
width = 3,
fontsize = 14,
fontname = 'Arial']
node [fillcolor = grey]
Home [label = 'Home']
node [fillcolor = skyblue]
Surgical [label = 'Surgical Management']
PreOp [label = 'Preoperative planning\n- Address modifiable risks\n- Further investigations']
IntraOp [label = 'Intraoperative management\n(Undergoes surgery)']
PostOp [label = 'Postoperative recovery']
node [fillcolor = pink]
ICU [label = 'Critical Care']
Ward [label = 'Surgical Ward']
node [fillcolor = orange]
Enhanced [label = 'Enhanced Care Area\n(Level 1+ unit)']
edge [color = grey, constraint = true]
Surgical -> PreOp
PreOp -> IntraOp
IntraOp -> PostOp
PostOp -> {ICU Enhanced Ward}
edge [color = grey, constraint = false]
ICU -> {Enhanced Ward}
Ward -> {Enhanced ICU}
edge [color = grey, constraint = true]
Enhanced -> {ICU Ward}
edge [xlabel = 'Discharge',
fontsize = 14,
fontname = 'Arial']
Ward -> Home
}"</span><span class="p">)</span><span class="w">
</span><span class="n">Pathway_diagram_enhanced</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">export_svg</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">charToRaw</span><span class="p">()</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">rsvg_png</span><span class="p">(</span><span class="s2">"../figures/2018-06-12-DiagrammeR-for-vector-diagrams/Pathway_enhanced.png"</span><span class="p">,</span><span class="w"> </span><span class="n">height</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">850</span><span class="p">)</span></code></pre></figure>
<p><img src="../figures//2018-06-12-DiagrammeR-for-vector-diagrams/Pathway_enhanced.png" alt="Enhanced care areas (Level 1+ units) in the surgical pathway." /></p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.4.2 (2017-09-28)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] rsvg_1.1 DiagrammeRsvg_0.1 DiagrammeR_0.9.2 knitr_1.17
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.14 pillar_1.2.1 compiler_3.4.2
## [4] RColorBrewer_1.1-2 influenceR_0.1.0 plyr_1.8.4
## [7] bindr_0.1 viridis_0.4.1 tools_3.4.2
## [10] digest_0.6.14 jsonlite_1.5 viridisLite_0.2.0
## [13] evaluate_0.10.1 anomalize_0.1.0 tibble_1.4.2
## [16] gtable_0.2.0 rgexf_0.15.3 pkgconfig_2.0.1
## [19] rlang_0.2.0 igraph_1.1.2 rstudioapi_0.7
## [22] curl_1.2 yaml_2.1.18 bindrcpp_0.2
## [25] gridExtra_2.3 downloader_0.4 dplyr_0.7.4
## [28] stringr_1.2.0 htmlwidgets_1.0 hms_0.4.2
## [31] grid_3.4.2 glue_1.1.1 R6_2.1.2
## [34] Rook_1.1-1 XML_3.98-1.4 tidyr_0.7.2
## [37] ggplot2_2.2.1 purrr_0.2.4 readr_1.1.1
## [40] magrittr_1.5 scales_0.5.0 htmltools_0.3.6
## [43] assertthat_0.2.0 colorspace_1.2-6 brew_1.0-6
## [46] V8_1.5 stringi_1.1.7 visNetwork_2.0.3
## [49] lazyeval_0.2.0 munsell_0.4.3</code></pre></figure>Danny WongI’ve previously shown how we can use the DiagrammeR package to draw STROBE/CONSORT diagrams in R. But the package has far more capabilities than that! I’m using it to draw some figures in my MPhil to PhD Upgrade Report and will eventually use it in my thesis.Keeping up-to-date with the literature2018-05-02T00:00:00+00:002018-05-02T00:00:00+00:00http://dannyjnwong.github.io/Keeping-up-to-date-with-the-literature<p>The medical literature changes so fast that it’s terribly difficult to stay current. In pursuing my PhD, I’ve discovered that the old model of literature review -> formulate a question -> design an experiment/study -> do the study -> analyse -> write-up is terribly difficult to do in series. You constantly have to do EVERYTHING in parallel.</p>
<p>Also by the time you get to the write-up stage, you realise that your literature review is horribly out-of-date! What can we do to fix this?</p>
<p>I’ve recently found out that <a href="https://www.ncbi.nlm.nih.gov/pubmed">PubMed</a> has a brilliant RSS feed function. And so you can create a search of the literature base that you want to keep current with and then keep in refreshed in the background as an RSS feed. RSS stands for Really Simple Syndication. I’ll walk you through getting one set up:</p>
<h2 id="1-create-your-search">1. Create your search</h2>
<p>Go to <a href="https://www.ncbi.nlm.nih.gov/pubmed">PubMed</a> and create a search, it can be as simple or as complicated as you wish.</p>
<p><img src="../figures/2018-05-02-Keeping-up-to-date-with-the-literature/step1.png" alt="Step 1: Create your search" /></p>
<h2 id="2-create-your-rss-feed">2. Create your RSS feed</h2>
<p>Click on the <code class="language-plaintext highlighter-rouge">Create RSS</code> link just under the search bar.</p>
<p>A little configuration box will pop up. Select your settings (I chose to keep 100 articles on my feed). Then click on the <code class="language-plaintext highlighter-rouge">Create RSS</code> button.</p>
<p><img src="../figures/2018-05-02-Keeping-up-to-date-with-the-literature/step2.png" alt="Step 2: Create your RSS feed" /></p>
<h2 id="3-cut-and-paste-into-rss-feed-reader">3. Cut and paste into RSS feed reader</h2>
<p>If you haven’t already got an RSS feed reader installed. Install one. There’re loads on the market. I have chosen to use an RSS feed reader that’s contained within my browser (Google Chrome) as an extension. I’m using <a href="https://chrome.google.com/webstore/detail/slick-rss/ealjoljnibpdkocmldliaoojpgdkcdob?hl=en">Slick RSS</a>.</p>
<p>You can now open it up on your RSS feed reader like so:</p>
<p><img src="../figures/2018-05-02-Keeping-up-to-date-with-the-literature/step3.png" alt="Step 3: RSS feed reader" /></p>
<p>Quickly browse through the articles and their abstracts and click on the ones you think are relevant, and add it to your bibliography or print it out or do what you would normally to digest this information. Or maybe more realistically: file it away and let it stack up till when you have the time, if you EVER get the time.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.4.2 (2017-09-28)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.17
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.14 assertthat_0.2.0 dplyr_0.7.4 grid_3.4.2
## [5] plyr_1.8.4 R6_2.1.2 gtable_0.2.0 magrittr_1.5
## [9] evaluate_0.10.1 scales_0.5.0 highr_0.6 ggplot2_2.2.1
## [13] pillar_1.2.1 stringi_1.1.7 rlang_0.2.0 lazyeval_0.2.0
## [17] bindrcpp_0.2 anomalize_0.1.0 tools_3.4.2 stringr_1.2.0
## [21] glue_1.1.1 munsell_0.4.3 yaml_2.1.18 compiler_3.4.2
## [25] pkgconfig_2.0.1 colorspace_1.2-6 bindr_0.1 tibble_1.4.2</code></pre></figure>Danny WongThe medical literature changes so fast that it’s terribly difficult to stay current. In pursuing my PhD, I’ve discovered that the old model of literature review -> formulate a question -> design an experiment/study -> do the study -> analyse -> write-up is terribly difficult to do in series. You constantly have to do EVERYTHING in parallel.Caesarean section rates and peripartum outcomes2018-04-13T00:00:00+00:002018-04-13T00:00:00+00:00http://dannyjnwong.github.io/Caesarean-section-rates-and-peripartum-outcomes<p>I recently saw an interesting Tweet which got me to thinking what the associations were between Caesarean section rates in different countries and maternal and baby outcomes:</p>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Instead of "experts say" can we have "evidence suggests" please? (With links to high quality evidence.) <a href="https://t.co/X2K3XQ03ib">https://t.co/X2K3XQ03ib</a></p>— Steven Shorrock (@StevenShorrock) <a href="https://twitter.com/StevenShorrock/status/984759303100870663?ref_src=twsrc%5Etfw">April 13, 2018</a></blockquote>
<script async="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<p>So I went away and looked for the OECD data which might help with looking at this question. I found 2 sources from the OECD website, one for the <a href="https://data.oecd.org/healthcare/caesarean-sections.htm">Caesarean section rates</a> and another for the <a href="http://stats.oecd.org/index.aspx?queryid=30116#">outcomes</a>. I used the 2015 data (the most recent available).</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="c1">#Load the required packages</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">tidyverse</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">readr</span><span class="p">)</span><span class="w">
</span><span class="n">library</span><span class="p">(</span><span class="n">ggrepel</span><span class="p">)</span><span class="w">
</span><span class="c1">#Load the data</span><span class="w">
</span><span class="n">Caesarean_rates</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">read_csv</span><span class="p">(</span><span class="s2">"../data/DP_LIVE_13042018135921941.csv"</span><span class="p">)</span><span class="w">
</span><span class="n">Outcomes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">read_csv</span><span class="p">(</span><span class="s2">"../data/HEALTH_STAT_13042018135958973.csv"</span><span class="p">)</span><span class="w">
</span><span class="c1">#Join the two sources</span><span class="w">
</span><span class="n">Caesarean_rates</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">Caesarean_rates</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">filter</span><span class="p">(</span><span class="n">TIME</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">2015</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">select</span><span class="p">(</span><span class="n">LOCATION</span><span class="p">,</span><span class="w"> </span><span class="n">TIME</span><span class="p">,</span><span class="w"> </span><span class="n">Caesarean_rate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Value</span><span class="p">)</span><span class="w">
</span><span class="n">Outcomes</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">Outcomes</span><span class="w"> </span><span class="o">%>%</span><span class="w"> </span><span class="n">filter</span><span class="p">(</span><span class="n">Year</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="m">2015</span><span class="p">,</span><span class="w"> </span><span class="n">VAR</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s2">"MATINETW"</span><span class="p">,</span><span class="w"> </span><span class="n">VAR</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="s2">"MATIINTW"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="n">select</span><span class="p">(</span><span class="n">COU</span><span class="p">,</span><span class="w"> </span><span class="n">VAR</span><span class="p">,</span><span class="w"> </span><span class="n">Country</span><span class="p">,</span><span class="w"> </span><span class="n">Variable</span><span class="p">,</span><span class="w"> </span><span class="n">Year</span><span class="p">,</span><span class="w"> </span><span class="n">Outcome_Value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Value"</span><span class="p">)</span><span class="w"> </span><span class="o">%>%</span><span class="w">
</span><span class="c1">#rename the variables into something more understandable</span><span class="w">
</span><span class="n">mutate</span><span class="p">(</span><span class="n">VAR</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">recode</span><span class="p">(</span><span class="n">VAR</span><span class="p">,</span><span class="w"> </span><span class="n">`MATIINFA`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Infant mortality"</span><span class="p">,</span><span class="w">
</span><span class="n">`MATIMATM`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Maternal mortality"</span><span class="p">,</span><span class="w">
</span><span class="n">`MATINEON`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Neonatal mortality"</span><span class="p">,</span><span class="w">
</span><span class="n">`MATIPERI`</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Perinatal mortality"</span><span class="p">))</span><span class="w">
</span><span class="n">Combined</span><span class="w"> </span><span class="o"><-</span><span class="w"> </span><span class="n">left_join</span><span class="p">(</span><span class="n">Outcomes</span><span class="p">,</span><span class="w"> </span><span class="n">Caesarean_rates</span><span class="p">,</span><span class="w"> </span><span class="n">by</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nf">c</span><span class="p">(</span><span class="n">COU</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"LOCATION"</span><span class="p">))</span><span class="w">
</span><span class="c1">#Plot the data</span><span class="w">
</span><span class="n">ggplot</span><span class="p">(</span><span class="n">data</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Combined</span><span class="w"> </span><span class="p">,</span><span class="w"> </span><span class="n">aes</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Caesarean_rate</span><span class="p">,</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Outcome_Value</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">geom_point</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">geom_smooth</span><span class="p">(</span><span class="n">method</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"lm"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">geom_text_repel</span><span class="p">(</span><span class="n">aes</span><span class="p">(</span><span class="n">label</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Country</span><span class="p">))</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">facet_wrap</span><span class="p">(</span><span class="o">~</span><span class="w"> </span><span class="n">VAR</span><span class="p">,</span><span class="w"> </span><span class="n">nrow</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">2</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">labs</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Caesarean sections (per 1,000 live births)"</span><span class="p">,</span><span class="w">
</span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">"Deaths (per 1,000 live births)"</span><span class="p">)</span><span class="w"> </span><span class="o">+</span><span class="w">
</span><span class="n">theme_light</span><span class="p">()</span></code></pre></figure>
<p><img src="/figures/2018-04-13-Caesarean-section-rates-and-peripartum-outcomes/unnamed-chunk-6-1.png" alt="center" /></p>
<p>So it seems that all outcomes are worse in countries with higher Caesarean section rates. Of course this is not causal. But it’s an interesting association. Also Latvia seems to have a huge maternal mortality compared to all the other OECD countries, and is not an outlier for baby deaths. I wonder what that’s all about.</p>
<figure class="highlight"><pre><code class="language-r" data-lang="r"><span class="n">sessionInfo</span><span class="p">()</span></code></pre></figure>
<figure class="highlight"><pre><code class="language-text" data-lang="text">## R version 3.4.2 (2017-09-28)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows >= 8 x64 (build 9200)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United Kingdom.1252
## [2] LC_CTYPE=English_United Kingdom.1252
## [3] LC_MONETARY=English_United Kingdom.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United Kingdom.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] knitr_1.17 ggrepel_0.7.0 bindrcpp_0.2 forcats_0.2.0
## [5] stringr_1.2.0 dplyr_0.7.4 purrr_0.2.4 tidyr_0.7.2
## [9] tibble_1.4.2 ggplot2_2.2.1 tidyverse_1.2.1 readr_1.1.1
## [13] sp_1.2-3
##
## loaded via a namespace (and not attached):
## [1] tidyselect_0.2.3 reshape2_1.4.3 haven_1.1.0 lattice_0.20-35
## [5] colorspace_1.2-6 htmltools_0.3.6 yaml_2.1.14 rlang_0.2.0
## [9] pillar_1.2.1 foreign_0.8-66 glue_1.1.1 modelr_0.1.1
## [13] readxl_1.0.0 bindr_0.1 plyr_1.8.4 munsell_0.4.3
## [17] gtable_0.2.0 cellranger_1.1.0 rvest_0.3.2 psych_1.6.9
## [21] evaluate_0.10.1 labeling_0.3 parallel_3.4.2 highr_0.6
## [25] broom_0.4.2 Rcpp_0.12.14 scales_0.5.0 backports_1.0.5
## [29] jsonlite_1.5 mnormt_1.5-5 hms_0.4.2 digest_0.6.14
## [33] stringi_1.1.7 grid_3.4.2 rprojroot_1.2 cli_1.0.0
## [37] tools_3.4.2 magrittr_1.5 lazyeval_0.2.0 crayon_1.3.4
## [41] pkgconfig_2.0.1 rsconnect_0.7 xml2_1.1.1 lubridate_1.7.1
## [45] assertthat_0.2.0 rmarkdown_1.7 httr_1.3.1 rstudioapi_0.7
## [49] R6_2.1.2 nlme_3.1-131 compiler_3.4.2</code></pre></figure>Danny WongI recently saw an interesting Tweet which got me to thinking what the associations were between Caesarean section rates in different countries and maternal and baby outcomes: