-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-results.Rmd
executable file
·913 lines (670 loc) · 37.8 KB
/
03-results.Rmd
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
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
---
editor_options:
chunk_output_type: console
output:
pdf_document: default
word_document: default
---
# Results {-}
```{r setup, include=FALSE, cache=F}
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message = FALSE, results = TRUE, cache = F, fig.align = "center", out.width = "100%", cache.lazy = FALSE)
# https://stackoverflow.com/questions/46080853/why-does-rendering-a-pdf-from-rmarkdown-require-closing-rstudio-between-renders/46083308#46083308
library(kableExtra)
if (knitr::is_latex_output()) {
usepackage_latex("booktabs")
usepackage_latex("longtable")
usepackage_latex("array")
usepackage_latex("multirow")
usepackage_latex("wrapfig")
usepackage_latex("float")
usepackage_latex("colortbl")
usepackage_latex("pdflscape")
usepackage_latex("tabu")
usepackage_latex("threeparttable")
usepackage_latex("threeparttablex")
usepackage_latex("ulem", "normalem")
usepackage_latex("makecell")
}
# format = 'html'
# synth_data = FALSE
library(tidyverse)
library(stringr)
library(tableone)
library(nlme)
library(boot)
# Real data ---------
if(synth_data == FALSE) {
#df <- read_csv('Data/final_wi_dataset-2020-03-03.csv') %>%
df <- read_csv('Data/final_wi_dataset-with_rp_id_2020-05-26.csv') %>%
mutate(
intervention = ifelse(monthsSinceIntervention > 0, "Post", "Pre"),
rot_paras = ifelse(rp == 1, "Rotational Paramedics", "Control"),
rp_table = ifelse(rp == 1, "Intervention", "Control"),
age = ordered(age, levels = c("[0,5]", "(5,10]", "(10,15]", "(15,20]", "(20,25]", "(25,30]", "(30,35]", "(35,40]", "(40,45]", "(45,50]", "(50,55]", "(55,60]", "(60,65]","(65,70]","(70,75]", "(75,80]", "(80,85]", "(85,90]", "(90,95]", "(95,100]", "(100,105]", "(105,110]")),
risk = ordered(risk, levels=c("Low", "Low-Medium","Medium", "High")),
los = ordered(los, levels=c("<1 year", "1 to 5 years", ">5 years")),
ltc = ordered(ltc, levels=c("[0,4]", "(4,8]", "(8,12]","(12,16]")),
`non-conveyed` = ifelse(conveyed == 1, 0, 1),
`safe non-conveyance` = case_when(
conveyed == 1 ~ 0,
recontact == 1 ~ 0,
TRUE ~ 1
),
newTimeElapsed = ifelse(timeElapsedMonths < 13, timeElapsedMonths + 1, timeElapsedMonths - 1)
) %>% filter(newTimeElapsed < 25) %>%
dplyr::select("safe non-conveyance", "non-conveyed", "season", "ooh", "call_cat","rural_urban", "imd_decile", "ltc", "age", "sex", "risk" , "wi", "los", "intervention", "rot_paras", "rp", "rp_table", "newTimeElapsed", "conveyed", "recontact", "recontact_conveyed", conveyed, recontact, recontact_RRV, recontact_Amb, rp_id)
}
# Synthetic data ----------
if(synth_data == TRUE) {
df <- readRDS('SynData/synthetic-dataset-with-wi.rds') %>%
mutate(
call_cat = as.character(call_cat),
age = ordered(age, levels = c("[0,5]", "(5,10]", "(10,15]", "(15,20]", "(20,25]", "(25,30]", "(30,35]", "(35,40]", "(40,45]", "(45,50]", "(50,55]", "(55,60]", "(60,65]","(65,70]","(70,75]", "(75,80]", "(80,85]", "(85,90]", "(90,95]", "(95,100]", "(100,105]", "(105,110]")),
los = ordered(los, levels=c("<1 year", "1 to 5 years", ">5 years")),
rp_table = ifelse(rp == 1, "Intervention", "Control")
)
}
# Economic analysis -----------------
# Calculate the per incident cost for an SP
# 10 weeks
ten_weeks_salary = (31121/52) * 10
# 10 weeks salary for 10 SPs
ten_for_ten = ten_weeks_salary * 10
# SPs attended 2059 cases (including missing wi) in the post-rotation phase
salary_per_inc = round(ten_for_ten / 2059, 2)
# £29.07 per incident.
# Calculate the total cost for each incident based on the unit costs
df$cost <- mapply(function(conveyed, recontact, recontact_conveyed, rp, intervention)
{
call_cost <- 7.33
S_and_T <- 209.38
S_T_and_C <- 257.34
A_E <- 135
cost = 0
# Add placement cost if rp
if(rp == "Rotational Paramedics" & intervention == "Post") {
cost = cost + salary_per_inc
}
# Add 999 call
cost = cost + call_cost
# If no ambulances and RRV conveyed, then need to ST and C
if(conveyed == 1) {
cost = cost + S_T_and_C + A_E
} else {
cost = cost + S_and_T
}
# If not conveyed but there is a recontact
# Then need to add these costs
if(conveyed == 0 & recontact == 1) {
# Add 999 call
cost = cost + call_cost
# If no ambulances and RRV conveyed, then need to ST and C
if(recontact_conveyed == 1) {
cost = cost + S_T_and_C + A_E
} else {
cost = cost + S_and_T
}
}
return(cost)
},
conveyed = df$conveyed, recontact = df$recontact, recontact_conveyed = df$recontact_conveyed, rp = df$rot_paras, intervention = df$intervention)
# Table 1 ---------------------
table1_df <- df %>%
mutate(
age = fct_collapse(age,
"[0,15]" = c("[0,5]", "(5,10]", "(10,15]"),
"(15, 65]" = c("(15,20]", "(20,25]", "(25,30]", "(30,35]", "(35,40]", "(40,45]", "(45,50]", "(50,55]", "(55,60]", "(60,65]"),
"(65,80]" = c("(65,70]", "(70,75]", "(75,80]"),
"(80,110]" = c("(80,85]", "(85,90]", "(90,95]", "(95,100]", "(100,105]", "(105,110]"),
NULL = "Unknown"),
wi = fct_lump(wi, n = 10)
)
matchedTbl_pre_post_control_rp <- CreateTableOne(
vars = c("safe non-conveyance", "non-conveyed", "season", "ooh", "call_cat","rural_urban", "imd_decile", "ltc", "age", "sex", "risk" , "wi", "los"),
strata = c("intervention", "rp_table"),
data = table1_df,
test = F,
factorVars = c("safe non-conveyance", "non-conveyed", "season", "call_cat", "ooh", "risk", "los", "age", "sex", "imd_decile", "rural_urban", "ltc", "wi")
)
# table1_df %>%
# #unite(col = "group", c(intervention, rp_table)) %>%
# filter(intervention == "Pre") %>%
# select(`safe non-conveyance`, `non-conveyed`, season, ooh, call_cat, rural_urban, imd_decile, ltc, age, sex, risk, wi, los, rp_table) %>%
# tbl_summary(by = rp_table) %>%
# add_p()
#
matrix_tbl <- print(matchedTbl_pre_post_control_rp)
col1 <- rownames(matrix_tbl)
# Formatting of headings
col1[2] <- "Appropriately not conveyed n (%)"
col1[3] <- "Not conveyed n (%)"
col1[4] <- "Yearly quarter n (%)"
col1[9] <- "Out-of-hours n (%)"
col1[10] <- "Call category"
col1[16] <- "Urban location n (%)"
col1[17] <- "IMD decile n (%)"
col1[28] <- "Prevalence of Long-term conditions n (%)"
col1[33] <- "Patient age in years n (%)"
col1[38] <- "Patient sex n (%)"
col1[42] <- "NEWS category n (%)"
col1[47] <- "Clinical working impression n (%)"
col1[59] <- "Years registered as a paramedic"
# This will come in handy for Table 1 headers
#list_of_cols <- c(4, 10, 17, 28, 33, 38, 42, 47, 59)
df_summary <- bind_cols(data.frame(Measure = col1, stringsAsFactors = F), as_tibble(matrix_tbl)) %>%
dplyr::select(Measure, `Pre:Control`, `Pre:Intervention`, `Post:Control`, `Post:Intervention`)
colnames(df_summary) <- c("Measure", "Control", "Intervention", "Control", "Intervention")
```
```{r sensitivity-analysis, results = FALSE}
# Need to undertake the sensitivity analysis first to report the results later.
source('Code/prep_no_wi.R')
```
As part of the HEE rotational paramedic pilot, 10 SPs undertook a 10 week placement in a primary care setting in the Leeds area. Five commenced their placement in June 2018, with a further three starting in August 2018 and the final two starting their placement in October 2018.
Between 1st June 2017 and 31st December, 2019 there were 8849 incidents attended by one of the intervention group SPs. Once data was adjusted to remove any cases during the 10 week GP placement, and outside of the 12 months prior to the start of the rotation and 12 months after the end of the rotation, 7349 cases remained (Figure \@ref(fig:figure1)) . A further 6 had no sex recorded, 15 had no age recorded, 8 had no post code and 4 cases were excluded due to either a missing index of multiple deprivation decile (3 cases), rural urban classification (3 cases) and/or prevalence of missing long-term condition data (4 cases). Finally, no working impression was included in 1785 cases, resulting in a final dataset of 5537/7349 (75.3%) cases for inclusion in the final analysis. Due to the high number of missing working impressions, a sensitivity analysis was performed excluding the working impression as a variable (Supplementary 1).
```{r figure1, fig.cap="STROBE flow chart of patient selection" }
# https://rpubs.com/phiggins/461686
data <- tibble(x= 1:100, y= 1:100)
p <- data %>%
ggplot(aes(x, y)) +
scale_x_continuous(minor_breaks = seq(10, 100, 10), limits = c(15, 95)) +
scale_y_continuous(minor_breaks = seq(10, 100, 10), limits = c(20,100)) +
theme_linedraw()
p <- p +
# Total cases
geom_rect(xmin = 36, xmax=64, ymin=94, ymax=100, color='black',
fill='white', size=0.25) +
annotate('text', x= 50, y=97,label= 'Incidents attended by intervention SPs (n=8849)', size=2.5) +
# Arrows
geom_segment(x=50, xend=50, y=94, yend=83.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
geom_segment(
x=50, xend=69.5, y=88.5, yend=88.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
# Exclude those not in 12 month pre/post
geom_rect(xmin = 70, xmax=95, ymin=84, ymax=93, color='black',
fill='white', size=0.25) +
annotate('text', x= 71, y=89,label= 'Excluded (n=1500)\n Incident occured more than 12 months before/after\n or during GP placement', size=2.5, hjust=0) +
# Cases that are potentially eligible
geom_rect(xmin = 36, xmax=64, ymin=77, ymax=83, color='black',
fill='white', size=0.25) +
annotate('text', x= 50, y=80,label= 'Incidents eligible for inclusion (n=7349)', size=2.5) +
# Arrows
geom_segment(x=50, xend=50, y=77, yend=56.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
geom_segment(
x=50, xend=69.5, y=66.5, yend=66.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
# Exclude those who could have been eligible but had to be removed
geom_rect(xmin = 70, xmax=95, ymin=58, ymax=75, color='black',
fill='white', size=0.25) +
annotate('text', x= 71, y=67,label= 'Excluded (n=1812)\n No sex recorded (n=6)\n No age recorded (n=15)\n No postcode (n=8)\n Missing IMD, rural/urban, long-term condition (n=4)\n No working impression (n=1785)', size=2.5, hjust=0) +
# Final set for analysis
geom_rect(xmin = 36, xmax=64, ymin=50, ymax=56, color='black',
fill='white', size=0.25) +
annotate('text', x= 50, y=53,label= 'Incidents available for matching (n=5537)', size=2.5) +
# Arrows
geom_segment(x=50, xend=50, y=50, yend=40.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
geom_segment(
x=50, xend=69.5, y=44.5, yend=44.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
# Exclude unmatched cases
geom_rect(xmin = 70, xmax=95, ymin=41, ymax=47, color='black',
fill='white', size=0.25) +
annotate('text', x=71, y=44,label= 'Excluded (n=339)\n Incidents not matched', size=2.5, hjust=0) +
# Matched cases
geom_rect(xmin = 36, xmax=64, ymin=36, ymax=40, color='black',
fill='white', size=0.25, size=0.25) +
annotate('text', x=50, y=38,label= 'Matched incidents (n=5198)', size=2.5) +
# Pre-placement
geom_rect(xmin = 16, xmax=44, ymin=20, ymax=24, color='black',
fill='white', size=0.25, size=0.25) +
annotate('text', x=30, y=22,label= 'Pre-placement incidents (n=3297)', size=2.5) +
# Post-placement
geom_rect(xmin = 56, xmax=84, ymin=20, ymax=24, color='black',
fill='white', size=0.25, size=0.25) +
annotate('text', x=70, y=22,label= 'Post-placement incidents (n=1901)', size=2.5) +
# Final Arrows
geom_segment(x=50, xend=50, y=36, yend=30,
size=0.15, linejoin = "mitre", lineend = "butt") +
geom_segment(
x=50, xend=30, y=30, yend=30,
size=0.15, linejoin = "mitre", lineend = "butt") +
geom_segment(
x=50, xend=70, y=30, yend=30,
size=0.15, linejoin = "mitre", lineend = "butt") +
geom_segment(
x=30, xend=30, y=30, yend=24.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed")) +
geom_segment(
x=70, xend=70, y=30, yend=24.5,
size=0.15, linejoin = "mitre", lineend = "butt",
arrow = arrow(length = unit(2, "mm"), type= "closed"))
p + theme_void()
```
## Matched dataset for analysis {-}
The matching algorithm utilised 5198/5537 (93.9%) cases (Table \@ref(tab:table1)). Overall, the control group was closely matched to the rotational paramedic (intervention group) incidents (defined as less than 10% in standardised mean difference). Only the NEWS risk category and prevalence of long-term conditions were outside this limit.
In addition to the substantial reduction in number of cases attended in the post-placement phase, there were also other differences in pre- and post-placement cases, which could have contributed to the change in rate of non-conveyance, validating the decision to include a matched control (Table \@ref(tab:table1)).
## Pre- and Post-rotation exploratory data analysis {-}
Operational activity was lower post-placement since intervention group SPs had to undertake a range of additional activities in the post-placement phase, including staffing a dedicated SP dispatch desk in EOC and working in GP practices as part of the HEE pilot (Table 2). Post-placement, there were also differences in triage call category and physiological acuity based on the NEWS risk category that the SPs were tasked to attend (Supplementary 2).
```{r table1, cache = F}
library(kableExtra)
# This will come in handy for Table 1 headers
#list_of_cols <- c(4, 10, 17, 28, 32, 55, 59, 64, 103)
list_of_cols <- c(4, 10, 17, 28, 33, 38, 42, 47, 59)
df_summary <- df_summary[-list_of_cols, ]
rownames(df_summary) = NULL
# Add asterix for footnote for pain: other
df_summary$Measure[49] = paste0(df_summary$Measure[49], '*')
kableone(df_summary, caption="Comparison of matched control and rotational paramedic groups, stratified by pre and post-placement phases", booktabs = TRUE, longtable = TRUE, format = format) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), latex_options = c("repeat_header", "striped", "hold_position")) %>%
add_header_above(c(" ", "Pre-placement" = 2, "Post-placement" = 2)) %>%
pack_rows(col1[4], 4, 7) %>%
pack_rows(col1[10], 9, 13) %>%
pack_rows(col1[17], 15, 24) %>%
pack_rows(col1[28], 25, 28) %>%
pack_rows(col1[33], 29, 32) %>%
pack_rows(col1[38], 33, 35) %>%
pack_rows(col1[42], 36, 39) %>%
pack_rows(col1[47], 40, 50) %>%
pack_rows(col1[59], 51, 53) %>%
footnote(
general = "lrti - lower respiratory tract infection",
symbol = "This working impression denotes pain that has not been classed as abdominal pain, cardiac chest pain or non-traumatic back pain.", threeparttable = T)
```
```{r activity-stats}
# Number of incidents per month
op_act <- df %>%
filter(rp == 1) %>%
count(intervention, newTimeElapsed)
op_act_pre = fivenum(op_act$n[op_act$intervention=="Pre"])
op_act_post = fivenum(op_act$n[op_act$intervention=="Post"])
op_act_pre_text = paste0("median ", op_act_pre[3], " incidents per month (IQR ", op_act_pre[2], "--", op_act_pre[4], ")")
op_act_post_text = paste0("median ", op_act_post[3], " incidents per month (IQR ", op_act_post[2], "--", op_act_post[4], ")")
# Cat 1 and 2 calls
cat_df <- df %>%
filter(rp == 1) %>%
count(cat1or2 = call_cat %in% c("cat1", "cat2"), newTimeElapsed)
cat_act_pre = cat_df %>% filter(newTimeElapsed < 13) %>% pull(n) %>% fivenum
cat_act_post = cat_df %>% filter(newTimeElapsed >= 13) %>% pull(n) %>% fivenum
cat_act_pre_text = paste0("median ", cat_act_pre[3], " incidents per month (IQR ", cat_act_pre[2], "--", cat_act_pre[4], ")")
cat_act_post_text = paste0("median ", cat_act_post[3], " incidents per month (IQR ", cat_act_post[2], "--", cat_act_post[4], ")")
# NEWS risk
new_df <- df %>%
filter(rp == 1) %>%
count(lownews = risk == "Low", newTimeElapsed)
new_act_pre = new_df %>% filter(newTimeElapsed < 13) %>% pull(n) %>% fivenum
new_act_post = new_df %>% filter(newTimeElapsed >= 13) %>% pull(n) %>% fivenum
new_act_pre_text = paste0("median ", new_act_pre[3], " incidents per month (IQR ", new_act_pre[2], "--", new_act_pre[4], ")")
new_act_post_text = paste0("median ", new_act_post[3], " incidents per month (IQR ", new_act_post[2], "--", new_act_post[4], ")")
```
```{r activity}
if(synth_data == TRUE) {
activity_df <- readRDS('SynData/median_activity_by_month.rds')
} else {
activity_df <- readRDS('Data/median_activity_by_month.rds')
}
# kableone(activity_df, caption="SP daliy activity (exluding leave and days off) stratified by pre- and post-placement time periods", booktabs = TRUE, longtable = TRUE, format = format) %>%
# kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), latex_options = c("repeat_header", "striped", "hold_position")) %>%
# footnote(
# general = "EOC - emergency operations centre, OPS - operational shift responding to 999 calls, STUDY - study leave and other training activities",threeparttable=T
# )
ops_pre <- glue::glue("(median {activity_df[6,3]} (IQR {activity_df[6,4]}--{activity_df[6,5]}) hours per month)")
ops_post <- glue::glue("(median {activity_df[3,3]} (IQR {activity_df[3,4]}--{activity_df[3,5]}) hours per month)")
```
Operational activity was higher pre-placement `r ops_pre` than post-placement `r ops_post`, since intervention group SPs had to undertake a range of additional activities in the post-placement phase, including staffing a dedicated SP dispatch desk in EOC and working in GP practices as part of the HEE pilot. In addition, there were also differences in triage call category (a marker of perceived acuity following telephone triage of the call), and physiological acuity based on the NEWS risk category that the SPs were tasked to attend, (Table \@ref(tab:table1) and Supplementary 1).
## Time series {-}
```{r time-series-prep }
ts_df <- df %>%
group_by(rot_paras, newTimeElapsed) %>%
summarise(
n = n(),
propnonConveyed = sum(conveyed == 0)/n,
propnonRecontact = sum(`safe non-conveyance` == 1)/n,
intervention = first(intervention),
rp = first(rp)
) %>%
ungroup() %>%
mutate(
intervention = ifelse(intervention == "Pre", 0, 1),
timeSinceIntervention = ifelse(intervention == 0, 0, newTimeElapsed - 12)
) %>%
rename(
level = intervention,
trend = timeSinceIntervention,
time = newTimeElapsed
) %>%
mutate(
rptime = ifelse(rp == 1, time, 0),
rplevel = ifelse(rp == 1, level, 0),
rptrend = ifelse(rp == 1, trend, 0)
)
ts_df_econ <- df %>%
mutate(
intervention = ifelse(intervention == "Pre", 0, 1),
timeSinceIntervention = ifelse(intervention == 0, 0, newTimeElapsed - 12)
) %>%
rename(
level = intervention,
trend = timeSinceIntervention,
time = newTimeElapsed,
snc = `safe non-conveyance`
) %>%
mutate(
rptime = ifelse(rp == 1, time, 0),
rplevel = ifelse(rp == 1, level, 0),
rptrend = ifelse(rp == 1, trend, 0)
)
```
```{r fig5, fig.cap="Plot of data for OLS regression with control group"}
step4its_gg <- ts_df %>%
mutate(
outcome = round(propnonRecontact, 2) )
step4its_gg_econ <- ts_df_econ %>%
mutate(
outcome = cost
)
cols2 <- c("control"="#0000ff", "intervention"="#ff0000")
fig5_fn <- function(data, flag) {
a <- ggplot(data = data, aes(x = time, y = outcome)) +
# Prepare graph
theme_bw() +
scale_x_continuous(name="Months elapsed", breaks = seq(1,24,1), labels = seq(1,24,1), expand = c(0,0)) +
geom_vline(xintercept = 12.5, color="black", size = 2) +
annotate("text", label = "Pre-placement", x = 4, y = 0.9, size = 4, colour = "black") +
annotate("text", label = "Post-placement", x = 16, y = 0.9, size = 4, colour = "black") +
# Prep control/intervention data
geom_point(data=data %>% filter(rp == 0), aes(color="control")) +
geom_line(data=data %>% filter(rp == 0), aes(color="control"), linetype="solid") +
geom_point(data=data %>% filter(rp == 1), aes(color="intervention")) +
geom_line(data=data %>% filter(rp == 1), aes(color="intervention"), linetype="solid") +
scale_color_manual(name="Group", values = cols2) +
theme(legend.position = "bottom")
if(flag == 'cits') {
a + scale_y_continuous(name = "Proportion of patients appropriately non-conveyed", expand = c(0,0), breaks=seq(0,1,0.1), limits = c(0,1), labels=scales::percent)
} else {
a + scale_y_continuous(name = "Mean cost (£)", expand = c(0,0), breaks=seq(0,400,50), limits = c(0,400))
}
}
fig5 <- fig5_fn(step4its_gg, 'cits')
#fig5_econ <- fig5_fn(step4its_gg_econ, '')
```
```{r cits-workflow }
library(tidymodels)
lm_mod <- linear_reg() %>%
set_engine('lm')
lm_fit <-
lm_mod %>%
fit(propnonRecontact ~ time + rp + rptime + level + trend + rplevel + rptrend, data = ts_df)
mean_pred <- predict(lm_fit, new_data = ts_df)
plot_data <-
ts_df %>%
bind_cols(mean_pred)
# Intercept is the initial value of the control group
# time is existing trend in control group
# rp is the difference in levels between control and intervention
# rptime is the trend of hte intervention with reference to control
# level is post-pilot control change in level of non-conveyance
# trend is post-pilot control change in trend on non-conveyance
# rplevel shows post-pilot intervention group change in level
# rptrend is the post-pilot intervention group change in trend
dw_test <- tidy(lmtest::dwtest(lm(propnonRecontact ~ time + rp + rptime + level + trend + rplevel + rptrend, data = ts_df),iterations=12,alternative="two.sided"))
```
```{r cits-table-prep }
f <- function(x, places = 1, prop = T) {
y <- sprintf(glue::glue("%.{places}f"), x * 100,1)
if(!prop) {
y <- sprintf(glue::glue("%.{places}f"), x)
}
return(y)
}
cits_tidy <- tidy(lm_fit, conf.int = T) %>%
mutate_at(c("estimate", "conf.low", "conf.high"), f) %>%
mutate(
ci = glue::glue("{conf.low}--{conf.high}"),
p.value = ifelse(p.value < 0.001, "<0.001", sprintf("%.3f", p.value))
)
ols_table_fn <- function(model, flag = '') {
tidy(model, conf.int = T) %>%
mutate_at(c("estimate", "conf.low", "conf.high"), f) %>%
mutate(
` ` = case_when(
term == "(Intercept)" ~ "Initial control group level",
term == "time" ~ "Pre-placement control group trend",
term == "rp" ~ "Difference in level between control and intervention groups",
term == "rptime" ~ "Intervention group trend relative to control group",
term == "level" ~ "Post-placement change in control group level",
term == "trend" ~ "Post-placement change in control group trend",
term == "rplevel" ~ "Post-placement intervention group change in level relative to control group",
term == "rptrend" ~ "Post-placement intervention group change in trend relative to control group",
TRUE ~ 'Safe non-conveyance'
),
`Coefficient (%)` = estimate,
`95% CI` = glue::glue("{conf.low} to {conf.high}"),
`P value` = ifelse(p.value < 0.001, "<0.001", sprintf("%.3f", p.value))
) %>%
dplyr::select(` `, `Coefficient (%)`, `95% CI`, `P value`)
}
ols_table <- ols_table_fn(lm_fit)
```
Figure \@ref(fig:fig6) illustrates the change in raw and fitted CITS model data between the pre- and post-placement phase. There was no indication of auto-regression, where future values are based on past values (Durbin-Watson statistic `r round(dw_test$statistic,2)`, p=`r round(dw_test$p.value,2)`). Post-placement, the intervention group significantly increased their appropriate non-conveyance rate by `r cits_tidy$estimate[7]`% (95%CI `r cits_tidy$ci[7]`%, p=`r cits_tidy$p.value[7]`) relative to the control group (Table \@ref(tab:cits-table)). However, there was a non-statistically significant decrease in the trend of appropriate non-conveyance relative to the control group of `r cits_tidy$estimate[8]`% (95%CI `r cits_tidy$ci[8]`%, p=`r cits_tidy$p.value[8]`). The sensitivity analysis (excluding working impression as a matching variable) demonstrated a smaller increase appropriate non-conveyance in the intervention group relative to the control group of `r cits_tidy_no_wi$estimate[7]`% (95%CI `r cits_tidy_no_wi$ci[7]`%, p`r cits_tidy_no_wi$p.value[7]`), and smaller decrease in the trend of appropriate non-conveyance (`r cits_tidy_no_wi$estimate[8]`%, 95%CI `r cits_tidy_no_wi$ci[8]`%, p=`r cits_tidy_no_wi$p.value[8]`).
```{r fig6, fig.cap="Effect of 10-week primary care placement on appropriate non-conveyance. a) Monthly appropriate non-conveyance rates b) Fitted CITS model. Dashed lines represent the counterfactuals (what would have happened in the absence of the intervention).", fig.height = 10}
# There was an outlier in the intervention group at month 18, but a sensitivity analysis conducted with the data point removed, suggested it had little effect on the post-rotation level and trend of appropriate non-conveyance (`r cits_tidy_no_18$estimate[7]`%, 95%CI `r cits_tidy_no_18$ci[7]`%, p=`r cits_tidy_no_18$p.value[7]` and `r cits_tidy_no_18$estimate[8]`%, 95%CI `r cits_tidy_no_18$ci[8]`%, p=`r cits_tidy_no_18$p.value[8]` respectively).
plot_fig6_fn <- function(data, model, flag) {
# Alternating control and rp
new_data_points <- data.frame(
time = c(1, 1, 12, 12, 13, 13, 24, 24),
rp = rep(c(0, 1), 4),
rptime = c(0, 1, 0, 12, 0, 13, 0, 24),
level = c(0, 0, 0, 0, 1, 1, 1, 1),
trend = c(0, 0, 0, 0, 1, 1, 12, 12),
rplevel = c(0, 0, 0, 0, 0, 1, 0, 1),
rptrend = c(0, 0, 0, 0, 0, 1, 0, 12),
stringsAsFactors = F
)
# Control then rp
cf_data_points <- data.frame(
time = c(13, 24, 13, 24),
rp = c(0, 0, 1, 1),
rptime = c(0, 0, 13, 24),
level = c(0, 0, 1, 1),
trend = c(0, 0, 12, 12),
rplevel = c(0, 0, 0, 0),
rptrend = c(0,0, 0, 0),
stringsAsFactors = F
)
# 12 months rp non-conveyance
rp_12_months_data_points <- data.frame(
time = c(12, 24),
rp = c(1, 1),
rptime = c(12, 24),
level = c(1, 1),
trend = c(12, 12),
rplevel = c(1, 1),
rptrend = c(1, 12),
stringsAsFactors = F
)
rp_12_months_pred <- predict(model, new_data = rp_12_months_data_points)
rp_12_months_pred_ci <- predict(model, new_data = rp_12_months_data_points, type = "conf_int")
mean_pred <- predict(model, new_data = new_data_points)
cf_mean_pred <- predict(model, new_data = cf_data_points)
plot_data <- new_data_points %>%
bind_cols(mean_pred)
cf_plot_data <- cf_data_points %>%
bind_cols(cf_mean_pred)
cols2 <- c("control"="#0000ff", "intervention"="#ff0000")
a <- 'propnonRecontact'
ypos <- 0.9
if(flag == 'econ') {
a <- 'cost'
ypos <- 250
}
b <- ggplot(data = data, aes(x = time, y = !!sym(a))) +
# Prepare graph
theme_bw() +
scale_x_continuous(name="Months elapsed", breaks = seq(1,24,1), labels = seq(1,24,1), expand = c(0,0)) +
geom_vline(xintercept = 12.5, color="black", size=2) +
annotate("text", label = "Pre-placement", x = 4, y = ypos, size = 4, colour = "black") +
annotate("text", label = "Post-placement", x = 16, y = ypos, size = 4, colour = "black") +
# Plot actual data points
geom_point(data=data %>% filter(rp == 0), aes(color="control"), alpha = 0.2) +
geom_point(data=data %>% filter(rp == 1), aes(color="intervention"), alpha = 0.2) +
# Plot rp lines
geom_line(data=plot_data %>% filter(rp == 1, level == 0), aes(y = .pred, color="intervention"), linetype="solid") +
geom_line(data=plot_data %>% filter(rp == 1, level == 1), aes(y = .pred, color="intervention"), linetype="solid") +
# Plot counterfactual rp lines
geom_line(data=cf_plot_data %>% filter(rp == 1), aes(y = .pred, color="intervention"), linetype="dashed") +
geom_line(data=cf_plot_data %>% filter(rp == 1), aes(y = .pred, color="intervention"), linetype="dashed") +
# Plot control lines
geom_line(data=plot_data %>% filter(rp == 0, level == 0), aes(y = .pred, color="control"), linetype="solid") +
geom_line(data=plot_data %>% filter(rp == 0, level == 1), aes(y = .pred, color="control"), linetype="solid") +
# Plot counterfactual control lines
geom_line(data=cf_plot_data %>% filter(rp == 0), aes(y = .pred, color="control"), linetype="dashed") +
geom_line(data=cf_plot_data %>% filter(rp == 0), aes(y = .pred, color="control"), linetype="dashed") +
scale_color_manual(name="Group", values = cols2) +
theme(legend.position = "bottom")
if(flag == 'cits') {
b + scale_y_continuous(name = "Proportion of patients appropriately non-conveyed", expand = c(0,0), breaks=seq(0,1,0.1), limits = c(0,1), labels=scales::percent)
} else {
b + scale_y_continuous(name = "Cost (£)", expand = c(0,0), breaks=seq(0,400,50), limits = c(0,400))
}
}
fig6 <- plot_fig6_fn(ts_df, lm_fit, 'cits')
#fig6_econ <- plot_fig6_fn(ts_df_econ, lm_fit_econ, 'econ')
ggpubr::ggarrange(fig5, fig6, nrow = 2, ncol = 1, labels = "auto", common.legend = T)
#ggpubr::ggarrange(fig5_econ, fig6_econ, nrow = 2, ncol = 1, labels = "auto", common.legend = T)
```
```{r cits-table, cache = F}
knitr::kable(ols_table, caption="Result of segmented regression analysis for appropriate non-conveyance", booktabs = TRUE, longtable = T, format = format) %>%
kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive"), latex_options = c("repeat_header", "striped", "hold_position")) %>%
column_spec(1, width = "25em")
```
## Economic analysis {-}
```{r econ_1}
#https://www.tidymodels.org/learn/statistics/bootstrap/
fit_lm_bootstrap <- function(split) {
lm(cost ~ time + rp + rptime + level + trend + rplevel + rptrend + snc, data = split)
}
econ_df <- ts_df_econ %>%
mutate(
strata = case_when(
level == 0 & rot_paras == 'Control' ~ 'P1',
level == 0 & rot_paras == 'Rotational Paramedics' ~ 'P2',
level == 1 & rot_paras == 'Control' ~ 'P3',
level == 1 & rot_paras == 'Rotational Paramedics' ~ 'P4',
)
)
set.seed(123)
econ_boots <- bootstraps(econ_df, 1000, strata = strata)
econ_models <- econ_boots %>%
mutate(
model = map(splits, fit_lm_bootstrap),
coef_info = map(model, tidy)
)
econ_coefs <- econ_models %>% unnest(coef_info)
percentile_intervals <- int_pctl(econ_models, coef_info)
#percentile_intervals
calc_cost <- function(level, rp, rplevel, rptime, rptrend, snc, time, trend, pi, which_coef) {
est <- pi %>% select(!!which_coef) %>% pull()
est_costs <- est[1] + (est[2] * level) + (est[3] * rp) + (est[4] * rplevel) + (est[5] * rptime) + (est[6] * rptrend) + (est[7] * snc) + (est[8] * time) + (est[9] * trend)
}
est <- percentile_intervals %>% select(".estimate") %>% pull()
est_upper <- percentile_intervals %>% select(".upper") %>% pull()
est_lower <- percentile_intervals %>% select(".lower") %>% pull()
final_econ_df <- ts_df_econ %>%
rowwise() %>%
mutate(
est_costs = calc_cost(level, rp, rplevel, rptime, rptrend, snc, time, trend, percentile_intervals, ".estimate"),
est_upper_costs = calc_cost(level, rp, rplevel, rptime, rptrend, snc, time, trend, percentile_intervals, ".upper"),
est_lower_costs = calc_cost(level, rp, rplevel, rptime, rptrend, snc, time, trend, percentile_intervals, ".lower")
)
#saveRDS(final_econ_df, 'Data/final_econ_df.rds')
# if(synth_data == FALSE) {
# final_econ_df <- readRDS('Data/final_econ_df.rds')
# } else {
# final_econ_df <- readRDS('SynData/final_econ_df.rds')
# }
#
diff_in_safe_conveyance <- (tidy(lm_fit) %>% filter(term == 'rplevel') %>% pull(estimate))
pre_post_econ_df <- final_econ_df %>%
group_by(level, rot_paras) %>%
summarise(
mean_cost = mean(est_costs),
mean_upper_cost = mean(est_upper_costs),
mean_lower_cost = mean(est_lower_costs),
n = n(),
non_convey = sum(snc == 1),
cost_per_safe_conveyance = sum(est_costs)/sum(snc == 1),
cost_upper_per_safe_conveyance = sum(est_upper_costs)/sum(snc == 1),
cost_lower_per_safe_conveyance = sum(est_lower_costs)/sum(snc == 1),
)
# saveRDS(pre_post_econ_df, 'Data/pre_post_econ_df.rds')
# if(synth_data == FALSE) {
# pre_post_econ_df <- readRDS('Data/pre_post_econ_df.rds')
# } else {
# pre_post_econ_df <- readRDS('SynData/pre_post_econ_df.rds')
# }
#CEA = Cost Pre - Cost Post / rplevel
diff_in_safe_conveyance <- (tidy(lm_fit) %>% filter(term == 'rplevel') %>% pull(estimate))
cea_df <- bind_rows(
pre_values <- pre_post_econ_df %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% select(ends_with('safe_conveyance')),
post_values = pre_post_econ_df %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% select(ends_with('safe_conveyance'))
) %>%
pivot_longer(cols = cost_per_safe_conveyance:cost_lower_per_safe_conveyance) %>%
group_by(name) %>%
summarise(
mean_diff = first(value) - last(value),
cea = (first(value) - last(value))/diff_in_safe_conveyance
)
# saveRDS(cea_df, 'Data/cea_df.rds')
# if(synth_data == FALSE) {
# cea_df <- readRDS('Data/cea_df.rds')
# } else {
# cea_df <- readRDS('SynData/cea_df.rds')
# }
```
```{r abstract-data, cache = F}
abstract_df <- data.frame(
# CITS data
level_val = cits_tidy$estimate[7],
level_ci = cits_tidy$ci[7],
level_p = cits_tidy$p.value[7],
trend_val = cits_tidy$estimate[8],
trend_ci = cits_tidy$ci[8],
trend_p = cits_tidy$p.value[8],
# Economic data
rp_mean_cost_per_nc = round(pre_post_econ_df %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_per_safe_conveyance),2),
rp_ci_per_nc = paste0(round(round(pre_post_econ_df %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_lower_per_safe_conveyance),2),2), "--£", round(round(pre_post_econ_df %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_upper_per_safe_conveyance),2),2)),
control_mean_cost_per_nc = round(pre_post_econ_df %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_per_safe_conveyance),2),
control_ci_per_nc = paste0(round(round(pre_post_econ_df %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_lower_per_safe_conveyance),2),2), "--£", round(round(pre_post_econ_df %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_upper_per_safe_conveyance),2),2)),
diff_mean = round(cea_df$mean_diff[cea_df$name=="cost_per_safe_conveyance"], 2),
diff_ci = paste0(round(cea_df$mean_diff[cea_df$name=="cost_upper_per_safe_conveyance"],2), "--£", round(cea_df$mean_diff[cea_df$name=="cost_lower_per_safe_conveyance"], 2)),
mean_cea = round(cea_df$cea[cea_df$name=="cost_per_safe_conveyance"], 2),
ci_cea = paste0(round(cea_df$cea[cea_df$name=="cost_upper_per_safe_conveyance"],2), "--£", round(cea_df$cea[cea_df$name=="cost_lower_per_safe_conveyance"], 2)),
# Sensitivty econ
rp_mean_cost_per_nc_no_wi = round(pre_post_econ_df_no_wi %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_per_safe_conveyance),2),
rp_ci_per_nc_no_wi = paste0(round(round(pre_post_econ_df_no_wi %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_lower_per_safe_conveyance),2),2), "--£", round(round(pre_post_econ_df_no_wi %>% filter(level == 1, rot_paras == 'Rotational Paramedics') %>% pull(cost_upper_per_safe_conveyance),2),2)),
control_mean_cost_per_nc_no_wi = round(pre_post_econ_df_no_wi %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_per_safe_conveyance),2),
control_ci_per_nc_no_wi = paste0(round(round(pre_post_econ_df_no_wi %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_lower_per_safe_conveyance),2),2), "--£", round(round(pre_post_econ_df_no_wi %>% filter(level == 0, rot_paras == 'Rotational Paramedics') %>% pull(cost_upper_per_safe_conveyance),2),2)),
diff_mean_no_wi = round(cea_df_no_wi$mean_diff[cea_df_no_wi$name=="cost_per_safe_conveyance"], 2),
diff_ci_no_wi = paste0(round(cea_df_no_wi$mean_diff[cea_df_no_wi$name=="cost_upper_per_safe_conveyance"],2), "--£", round(cea_df_no_wi$mean_diff[cea_df_no_wi$name=="cost_lower_per_safe_conveyance"], 2)),
mean_cea_no_wi = round(cea_df_no_wi$cea[cea_df_no_wi$name=="cost_per_safe_conveyance"], 2),
ci_cea_no_wi = paste0(round(cea_df_no_wi$cea[cea_df_no_wi$name=="cost_upper_per_safe_conveyance"],2), "--£", round(cea_df_no_wi$cea[cea_df_no_wi$name=="cost_lower_per_safe_conveyance"], 2)),
stringsAsFactors = F
)
adf <- abstract_df
if(synth_data == TRUE) {
saveRDS(abstract_df, 'SynData/abstract-data.rds')
} else {
saveRDS(abstract_df, 'Data/abstract-data.rds')
}
```
Post-placement, the cost per appropriate non-conveyance for intervention group SPs was a mean of £`r adf$rp_mean_cost_per_nc` (95% bootstrapped CI £`r adf$rp_ci_per_nc`) versus £`r adf$control_mean_cost_per_nc` (95% bootstrapped CI £`r adf$control_ci_per_nc`) for the same group in the pre-placement phase. This represents a mean saving of £`r adf$diff_mean` per appropriate non-conveyance (95% bootstrapped CI £`r adf$diff_ci`) and a cost-effectiveness ratio of £`r adf$mean_cea` per percentage increase in appropriate non-conveyance (95% bootstrapped CI £`r adf$ci_cea`).
The sensitivity analysis (excluding the working impression) calculated the mean post-placement cost per appropriate non-conveyance for intervention group SPs to be £`r adf$rp_mean_cost_per_nc_no_wi` (95% bootstrapped CI £`r adf$rp_ci_per_nc_no_wi`) versus £`r adf$control_mean_cost_per_nc_no_wi` (95% bootstrapped CI £`r adf$control_ci_per_nc_no_wi`) for the same group in the pre-placement phase. This represents a mean saving of £`r adf$diff_mean_no_wi` per appropriate non-conveyance (95% bootstrapped CI £`r adf$diff_ci_no_wi`) and a cost-effectiveness ratio of £`r adf$mean_cea_no_wi` per percentage increase in appropriate non-conveyance (95% bootstrapped CI £`r adf$ci_cea_no_wi`).