-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentifying_overlap_between_cohorts.qmd
840 lines (617 loc) · 29.3 KB
/
identifying_overlap_between_cohorts.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
---
editor: visual
execute:
echo: false
message: false
warning: false
cache: false
title: "Community Services Strategy: Identifying overlap between cohorts"
lang: en-GB
author: Sarah Lucas
date: last-modified
date-format: "YYYY-MM-DD"
title-block-banner: "#f9bf07"
title-block-banner-color: "#333739"
format:
html:
page-layout: full
embed-resources: true
smooth-scroll: true
theme: cosmo
fontcolor: black
toc: true
toc-location: left
toc-title: Summary
toc-depth: 3
css: styles.css
---
```{r}
options(java.parameters = "-Xmx8000m")
library(targets)
library(tidyr)
library(dplyr)
library(stringr)
library(janitor)
library(ggplot2)
library(StrategyUnitTheme)
library(rJava)
library(UpSetR)
library(tidyverse)
library(venneuler)
library(grid)
library(data.table)
library(grid)
library(gridExtra)
library(ComplexUpset)
library(ggVennDiagram)
library(scales)
library(DT)
options(scipen = 999)
source("r/Functions for cohort overlap.R")
cohort_overlap_data_2324<-tar_read(cohort_overlap_data_2324)
spells_beddays_data<-tar_read(spells_beddays_data)
```
```{r, eval=FALSE}
# Formatting data
con <- dbConnect(odbc(),
Driver = "SQL Server",
server = "PRODNHSESQL101",
Database = "NHSE_Sandbox_StrategyUnit")
raw_cohort_overlap_data <-
as_tibble(
dbGetQuery(con, '
SELECT *
FROM [NHSE_Sandbox_StrategyUnit].[dbo].[nhse_comm_strat_cohort_overlap]
')) |>
clean_names()|>
as.data.frame()
cohort_overlap_data<-raw_cohort_overlap_data|>
filter(!is.na(der_pseudo_nhs_number))|>
mutate(falls=ifelse(!is.na(flag_falls_exp)|!is.na(flag_fall_imp_frac)|!is.na(flag_fall_imp_tend), "falls", NA))|> # Single flag for falls
mutate(falls=ifelse(!is.na(falls),1,0))|>
mutate(eol=ifelse(!is.na(flag_eol),1,0))|>
mutate(elderly_emergency=ifelse(!is.na(flag_elderly_emergency),1,0))|>
mutate(frail=ifelse(!is.na(flag_frail),1,0))|>
mutate(amb_chronic=ifelse(!is.na(amb_chronic),1,0))|>
mutate(amb_acute=ifelse(!is.na(amb_acute),1,0))|>
mutate(amb_vacc_prev=ifelse(!is.na(amb_vacc_prev),1,0))|>
mutate(expanded_eol=ifelse(!is.na(death_location_type),1,0))|>
rename(icb=icb_name_short)|>
mutate(imd_decile=as.character(imd_decile))|>
mutate(imd_decile=fct_relevel(imd_decile,c("1","2","3", "4","5","6","7","8","9", "10")))|>
mutate(sex=case_when(sex==1 ~ "male",
sex==2 ~ "female"))|>
mutate(age_range=(case_when(der_age_at_cds_activity_date<60 ~"<60",
der_age_at_cds_activity_date>=60 & der_age_at_cds_activity_date<65 ~ "60-64",
der_age_at_cds_activity_date>=65 & der_age_at_cds_activity_date<70~ "65-69",
der_age_at_cds_activity_date>=70 & der_age_at_cds_activity_date<75~ "70-74",
der_age_at_cds_activity_date>=75 & der_age_at_cds_activity_date<80 ~ "75-79",
der_age_at_cds_activity_date>=80 & der_age_at_cds_activity_date<85~ "80-84",
der_age_at_cds_activity_date>=85 & der_age_at_cds_activity_date<90~ "85-89",
der_age_at_cds_activity_date>=90 ~ "90+" )))|>
select(-der_age_at_cds_activity_date)|>
mutate(ethnicity=case_when(grepl("^A", ethnic_group) ~ "White British",
grepl("^B", ethnic_group)|grepl("^C", ethnic_group) ~ "White Other",
grepl("^D", ethnic_group)|grepl("^E", ethnic_group)| grepl("^F", ethnic_group)|grepl("^G", ethnic_group) ~ "Mixed",
grepl("^H", ethnic_group)|grepl("^J", ethnic_group)| grepl("^K", ethnic_group)|grepl("^L", ethnic_group) ~ "Asian/Asian British",
grepl("^M", ethnic_group)|grepl("^N", ethnic_group)| grepl("^P", ethnic_group) ~ "Black/Black British",
grepl("^R", ethnic_group)|grepl("^S", ethnic_group) ~ "Other",
grepl("^9", ethnic_group)|grepl("^Z", ethnic_group)|is.na(ethnic_group) ~ "Unknown"))|>
mutate(ethnicity=fct_relevel(ethnicity, c("Asian/Asian British", "Black/Black British", "Mixed", "Other", "White British", "White Other", "Unknown")))|>
mutate(elderly_emergency=ifelse(elderly_emergency==1 & age_range=="70-74", 0,elderly_emergency))|>
mutate(elderly_emergency=ifelse(elderly_emergency==1 & age_range=="60-64", 0,elderly_emergency))|>
mutate(elderly_emergency=ifelse(elderly_emergency==1 & age_range=="<60", 0,elderly_emergency))|>
mutate(frail=ifelse((frail==1 & age_range=="60-64"), 0,frail))|>
mutate(frail=ifelse((frail==1 & age_range=="<60"), 0,frail))|>
select(-ethnic_group)|>
as.data.frame()
# Disconnect! #
dbDisconnect(con)
cohort_overlap_data_spells_beddays<-cohort_overlap_data|>
distinct(der_pseudo_nhs_number, der_financial_year, apcs_ident, .keep_all = TRUE)|>
mutate(cohort=paste0(falls, frail, elderly_emergency, eol, expanded_eol, amb_chronic, amb_acute, amb_vacc_prev))|>
group_by(der_financial_year, age_range, sex, ethnicity, imd_decile, falls, frail, elderly_emergency, eol, expanded_eol, amb_chronic, amb_acute, amb_vacc_prev, cohort)|>
summarise(spells=n(), beddays=sum(der_spell_lo_s))
cohort_overlap_data_patients<-cohort_overlap_data|>
group_by(der_pseudo_nhs_number, der_financial_year,
age_range, sex, ethnicity, imd_decile)|>
reframe(Falls=max(falls),
EOL=max(eol),
`Elderly Emergency`=max(elderly_emergency),
Frail=max(frail),
`ACSC Chronic`=max(amb_chronic),
`ACSC Acute`=max(amb_acute),
`ACSC Vaccine Preventable`=max(amb_vacc_prev),
`Expanded EOL`=max(expanded_eol))|>
distinct(der_pseudo_nhs_number, der_financial_year, .keep_all = TRUE)|>
mutate(cohort=paste0(Falls, Frail, `Elderly Emergency`, EOL, `Expanded EOL`, `ACSC Chronic`,`ACSC Acute`, `ACSC Vaccine Preventable`))|>
group_by(der_financial_year, age_range, sex, ethnicity, imd_decile, cohort, Falls, Frail, `Elderly Emergency`, EOL, `Expanded EOL`, `ACSC Chronic`,`ACSC Acute`, `ACSC Vaccine Preventable`)|>
summarise(patients=n())|>
mutate(`ACSC All`=ifelse(`ACSC Chronic`==1|`ACSC Acute`==1| `ACSC Vaccine Preventable`==1, 1,0))
save(cohort_overlap_data_patients, file="cohort_overlap_data_patients.RData")
save(cohort_overlap_data_spells_beddays, file="cohort_overlap_data_spells_beddays.RData")
```
## Aims
To understand the extent of the overlap between the different cohorts included within the Community Strategies analysis
## Cohorts
The patient cohorts included within this analysis are:
**Elderly emergency**: those 75 or over with an emergency admission.
**Frail**: those 65 or over with an emergency admission and a frailty score over 5. The frailty score is calculated from ICD-10 diagnoses recorded for admissions during the previous 2 years and using the risk scores in Gilbert et al (2018), Development and validation of a Hospital Frailty Risk Score focusing on older people in acute care settings using electronic hospital records: an observational study. The Lancet, 391(10132), pp.1775-1782. (Note these patients are a subset for those in the elderly emergency cohort)
**Falls**: those 65 or over with an emergency admission related to a fall.
**End of life (EOL)**: those who die within 14 days of an admission. These patients die in hospital and there are no procedures carried out and no indication that the patient experienced any trauma. (NHP definition)
**Expanded End of Life**: those with at least one hospital admission in the the year prior to their death.
**Ambulatory Care Sensitive Conditions (ACSC)**; those with admissions that could potentially be avoided with effective management and treatment such as improved primary or community health care services such as screening, vaccination, immunisation and health monitoring.
- **Chronic**: admissions for asthma, congestive heart failure, diabetes complications, chronic obstructive pulmonary disease, angina, iron-deficiency anaemia, hypertension and nutritional deficiencies
- **Acute**: admissions for dehydration and gastroenteritis, pyelonephritis, perforated/bleeding ulcer, cellulitis, pelvic inflammatory disease, dental conditions, convulsions/epilepsy, gangrene and ear, nose and throat infections
- **Vaccine Preventable**: admissions for influenza, pneumonia and other vaccine-preventable conditions
Overlap of the patients between cohorts is determined. The Venn diagrams are coloured so that the largest groups/overlap is shown in red and the smallest groups/overlap is shown in blue. The Upset plots show only the largest groups/overlaps. Values and percentages on the Venn diagrams will be slightly different to those on the Upset plots as the Venn diagrams only contain a maximum of 5 groups, whereas the Upset plots contain all groups. All data shown is for 2023/24.
## Size of cohorts
```{r}
cohort_overlap_data_2324|>
summarise(`Elderly Emergency`=sum(`Elderly Emergency`),
Frail=sum(Frail),
Falls=sum(Falls),
`Expanded EOL`=sum(`Expanded EOL`),
EOL=sum(EOL),
`ACSC Chronic`=sum(`ACSC Chronic`),
`ACSC Acute`=sum(`ACSC Acute`),
`ACSC Vaccine Preventable`=sum(`ACSC Vaccine Preventable`))|>
gather(key=Cohort, value=`Number of people`)|>
arrange(desc(`Number of people`))|>
mutate(Cohort=factor(Cohort, unique(Cohort)))|>
ggplot()+
geom_bar(aes(x=Cohort, y=`Number of people`), stat="identity")+
su_theme()+
theme(axis.title.x=element_blank(),
axis.title.y=element_text(size=16),
axis.text=element_text(size=12))+
scale_y_continuous(expand=c(0,0))+
scale_x_discrete(labels = label_wrap(width = 10))
```
## Table of numbers of patients in each cohort/overlap
Spells and beddays are allocated to cohorts based on each admission. For patients they are included in all the cohorts for which they had an admission during the 2023/24 year. Therefore if a patient had one admission included within the cohort for fall and one admission included in the elderly emergency cohort, they would be recorded as being in the fall-elderly emergency overlap cohort, but their spells and beddays for these admissions would be recorded under falls only and elderly emergency only. This is why there may be a number of patients with a particular overlap of cohorts but there are no/few spells/beddays associated with this overlap of cohorts.
Where the number of patients, spells or beddays is less than 10 the numbers have been suppressed.
```{r}
table_of_overlap<-tar_read(table_of_overlap)
spells_beddays_data<-tar_read(spells_beddays_data) |> mutate(binary_cohort=stringr::str_extract(binary_cohort, "^.{5}"))|>
group_by(age_groups, sex, binary_cohort)|>
summarise(Spells=sum(Spells), Beddays=sum(Beddays))|>
filter(binary_cohort!="00000")
table_of_overlap<-table_of_overlap|>
ungroup()|>
full_join(spells_beddays_data[,c("Spells", "Beddays", "binary_cohort", "sex", "age_groups")], by=c("binary_cohort", "sex", "age_groups"))|>
mutate(intersection=ifelse(is.na(intersection), "EOL", intersection))|>
mutate(EOL=ifelse(is.na(EOL), "1", EOL))%>%
replace(is.na(.), 0)|>
rename(Intersection=intersection)|>
select(Intersection, age_groups, sex, `Number of patients`, Spells, Beddays,`Elderly Emergency`, Frail, Falls,`Expanded EOL`, EOL )|>
mutate(`Number of patients`=ifelse(`Number of patients`<10, "<10", `Number of patients`))|>
mutate(Spells=ifelse(Spells<10, "<10", Spells))|>
mutate(Beddays=ifelse(Beddays<10, "<10", Beddays))
create_dt(table_of_overlap)
```
## Overlap between cohorts (2023/24)
There is significant overlap between the frail and elderly emergency cohorts, which is to be expected given they are the largest cohorts and the frail cohort is generally a subset of the elderly admissions cohort with some additional patients aged 65-74 years. There is also a considerable overlap between the elderly emergency and frail cohorts and the expanded EOL and falls cohorts.
::: panel-tabset
#### Venn Diagrams
::: columns
::: {.column width="50%"}
```{r}
Plot_venn_diagram(cohort_overlap_data_2324,
"Elderly Emergency",
"Frail",
"Falls",
"EOL",
"Overlap of patients between elderly and eol cohorts")
```
:::
::: {.column width="50%"}
```{r}
Plot_venn_diagram(cohort_overlap_data_2324,
"ACSC Chronic",
"ACSC Acute",
"ACSC Vaccine Preventable",
NA,
"Overlap between ambulatory care sensitive conditions cohorts")
```
:::
:::
::: columns
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324,
"Frail",
"Elderly Emergency",
"Falls",
"ACSC All",
"EOL",
"Overlap of patients between the elderly, eol and ambulatory care sensitive cohorts")
```
:::
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324,
"Frail",
"Elderly Emergency",
"Falls",
"ACSC All",
"Expanded EOL",
"Overlap of patients between the elderly, expanded eol and ambulatory care sensitive cohorts")
```
:::
:::
#### Upset plots
```{r, fig.width=10, fig.height=6, eval=FALSE}
#https://krassowski.github.io/complex-upset/articles/Examples_R.html#adjusting-the-default-themes
upset_plot_data<-cohort_overlap_data_2324
cohorts = colnames(upset_plot_data)[3:10]
upset_plot_data[cohorts] = upset_plot_data[cohorts] == 1
#t(head(upset_plot_data[cohorts], 3))
size = get_size_mode('exclusive_intersection')
ComplexUpset::upset(upset_plot_data, cohorts, name='Cohorts',
width_ratio=0.1, n_intersections=17,
set_sizes=FALSE,
keep_empty_groups=FALSE,
themes=(upset_modify_themes(
list(
'intersections_matrix'=theme(text=element_text(size=13),
axis.title.x=element_blank())
))),
base_annotations = list(
'Intersection size'=(
intersection_size(
text_mapping=aes(
label=paste0(round(!!get_size_mode('exclusive_intersection')/nrow(cohort_overlap_data_2324) * 100, 1), '%', '\n ', !!size ) ) ,
text=list(size=2.9),
bar_number_threshold = 1)+
theme(axis.title.y = element_text(size=14, vjust=-24),
axis.text.y=element_text(size=10),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank())+
scale_y_continuous(limits=c(0,330000)
))))
```
```{r, fig.width=10, fig.height=6}
plot_upset_plot_individual_acsc(cohort_overlap_data_2324, 17, 330000)
```
:::
## Focus on overlap for specific cohorts
Given the cohorts are significantly different sizes to better understand the degree of overlap in each group we have looked individually at those in each cohort to determine how many people are solely in the cohort of interest and with which other cohorts is there the greatest overlap.
::: panel-tabset
#### Emergency Elderly
Of those in the elderly emergency cohort, 27% are solely in this cohort. The elderly emergency cohort has the greatest overlap with the frail and expanded EOL cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(`Elderly Emergency`==1), 15 , 370000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps(cohort_overlap_data_2324, `Elderly Emergency`, "Number (%) of Elderly Emergency cohort that are included within other cohorts")
```
```{r, eval=FALSE}
cohort_overlap_data_2324|>
filter(`Elderly Emergency`==1)|>
summarise(`Elderly Emergency`=sum(`Elderly Emergency`),
Frail=sum(Frail),
Falls=sum(Falls),
`Expanded EOL`=sum(`Expanded EOL`),
EOL=sum(EOL),
`ACSC Chronic`=sum(`ACSC Chronic`),
`ACSC Acute`=sum(`ACSC Acute`),
`ACSC Vaccine Preventable`=sum(`ACSC Vaccine Preventable`))|>
gather(key=Cohort, value=`Number of people`)|>
mutate(cohort_of_interest=)
arrange(desc(`Number of people`))|>
mutate(Cohort=factor(Cohort, unique(Cohort)))|>
ggplot()+
geom_bar(aes(x=Cohort, y=`Number of people`), stat="identity")+
su_theme()+
theme(axis.title.x=element_blank(),
axis.title.y=element_text(size=16),
axis.text=element_text(size=12))+
scale_y_continuous(expand=c(0,0))+
scale_x_discrete(labels = label_wrap(width = 10))
```
#### Frail
Of those in the frail cohort, 17% are solely in this cohort, there is considerable overlap with the elderly emergency, expanded EOL and falls cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(Frail==1),15, 330000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps(cohort_overlap_data_2324, Frail, "Number (%) of Frail cohort that are included within other cohorts")
```
#### Falls
Only 2.9% of those in the falls cohort are solely in this cohort. Those in the falls cohort are most often also in the the elderly emergency, frail and expanded EOL cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(Falls==1),15, 90000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps(cohort_overlap_data_2324, Falls, "Number (%) of Falls cohort that are included within other cohorts")
```
#### EOL
Only 1.3% of those in the EOL cohort are solely in this cohort. Given it is a subset of the expanded EOL cohort, it would be expected that all of the EOL cohort are also in the expanded EOL cohort, so this 1.3% may be the result of potential coding issues. Besides the expanded EOL cohort the EOL also tends to overlap the most with the elderly emergency and frail cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(EOL==1),15, 18000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps(cohort_overlap_data_2324, EOL, "Number (%) of End of Life cohort that are included within other cohorts")
```
#### Expanded EOL
Of those in the expanded EOL cohort, 25% are solely in this cohort. There is considerable overlap between this group and the elderly emergency and frail cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(`Expanded EOL`==1),15, 150000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps(cohort_overlap_data_2324, `Expanded EOL`, "Number (%) of Expanded End of Life cohort that are included within other cohorts")
```
#### ACSC
Of those in the ambulatory sensitive care cohorts, 28.5% are solely in the acute cohort, 21% are solely in the chronic cohort and 9% are solely in the vaccine preventable cohort. The largest overlaps for the chronic cohort are with the elderly emergency cohort. There is also considerable overlap between the vaccine preventable cohort and the elderly emergency and frail cohorts.
```{r, fig.width=10, fig.height=6}
plot_upset_plot_individual_acsc(cohort_overlap_data_2324|>filter(`ACSC All`==1),15, 210000)
```
```{r, fig.width=8, fig.height=4}
plotting_barchart_summary_of_overlaps_individual_acsc(cohort_overlap_data_2324, `ACSC All`, "Number (%) of Ambulatory Care Sensitive Conditions cohort that are included within other cohorts")
```
:::
## Differences in cohort overlap by age
In those under 75 years the majority are within either frail, ACSC cohort or expanded EOL cohorts, with relatively little overlap between the cohorts. In those over 75 there is more overlap between cohorts, the majority are in the elderly emergency cohort with considerable overlap with the frail and expanded EOL cohorts.
:::panel-tabset
#### Venn diagrams
::: columns
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(age_range=="<60"|age_range=="60-64"|age_range=="65-69"|age_range=="70-74"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for patients under 75 yrs of age")
```
:::
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(age_range!="<60" & age_range!="60-64" & age_range!="65-69"&age_range!="70-74"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for patients 75 yrs and over")
```
:::
:::
::: columns
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(age_range=="<60"|age_range=="60-64"|age_range=="65-69"|age_range=="70-74"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for patients under 75 yrs of age")
```
:::
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(age_range!="<60" & age_range!="60-64" & age_range!="65-69"&age_range!="70-74"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for patients 75 yrs and over")
```
:::
:::
#### Upset plots
**Under 75 years of age**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(age_range=="<60"|age_range=="60-64"|age_range=="65-69"|age_range=="70-74"),15, 450000)
```
**75 years of age and over**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(age_range!="<60" & age_range!="60-64" & age_range!="65-69"&age_range!="70-74"),15, 330000)
```
:::
## Differences in cohort overlap by sex
Generally the distribution and patterns of overlap are similar between men and women. However, male patients are more likely to be in the solely frail cohort, whereas female patients are less likely to be in the solely frail cohort, but more likely to be in the frail, elderly emergency and falls cohorts.
:::panel-tabset
#### Venn diagrams
::: columns
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
#### Venn diagrams
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(sex=="male"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for male patients")
```
:::
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(sex=="female"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for female patients")
```
:::
:::
::: columns
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(sex=="male"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for male patients")
```
:::
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(sex=="female"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for female patients")
```
:::
:::
#### Upset plots
**Male**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(sex=="male"),15, 200000)
```
**Female**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(sex=="female"),15, 230000)
```
:::
## Differences in cohort overlap by deprivation
Those in the most deprived areas (IMD decile 1 & 2) are most likely to be in the acute or chronic ambulatory care sensitive cohorts, while those in the most affluent areas (IMD decile 9 & 10) are more likely to be in the elderly emergency cohort.
::: panel-tabset
#### Venn diagrams
::: columns
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
#### Venn diagrams
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(imd_decile=="1"|imd_decile=="2"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for patients living in the most deprived areas (IMD decile 1 & 2)")
```
:::
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(imd_decile=="9"|imd_decile=="10"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for patients living in the least deprived areas (IMD decile 9 & 10)")
```
:::
:::
::: columns
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(imd_decile=="1"|imd_decile=="2"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for patients living in the most deprived areas (IMD decile 1 & 2)")
```
:::
::: {.column width="50%"}
```{r, eval=FALSE}
Plot_venn_diagram(cohort_overlap_data_2324|>filter(imd_decile=="9"|imd_decile=="10"),
"Elderly Emergency",
"Frail",
"Falls",
"ACSC All",
"Overlap of cohorts for patients living in the least deprived areas (IMD decile 9 & 10)")
```
:::
:::
#### Upset plots
**Most deprived areas (IMD deciles 1 & 2)**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(imd_decile=="1"|imd_decile=="2"),15, 130000)
```
**Least deprived areas (IMD deciles 9 & 10)**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(imd_decile=="9"|imd_decile=="10"),15, 80000)
```
:::
## Differences in cohort overlap by ethnicity
Those who are White British were most commonly in the elderly emergency cohort, and in both the elderly emergency and frail cohorts. Those of all other ethnicities were most commonly in the acute ambulatory care sensitive conditions cohort. The second most common cohort in all those who were not white was the chronic ambulatory care sensitive conditions cohort.
::: panel-tabset
#### Venn diagrams
::: columns
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="White British"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for White British patients")
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="Black/Black British"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for Black/Black British patients")
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="Mixed"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for Mixed ethnicity patients")
```
:::
::: {.column width="50%"}
```{r, fig.width=8, fig.height=8}
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="Asian/Asian British"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for Asian/Asian British patients")
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="White Other"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for White Other patients")
Plot_venn_diagram_5groups(cohort_overlap_data_2324|>filter(ethnicity=="Other"),
"Frail",
"Elderly Emergency",
"Falls",
"EOL",
"ACSC All",
"Overlap of cohorts for Other ethnicity patients")
```
:::
:::
#### Upset plots
**White British**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="White British"),15, 280000)
```
**Asian/Asian British**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="Asian/Asian British"),15, 40000)
```
**Black/ Black British**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="Black/Black British"),15, 18000)
```
**White Other**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="White Other"),15, 26000)
```
**Mixed**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="Mixed"),15, 10000)
```
**Other**
```{r, fig.width=10, fig.height=6}
plot_upset_plot(cohort_overlap_data_2324|>filter(ethnicity=="Other"),15, 15000)
```
:::