class: center, middle, inverse, title-slide # Using R to explore outpatient trajectories
from linked healthcare data ### Fiona Grimm, The Health Foundation
NHS-R conference 2019
@fiona_grimm
@HealthFdn
### 2019/11/04 --- # Outpatient care redesign in the NHS Long Term Plan .pull-left[ <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-4-1.png" width="550px" style="display: block; margin: auto;" /> ] -- .pull-right[ <br> "...over the next five years patients will be able to avoid up to a third of face-to-face outpatient visits..." <br> ### Strategies to achieve this * Avoid referrals by supporting GPs * Replace face-to-face with virtual appointments * Fewer and/or more flexible follow-ups What will be the effect on demand and how long will it take? ] --- class: inverse, middle, center # How can operational research techniques<br>inform policy? --- ## Proof of concept: testing alternative models of diabetes outpatient care -- .large[ ### The approach 1. Primary care data (CPRD) linked to HES for a cohort of diabetes patients 2. Characterise follow-up frequencies 3. Create transition probability matrix ] --- .pull-left[ ### From patient-level follow up patterns.. <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-5-1.png" width="450px" style="display: block; margin: auto;" /> ] --- .pull-left[ ### From patient-level follow up patterns.. <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-6-1.png" width="450px" style="display: block; margin: auto;" /> ] -- .pull-right[ ### ..to time interval between follow-ups <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-7-1.png" width="450px" style="display: block; margin: auto;" /> ] --- .pull-left[ ### From patient-level follow up patterns.. <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-8-1.png" width="450px" style="display: block; margin: auto;" /> ] .pull-right[ ### ..to time interval between follow-ups <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-9-1.png" width="450px" style="display: block; margin: auto;" /> ] --- .pull-left[ ### From patient-level follow up patterns.. <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-10-1.png" width="450px" style="display: block; margin: auto;" /> ] .pull-right[ ### ..to time interval between follow-ups <img src="FionaGrimm_NHSR_files/figure-html/unnamed-chunk-11-1.png" width="450px" style="display: block; margin: auto;" /> ] -- .pull-right[
map to follow-up categories
create transition probability matrix ] --- ## Proof of concept: the impact of policy scenarios on diabetes outpatient care .large[ ### The approach 1. Primary care data (CPRD) linked to HES for a cohort of diabetes patients 2. Characterise follow-up frequencies 3. Create transition probability matrix 4. Model the overall volume of appointments using stochastic analytical models (Markov chains) and/or simulations 5. Test the effect of different scenarios ] --- class: inverse, center, bottom background-image: url(https://creativepool.com/files/candidate/portfolio/full/1118419.jpg) background-size: 40% <br> <br> # some great #rstats tools that helped with this analysis --- # {tidylog} expects nothing and gives great feedback ```r library(tidyverse) summary <- mtcars %>% mutate(mpg_by_wt = mpg / wt) %>% filter(cyl > 4) %>% select(mpg_by_wt, cyl) ``` --- # {tidylog} expects nothing and gives great feedback ```r library(tidyverse) *library(tidylog) summary <- mtcars %>% mutate(mpg_by_wt = mpg / wt) %>% filter(cyl > 4) %>% select(mpg_by_wt, cyl) ``` ``` ## mutate: new variable 'mpg_by_wt' with 32 unique values and 0% NA ``` ``` ## filter: removed 11 rows (34%), 21 rows remaining ``` ``` ## select: dropped 10 variables (mpg, disp, hp, drat, wt, …) ``` -- <br> .pull-left[.content-box-green[ Zero effort! Saves time and helps avoid mistakes ]] .pull-right[.content-box-red[ Beware when iterating: printing console output might be slow]] --- # Tools for filtering ```r library(tidyverse) library(lubridate) library(nycflights13) ``` .pull-left[ ### By time period ```r start <- ymd('2013-01-01') end <- start + days(2) my_interval <- interval(start, end) flights %>% * filter(time_hour %within% my_interval) ``` ] -- .pull-right[ ### By another table ```r top5_carries <- flights %>% group_by(carrier) %>% count() %>% arrange(desc(n)) %>% head() flights %>% * semi_join(top5_carries, by = 'carrier') ``` ] --- # Tools for summarising .pull-left[ ### Cross-tabs with {janitor} ```r library(janitor) mtcars %>% * tabyl(gear, cyl) %>% adorn_percentages() %>% adorn_pct_formatting() %>% adorn_rounding() %>% adorn_title() ``` ``` ## cyl ## gear 4 6 8 ## 3 6.7% 13.3% 80.0% ## 4 66.7% 33.3% 0.0% ## 5 40.0% 20.0% 40.0% ``` ] -- .pull-right[ ### Baseline characteristics with {tableone} ```r library(tableone) CreateTableOne(data = iris, vars = c('Sepal.Length', 'Sepal.Width', 'Species')) ``` ``` ## ## Overall ## n 150 ## Sepal.Length (mean (SD)) 5.84 (0.83) ## Sepal.Width (mean (SD)) 3.06 (0.44) ## Species (%) ## setosa 50 (33.3) ## versicolor 50 (33.3) ## virginica 50 (33.3) ``` ] --- .pull-left[ # Acknowledgements ### Project team * .bold[Meetali Kakad], University of Oslo * Martin Utley, UCL Clinical Operations Research Unit * Sarah Deeny, Health Foundation ### Funding * The Health Foundation * Research Council of Norway ### Clinical input * Sarita Naik, Consultant Diabetologist, UCLH * Ali Chakera, Consultant Diabetologist, Brighton and Sussex University Hospital ] .pull-right[ # Get in touch .red[@fiona_grimm] .red[@tali_md] # Find our R code on GitHub .red[hfanalyticslab.github.io] <!-- --> ]