-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPQIP_prediction_modelling.Rmd
1622 lines (1269 loc) · 73.8 KB
/
PQIP_prediction_modelling.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
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "PQIP morbidity risk prediction modelling"
output:
word_document: default
html_document: default
---
```{r setup, include=FALSE, echo=FALSE, warning=FALSE}
knitr::opts_chunk$set(echo = FALSE)
setwd("~/Documents/Work/Research/Postoperative-morbidity-model-development-PQIP-2022")
```
## Data export
Data were exported from the central PQIP database on 9th April 2021.
```{r, echo=FALSE, include=FALSE, warning=FALSE}
## Load packages required for analysis
source("./source files/packages.R")
source("./source files/bootstepAIC.R")
source("./source files/validation.R")
source("./source files/ModelAnalysisFunctions.R")
## Load data
export_data <- read.csv(file = "./data/data_export.csv",
na.strings = c("", "NA", "-9999", "NULL"))
admission_data <- read.csv(file = "./data/admission.csv",
na.strings = c("", "NA", "-9999", "NULL")) %>%
select(ReferenceCode, Locked,
S14LookAfterPersonalToiletHygieneUnaided,S14AbleToBreatheEasily,
S14WorkOrUndertakeUsualHomeActivities,
EQ5D01Mobility, EQ5D02Selfcare, EQ5D03UsualActivities,
S15StandingForLongPeriodsSuchAs30Minutes,S15TakingCareOfHouseholdResponsibilities,
S15HowMuchProblemJoiningCommunityActivitiesInTheSameWayAsAnyoneElseCan,
S15WalkingALongDistanceSuchAsAKilometreOrEquivalent, S15WashingYourWholeBody,
S15GettingDressed) %>%
filter(Locked == "True") %>% select(-Locked)
export_data <- left_join(export_data, admission_data, by = c("CaseId" = "ReferenceCode"))
# run initial data cleaning script
# Clean date format, procedure codes, severity of procedure, remove test data
# Filter to locked records only
source("./source files/data cleaning.R")
source("./source files/data_cleaning_2.R")
source("./source files/table2.R")
```
```{r}
## total number of cases in data export
n_total_export
## number of locked cases in export
n_locked
## number who underwent surgery on or before 30th March 2020
n_eligble_date
## number of eligible colorectal cases based on date of surgery and surgical specialty
n_colorectal_eligible
# merge LSOA to dataframe
## link IMD quintile to LSOA based on corrected quintiles (Abel et al 2016, BMJ Open)
# https://doi.org/10.5523/bris.1ef3q32gybk001v77c1ifmty7x
LSOA_linkage <- read_csv("data/LSOA_linkage_JB_25082021.csv")
LSOA_linkage <- LSOA_linkage %>%
select(CaseId, lsoa11cd) %>%
mutate(lsoa11cd = factor(lsoa11cd))
export_data <- left_join(export_data, LSOA_linkage, by = "CaseId")
source("./source files/IMD_2019.R")
export_data <- left_join(export_data, IMD_adjusted, by = c("lsoa11cd" = "LSOA_code")) %>%
mutate(IMD_quintile_adjusted = factor(IMD_quintile_adjusted))
```
## Predictor variable exploration
## Age
```{r}
Desc(export_data$S01AgeYears)
```
### Sex
```{r}
Desc(export_data$S01Gender)
## convert gender to factor
export_data <- export_data %>% mutate(S01Gender = factor(S01Gender))
```
### BMI
```{r}
Desc(export_data$S01BMI)
```
We can see that ther are extreme outliers in the BMI data. We will explore this in more detail by plotting height against weight.
```{r}
ggplot(export_data, aes(x=S01Weight,y=S01Height)) +
geom_point() +
theme_cowplot()
```
We will explore all cases with BMI \<15kg/m2 and \>50kg/m2 to see if there is an obvious error with height/weight being entered into the incorrect field.
```{r}
export_data %>% filter(S01BMI <= 12 | S01BMI >= 50) %>% select(CaseId, S01Height, S01Weight, S01BMI) %>% arrange(CaseId)
```
We can see that some cases have the height and weight entered into the opposite field. We will correct these now. We will place a cut off of BMI \>60 and \<12, and change these data to NA for now. They will be imputed later.
```{r}
source("./source files/BMI_correction.R")
export_data$S01Height[export_data$CaseId %in% BMI_CaseId] <- BMI_height
export_data$S01Weight[export_data$CaseId %in% BMI_CaseId] <- BMI_weight
export_data$S01BMI[export_data$CaseId %in% BMI_CaseId] <- export_data$S01Weight[export_data$CaseId %in% BMI_CaseId]/((export_data$S01Height[export_data$CaseId %in% BMI_CaseId]/100)^2)
# set BMI <12 and >60 to NA
BMI_remove <- nrow(export_data %>% filter(S01BMI >60 | S01BMI < 12) %>% select(CaseId, S01Height, S01Weight, S01BMI))
export_data <- export_data %>% mutate(S01BMI = ifelse(S01BMI >60, NA,
ifelse(S01BMI <12, NA,
S01BMI)))
Desc(export_data$S01BMI)
summary(export_data$S01BMI)
```
### Severity of procedure - actual procedure performed
```{r}
Desc(export_data$SORT_severity)
export_data <- export_data %>% mutate(SORT_severity.combined = dplyr::recode_factor(SORT_severity,
`Min`="Min/Int/Maj",
`Int`="Min/Int/Maj",
`Maj`="Min/Int/Maj"))
Desc(export_data$SORT_severity.combined)
```
### Mode of surgery - actual mode performed
If the procedure was converted to open, then it would be considered as open here.
```{r}
# Let's create a combined category for this variable - we will also combine laparoscopic/thoracoscopic into one variable
Desc(export_data$S03ActualProcedureSurgeryMode)
Desc(export_data$S02PlannedProcedureSurgeryModeLaparoscopic)
table(export_data$S03WasProcedureTheSameAsThePlannedProcedure, export_data$S03ActualProcedureSurgeryMode)
table(export_data$S02PlannedProcedureSurgeryModeOpen, export_data$S02PlannedProcedureSurgeryModeLaparoscopic)
table(export_data$S02PlannedProcedureSurgeryModeLaparoscopic, export_data$S02PlannedProcedureSurgeryModeRobotic)
table(export_data$S02PlannedProcedureSurgeryModeRobotic, export_data$S02PlannedProcedureSurgeryModeThoracoscopic)
table(export_data$S03WasProcedureTheSameAsThePlannedProcedure, export_data$S02PlannedProcedureSurgeryModeThoracoscopic)
# create variable that includes actual mode of surgery
export_data <- export_data %>%
mutate(S02PlannedProcedureSurgeryModeThoracoscopic = replace_na(S02PlannedProcedureSurgeryModeThoracoscopic,2)) %>%
mutate(ModeSurgery = ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Opn",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1
& S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==2
& S02PlannedProcedureSurgeryModeThoracoscopic==2,"OpnLap",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"OpnRob",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"OpnTho",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 &
S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Lap",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"LapRob",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"LapTho",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Rob",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"RobTho",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"Tho",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"OpnLapRob",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"OpnLapTho",
ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "Y" & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==1,"LapRobTho",
NA)))))))))))))) %>%
mutate(ModeSurgery = ifelse(S03WasProcedureTheSameAsThePlannedProcedure == "N",
S03ActualProcedureSurgeryMode, ModeSurgery)) %>%
mutate(ModeSurgery = ifelse(is.na(ModeSurgery) & S02PlannedProcedureSurgeryModeOpen==1 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Opn",
ifelse(is.na(ModeSurgery) & S02PlannedProcedureSurgeryModeOpen==1
& S02PlannedProcedureSurgeryModeLaparoscopic==1 & S02PlannedProcedureSurgeryModeRobotic==2
& S02PlannedProcedureSurgeryModeThoracoscopic==2,"OpnLap",
ifelse(is.na(ModeSurgery) & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==1 &
S02PlannedProcedureSurgeryModeRobotic==2 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Lap",
ifelse(is.na(ModeSurgery) & S02PlannedProcedureSurgeryModeOpen==2 &
S02PlannedProcedureSurgeryModeLaparoscopic==2 & S02PlannedProcedureSurgeryModeRobotic==1 &
S02PlannedProcedureSurgeryModeThoracoscopic==2,"Rob", ModeSurgery))))) %>%
mutate(ModeSurgeryCombined = factor(recode(ModeSurgery,
`Lap`="Lap",
`Tho`="Lap",
`LapRob`="Rob",
`OpnLap`="Opn",
`OpnLapRob`="Opn",
`OpnRob`="Opn")))
Desc(export_data$ModeSurgeryCombined)
```
Based on this coding, where multiple modes of surgery have been selected we have applied the following hierachy: Open \> Robotic \> Laparoscopic
### NCEPOD classification of surgery
```{r}
Desc(export_data$S02UrgencyOfSurgery)
export_data$S02UrgencyOfSurgery <- factor(export_data$S02UrgencyOfSurgery)
```
```{r}
export_data <- export_data %>% select(-S02PlannedProcedureSurgeryMultiStageProcedure, -S02PlannedProcedureSurgeryMultiStageProcedureDate)
```
### Cancer diagnosis
```{r}
Desc(export_data$S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsNo)
Desc(export_data$S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesSolidLocal)
Desc(export_data$S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesSolidMeta)
Desc(export_data$S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLeukaemia)
Desc(export_data$S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLymphoma)
## We will combine these variables into one.
export_data <- export_data %>%
mutate(CancerDiagnosis = ifelse(S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesSolidMeta==1 |
S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLeukaemia==1 |
S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLymphoma==1 | S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesSolidLocal==1,
"Cancer diagnosis","No cancer")) %>%
mutate(CancerDiagnosis = factor(CancerDiagnosis))
Desc(export_data$CancerDiagnosis)
```
### Serum Sodium
```{r}
Desc(export_data$S02SerumSodium)
Na_remove <- nrow(export_data %>% filter(S02SerumSodium > 160))
export_data$S02SerumSodium[export_data$S02SerumSodium > 160] <- NA
```
### Serum Potassium
```{r}
Desc(export_data$S02SerumPotassium)
## we will set any potassium level >6.5mmol/L to NA as these patients to NA
K_remove <- nrow(export_data %>% filter(S02SerumPotassium >= 6.5))
export_data$S02SerumPotassium[export_data$S02SerumPotassium >= 6.5] <- NA
```
### Serum Urea
```{r}
Desc(export_data$S02SerumUrea)
ggplot(export_data, aes(S02SerumUrea, S02SerumCreatinine)) +
geom_point()
# we can see the plot shows significant outliers with normal creatinine level but urea >40umol/L. We will set these values to NA and impute them late
Urea_remove <- nrow(export_data %>% filter(S02SerumUrea > 40))
export_data$S02SerumUrea[export_data$S02SerumUrea > 40] <- NA
export_data$log.Urea <- log(export_data$S02SerumUrea)
```
### Serum Creatinine
```{r}
Desc(export_data$S02SerumCreatinine)
export_data <- export_data %>% mutate(log.Creatinine = log(S02SerumCreatinine))
```
### Serum Troponin
```{r}
Desc(export_data$S02SerumTroponin)
# The missingness in the Troponin variable is almost 100% therefore we will remove this as a candidate variable
export_data <- export_data %>% select(-S02SerumTroponin, -S02SerumTroponin_NK)
```
### Serum Albumin
```{r}
Desc(export_data$S02SerumAlbumin)
```
### White cell count
```{r}
Desc(export_data$S02WhiteCellCount)
ggplot(export_data, aes(S02WhiteCellCount)) +
geom_bar()
export_data %>% filter(S02WhiteCellCount >37.5) %>% select(S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLeukaemia,
S02PatientHasDiagnosisOfCancerCurrentOrLessThan5YearsYesLymphoma, CaseId)
## we can see that none of these patients were diagnosed with either Leukaemia or lymphoma (a cause of significantly elevated WCC). We will therefore set these values to NA and impute based on physiological plausibility
WCC_remove <- nrow(export_data %>% filter(S02WhiteCellCount > 40))
export_data$S02WhiteCellCount[export_data$S02WhiteCellCount >40] <- NA
```
### Haemoglobin
```{r}
Desc(export_data$S02Haemoglobin)
ggplot(export_data, aes(S02Haemoglobin)) +
geom_bar()
Hb_remove <- nrow(export_data %>% filter(S02Haemoglobin < 7.0))
export_data$S02Haemoglobin[export_data$S02Haemoglobin < 7.0] <- NA
```
### Pulse Rate
```{r}
Desc(export_data$S02PulseRate)
ggplot(export_data, aes(S02PulseRate)) +
geom_bar()
# We will remove all values >150 on the basis that these patients would not go on to have elective surgery
HR_remove <- nrow(export_data %>% filter(S02PulseRate > 150))
export_data$S02PulseRate[export_data$S02PulseRate > 150] <- NA
```
### Systolic BP
```{r}
Desc(export_data$S02SystolicBP)
ggplot(export_data, aes(S02SystolicBP)) +
geom_bar()
# We will remove all values >200 and <70mmHg on the basis that these patients would not go on to have elective surgery
BP_remove <- nrow(export_data %>% filter(S02SystolicBP > 250 | S02SystolicBP < 70))
export_data$S02SystolicBP[export_data$S02SystolicBP > 250] <- NA
export_data$S02SystolicBP[export_data$S02SystolicBP < 70] <- NA
```
### GCS
```{r}
Desc(export_data$S02GlasgowComaScaleTotal)
ggplot(export_data, aes(S02GlasgowComaScaleTotal)) +
geom_bar()
# We will remove GCS as a candidate variable given the lack of variation (100% GCS 15)
#export_data <- export_data %>% select(-S02GlasgowComaScaleTotal)
```
### Oxygen saturations
```{r}
Desc(export_data$S02SpO2)
ggplot(export_data, aes(S02SpO2)) +
geom_bar()
O2sats_remove <- nrow(export_data %>% filter(S02SpO2 < 85))
export_data$S02SpO2[export_data$S02SpO2 < 85] <- NA
```
### ECG findings
```{r}
Desc(export_data$S02ECGFindings)
export_data$S02ECGFindings <- factor(export_data$S02ECGFindings)
```
### Cardiac history findings
```{r}
Desc(export_data$S02CardiacHistoryFindings)
# we will combine P and R groups
export_data$S02CardiacHistoryFindings.combined = dplyr::recode_factor(export_data$S02CardiacHistoryFindings,
`P`="P/R",`R`="P/R")
Desc(export_data$S02CardiacHistoryFindings.combined)
```
### NYHA classification
```{r}
Desc(export_data$S02NYHAHeartFailureClassification)
# we will combine III and IV groups
export_data$S02NYHAHeartFailureClassification.combined = dplyr::recode_factor(export_data$S02NYHAHeartFailureClassification,
`III`="III/IV",`IV`="III/IV")
Desc(export_data$S02NYHAHeartFailureClassification.combined)
```
### Respiratory history findings
```{r}
Desc(export_data$S02RespiratoryHistoryFindings)
# we will combine DLE and DAR groups
export_data$S02RespiratoryHistoryFindings.combined = dplyr::recode_factor(export_data$S02RespiratoryHistoryFindings,
`DLE`="DLE/DAR",`DAR`="DLE/DAR")
Desc(export_data$S02RespiratoryHistoryFindings.combined)
```
### Respiratory infection in last month
```{r}
Desc(export_data$S02PatientHadRespiratoryInfectionInTheLastMonth)
export_data$S02PatientHadRespiratoryInfectionInTheLastMonth <- factor(export_data$S02PatientHadRespiratoryInfectionInTheLastMonth)
```
### History of CVA
```{r}
Desc(export_data$S02PatientHasHistoryOfCerebrovascularDisease)
export_data$S02PatientHasHistoryOfCerebrovascularDisease.combined = dplyr::recode_factor(export_data$S02PatientHasHistoryOfCerebrovascularDisease,
`YNH`="YNH/YWH",
`YWH`="YNH/YWH")
Desc(export_data$S02PatientHasHistoryOfCerebrovascularDisease.combined)
```
### Dementia
```{r}
Desc(export_data$S02PatientHasDementia)
export_data$S02PatientHasDementia <- factor(export_data$S02PatientHasDementia)
```
### Diabetes
```{r}
Desc(export_data$S02PatientHasDiabetes)
export_data <- export_data %>% mutate(Diabetes = recode_factor(S02PatientHasDiabetes,
`2` = "N",
`T1` = "Y",
`T2I` = "Y",
`1` = "Y",
`T2D` = "Y",
`T2N` = "Y"))
Desc(export_data$Diabetes)
Desc(export_data %>% filter(Diabetes == "Y") %>% select(S02HbA1c))
## Remove HbA1c >20
HbA1c_remove <- nrow(export_data %>% filter(S02HbA1c > 20))
export_data$S02HbA1c[export_data$S02HbA1c >20] <- NA
```
### Liver disease
```{r}
Desc(export_data$S02PatientHasLiverDisease)
# we will combine YWO and YW into one group as <1% on both groups
export_data$S02PatientHasLiverDisease.combined = dplyr::recode_factor(export_data$S02PatientHasLiverDisease,
`YWO`="Y", `YW`="Y")
Desc(export_data$S02PatientHasLiverDisease.combined)
Desc(export_data$S02PatientHasLiverDiseaseChildPughGrade)
Desc(export_data$S02PatientHasLiverDiseaseType)
# We will remove Child's Pugh variable and Liver disease type due to missingness >95%
export_data <- export_data %>% select(-S02PatientHasLiverDiseaseChildPughGrade, -S02PatientHasLiverDiseaseType)
```
### ASA category
```{r}
Desc(export_data$S02PatientsASAGrade)
# we will combine ASA IV and ASA V groups as there are fewer than 1% cases in ASA V category
export_data <- export_data %>% mutate(S02PatientsASAGrade.combined = dplyr::recode(export_data$S02PatientsASAGrade,
`IV`="IV/V",`V`="IV/V"))
Desc(export_data$S02PatientsASAGrade.combined)
```
### Smoking history
```{r}
Desc(export_data$S02PatientsSmokingHistory)
# we will convery "not known" to NA and impute later
export_data$S02PatientsSmokingHistory[export_data$S02PatientsSmokingHistory == "NK"] <- NA
export_data$S02PatientsSmokingHistory <- factor(export_data$S02PatientsSmokingHistory)
```
### Operations in last 30 days
```{r}
Desc(export_data$S03HowManyOperationsInPast30Days)
export_data$S03HowManyOperationsInPast30Days <- factor(export_data$S03HowManyOperationsInPast30Days)
# we will combine categories "2" and "G2" into one
export_data$S03HowManyOperationsInPast30Days.combined = dplyr::recode_factor(export_data$S03HowManyOperationsInPast30Days,
`2`="2ormore",`G2`="2ormore")
export_data$S03HowManyOperationsInPast30Days.combined = factor(export_data$S03HowManyOperationsInPast30Days.combined,
ordered = FALSE)
Desc(export_data$S03HowManyOperationsInPast30Days.combined)
```
### Clinical frailty scale
```{r}
Desc(export_data$S02RockwoodClinicalFrailtyScore)
## We will exclude owing to missing data (55.7% missing)
export_data <- export_data %>%
mutate(Rockwood.combined = dplyr::recode(S02RockwoodClinicalFrailtyScore,
`1`='1',
`2`='2',
`3`='3',
`4`='4',
`5`='5',
`6`='6-9',
`7`='6-9',
`8`='6-9',
`9`='6-9',
`ND`='ND')) %>%
mutate(Rockwood.combined = ifelse(Rockwood.combined != "ND", Rockwood.combined, NA),
Rockwood.combined = factor(Rockwood.combined))
```
## Full morbidity prediction model
The following variables are suitable for consideration of entry into the model:
1. Sex
2. Age (years)
3. ASA grade
4. Severity of surgery
5. Mode of surgery
6. Urgency of surgery
7. BMI
8. Serum sodium
9. Serum potassium
10. Serum urea
11. Serum creatinine
12. Serum Albumin
13. White Cell Count
14. Haemoglobin
15. Heart rate
16. Systolic blood pressure
17. Oxygen saturations
18. Respiratory history findings
19. Cardiac history findings
20. NYHA classification
21. ECG findings
22. Respiratory infection in last month
23. Cerebrovascular disease
24. Dementia history
25. Cancer diagnosis
26. Number of operations in last 30 days
27. Diabetes - with control status
28. Smoking status
29. Liver disease
30. Rockwood Clinical Frailty Scale
31. Index of multiple deprivation (IMD 2019 - adjusted using Abel 2016 method)
Excluded variables (based on missingness):
1. Troponin
2. Child's Pugh classification
3. Multi-stage procedures
```{r}
## Relevel variables to set reference level
export_data <- export_data %>%
mutate(S01Gender = relevel(S01Gender, ref = "F"),
S02PatientsASAGrade.combined = relevel(S02PatientsASAGrade.combined, ref = "I"),
SORT_severity.combined = relevel(SORT_severity.combined, ref = "Min/Int/Maj"),
S02UrgencyOfSurgery = relevel(S02UrgencyOfSurgery, ref = "El"),
S02RespiratoryHistoryFindings.combined = relevel(S02RespiratoryHistoryFindings.combined, ref = "N"),
S02CardiacHistoryFindings.combined = relevel(S02CardiacHistoryFindings.combined, ref = "NF"),
S02NYHAHeartFailureClassification.combined = relevel(S02NYHAHeartFailureClassification.combined, ref = "I"),
S02ECGFindings = relevel(S02ECGFindings, ref = "N"),
S02PatientHadRespiratoryInfectionInTheLastMonth = relevel(S02PatientHadRespiratoryInfectionInTheLastMonth, ref = "N"),
S02PatientHasHistoryOfCerebrovascularDisease.combined = relevel(S02PatientHasHistoryOfCerebrovascularDisease.combined, ref = "N"),
S02PatientHasDementia = relevel(factor(S02PatientHasDementia), ref = "N"),
CancerDiagnosis = relevel(CancerDiagnosis, ref = "No cancer"),
S03HowManyOperationsInPast30Days.combined = relevel(S03HowManyOperationsInPast30Days.combined, ref = "1"),
Rockwood.combined = relevel(Rockwood.combined, ref = "1"),
S02PatientsSmokingHistory == relevel(S02PatientsSmokingHistory, "NS"),
S02PatientHasLiverDisease.combined = relevel(S02PatientHasLiverDisease.combined, ref = "N"),
IMD_quintile_adjusted = relevel(IMD_quintile_adjusted, ref = "1"))
```
#### Sensitivity analysis
1. Rockwood frailty scoring - run analysis based on data after introduction of Rockwood frailty scoring where missingness is lower
2. Homogenous outcome measure - gastrointestinal POMS
3. Multilevel model incorporating random intercept for hospital site
## Multiple imputation
We will use multiple imputation to handle missing variables. To do this we will use the MICE package in R, using the default predictive mean matching for continuous variables and logistic regression for binary variables. Our imputation model will include all candidate predictors.
We will impute the dataset 10 times.
```{r}
export_data <- POSSUM.SORT.calculation(export_data)
auc_SORT <- roc(export_data$POMS.overall, export_data$SORT.morbidity.intercept_slope_calibrated)
set.seed(15092021)
ci_auc_SORT <- ci.auc(auc_SORT, method = "bootstrap")
auc_POSSUM <- roc(export_data$POMS.overall, export_data$POSSUM.morbidity.intercept_slope_calibrated)
set.seed(15092021)
ci_auc_POSSUM <- ci.auc(auc_POSSUM, method = "bootstrap")
roc.test(auc_SORT, auc_POSSUM, method = "bootstrap")
POMS_summary <- export_data %>% select(POMS.overall, POMS.major, ClavienGradeIIabove) %>%
mutate(n = 1) %>%
summarise(POMSoverall.perc = round(sum(POMS.overall)/sum(n)*100,1),
POMSmajor.perc = round(sum(POMS.major)/sum(n)*100,1),
ClavienGradeIIabove.perc = round(sum(ClavienGradeIIabove)/sum(n)*100,1),
POMSoverall.n = sum(POMS.overall),
POMSmajor.n = sum(POMS.major),
ClavienGradeIIabove.n = sum(ClavienGradeIIabove))
n_LOS_7days <- paste(c(nrow(export_data %>% filter(LengthOfStay>=7)),"-", round(nrow(export_data %>% filter(LengthOfStay>=7))/nrow(export_data)*100,1),"%"))
POMS_organ_domain <- export_data %>%
select(Pulmonary.overall, Infectious.overall, Renal.overall, Gastrointestinal.overall, Cardiovascular.overall, Neurological.overall, Haematological.overall, Wound.overall, Pain.overall) %>%
summarise(across(.cols = everything(), ~ sum(.x))) %>%
pivot_longer(everything()) %>%
mutate(n = value,
percent = round(value/nrow(export_data)*100,3)) %>%
select(name, n, percent)
POMS.table <- export_data %>%
select(S06PatientHasNewRequirementForO2Therapy,
S06PatientHasNewRequirementForVentilator,
S06PatientIsOnIVAntibiotic,
S06HasHadATemperatureGreaterThan38InThePast24h,
S06PatientHasBeenUnableToTolerateEnteralNutrition,
S06PatientHasHadNauseaVomitingOrAbdominalDistensionInPast24h,
S06PatientHadSinceSurgeryOliguria,
S06PatientHadSinceSurgeryCreatinine30,
S06PatientHadSinceSurgeryUrinaryCatheterBeyondDay1,
S06PatientHasHadDiagnosticTestsHypotension,
S06PatientHasHadDiagnosticTestsNewMyocardialInfarctionOrIschaemia,
S06PatientHasHadDiagnosticTestsThromboticEvent,
S06PatientHasHadDiagnosticTestsArrhythmias,
S06PatientHasHadDiagnosticTestsCardiogenicPulmonaryOedema,
S06PatientHasDevelopedSinceSurgeryNewNeurologicalDeficit,
S06PatientHasDevelopedSinceSurgeryDeliriumOrConfusion,
S06PatientHasDevelopedSinceSurgerySedativeInducedComa,
S06PatientHasDevelopedSinceSurgeryNonSedativeAassociatedComa,
S06PatientHadWoundRequiringSurgicalExploration,
S06PatientHadDrainageOfPus,
S06PatientRequiredRedCellTransfusion,
S06PatientRequiredPlasma,
S06PatientSurgicalPainParenteralOpioids,
S06PatientSurgicalPainRegionalAnaesthesia) %>%
mutate(coma = S06PatientHasDevelopedSinceSurgerySedativeInducedComa == 1 | S06PatientHasDevelopedSinceSurgeryNonSedativeAassociatedComa == 1,
wound = S06PatientHadWoundRequiringSurgicalExploration == 1 | S06PatientHadDrainageOfPus == 1) %>%
dplyr::summarise(O2 = sum(S06PatientHasNewRequirementForO2Therapy==1)/length(S06PatientHasNewRequirementForO2Therapy),
ventilator = sum(S06PatientHasNewRequirementForVentilator==1)/length(S06PatientHasNewRequirementForVentilator),
IVanti = sum(S06PatientIsOnIVAntibiotic==1)/length(S06PatientIsOnIVAntibiotic),
temperature = sum(S06HasHadATemperatureGreaterThan38InThePast24h==1)/length(S06HasHadATemperatureGreaterThan38InThePast24h),
catheter = sum(S06PatientHadSinceSurgeryUrinaryCatheterBeyondDay1==1)/length(S06PatientHadSinceSurgeryUrinaryCatheterBeyondDay1),
creat = sum(S06PatientHadSinceSurgeryCreatinine30==1)/length(S06PatientHadSinceSurgeryCreatinine30),
Oliguria = sum(S06PatientHadSinceSurgeryOliguria==1)/length(S06PatientHadSinceSurgeryOliguria),
ent.nut = sum(S06PatientHasBeenUnableToTolerateEnteralNutrition==1)/length(S06PatientHasBeenUnableToTolerateEnteralNutrition),
nausea = sum(S06PatientHasHadNauseaVomitingOrAbdominalDistensionInPast24h==1)/length(S06PatientHasHadNauseaVomitingOrAbdominalDistensionInPast24h),
thrombotic = sum(S06PatientHasHadDiagnosticTestsThromboticEvent==1)/length(S06PatientHasHadDiagnosticTestsThromboticEvent),
arrythmmia = sum(S06PatientHasHadDiagnosticTestsArrhythmias==1)/length(S06PatientHasHadDiagnosticTestsArrhythmias),
hypotension = sum(S06PatientHasHadDiagnosticTestsHypotension==1)/length(S06PatientHasHadDiagnosticTestsHypotension),
myocard = sum(S06PatientHasHadDiagnosticTestsNewMyocardialInfarctionOrIschaemia==1)/length(S06PatientHasHadDiagnosticTestsNewMyocardialInfarctionOrIschaemia),
pulOedema = sum(S06PatientHasHadDiagnosticTestsCardiogenicPulmonaryOedema==1)/length(S06PatientHasHadDiagnosticTestsCardiogenicPulmonaryOedema),
coma = sum(coma)/length(coma),
delerium = sum(S06PatientHasDevelopedSinceSurgeryDeliriumOrConfusion==1)/length(S06PatientHasDevelopedSinceSurgeryDeliriumOrConfusion),
neurodef = sum(S06PatientHasDevelopedSinceSurgeryNewNeurologicalDeficit==1)/length(S06PatientHasDevelopedSinceSurgeryNewNeurologicalDeficit),
FFP = sum(S06PatientRequiredPlasma==1)/length(S06PatientRequiredPlasma),
RBC = sum(S06PatientRequiredRedCellTransfusion==1)/length(S06PatientRequiredRedCellTransfusion),
wound = sum(wound)/length(wound),
opiod = sum(S06PatientSurgicalPainParenteralOpioids==1)/length(S06PatientSurgicalPainParenteralOpioids),
regional = sum(S06PatientSurgicalPainRegionalAnaesthesia==1)/length(S06PatientSurgicalPainRegionalAnaesthesia)) %>%
pivot_longer(cols = everything(), names_to = "POMSdomain") %>%
mutate(percent = round(value*100,3),
n = value*11646)
clavien_summary <- export_data %>% select(S07GradeLevelOfComplicationsNone,
S07GradeLevelOfComplicationsGradeI,
S07GradeLevelOfComplicationsGradeII,
S07GradeLevelOfComplicationsGradeIIIA,
S07GradeLevelOfComplicationsGradeIIIB,
S07GradeLevelOfComplicationsGradeIVA,
S07GradeLevelOfComplicationsGradeIVB,
S07GradeLevelOfComplicationsGradeV) %>%
mutate(across(everything(), ~.x=="1")) %>%
summarise(across(everything(), ~sum(.x)/length(.x))) %>%
pivot_longer(everything()) %>%
mutate(n = value*nrow(export_data),
percent = round(value*100,4)) %>%
select(name, n, percent)
data_impute <- export_data %>%
select(POMS.overall, POMS.major, ClavienGradeIIabove,
S01Gender, S01AgeYears, S02PatientsASAGrade.combined, CancerDiagnosis,
SORT_severity.combined, ModeSurgeryCombined, S02UrgencyOfSurgery, S01BMI,
S02SerumSodium, S02SerumPotassium, S02SerumUrea, S02SerumCreatinine,
S02WhiteCellCount, S02SerumAlbumin,
S02Haemoglobin, S02PulseRate, S02SystolicBP, S02SpO2,
S02RespiratoryHistoryFindings.combined, S02CardiacHistoryFindings.combined,
S02NYHAHeartFailureClassification.combined, S02ECGFindings,
S02PatientHadRespiratoryInfectionInTheLastMonth,
S02PatientHasHistoryOfCerebrovascularDisease.combined, S02PatientHasDementia, S03HowManyOperationsInPast30Days.combined, Diabetes, S02HbA1c, S02PatientsSmokingHistory,
S02PatientHasLiverDisease.combined,
S14LookAfterPersonalToiletHygieneUnaided,S14AbleToBreatheEasily,
S14WorkOrUndertakeUsualHomeActivities,
EQ5D01Mobility, EQ5D02Selfcare, EQ5D03UsualActivities,
S15StandingForLongPeriodsSuchAs30Minutes,S15TakingCareOfHouseholdResponsibilities,
S15HowMuchProblemJoiningCommunityActivitiesInTheSameWayAsAnyoneElseCan,
S15WalkingALongDistanceSuchAsAKilometreOrEquivalent, S15WashingYourWholeBody,
S15GettingDressed, Rockwood.combined, SiteName, S01PostcodeOut,
IMD_quintile_adjusted) %>%
mutate(log.Urea = log(S02SerumUrea),
log.Creatinine = log(S02SerumCreatinine),
IMD_quintile_adjusted = recode(IMD_quintile_adjusted,
`1` = "5 - least deprived",
`2` = "4",
`3` = "3",
`4` = "2",
`5` = "1 - most deprived"),
IMD_quintile_adjusted = relevel(IMD_quintile_adjusted, ref = "5 - least deprived"),
S15StandingForLongPeriodsSuchAs30Minutes = factor(S15StandingForLongPeriodsSuchAs30Minutes),
S15TakingCareOfHouseholdResponsibilities = factor(S15TakingCareOfHouseholdResponsibilities),
S15HowMuchProblemJoiningCommunityActivitiesInTheSameWayAsAnyoneElseCan = factor(S15HowMuchProblemJoiningCommunityActivitiesInTheSameWayAsAnyoneElseCan),
S15WalkingALongDistanceSuchAsAKilometreOrEquivalent = factor(S15WalkingALongDistanceSuchAsAKilometreOrEquivalent),
S15WashingYourWholeBody = factor(S15WashingYourWholeBody),
S15GettingDressed = factor(S15GettingDressed)) %>%
select(c(-S02SerumUrea, -S02SerumCreatinine))
data_complteness <- pct_complete(data_impute %>% select(S01Gender,S01AgeYears, S02PatientsASAGrade.combined, CancerDiagnosis,SORT_severity.combined,ModeSurgeryCombined, S02UrgencyOfSurgery, S01BMI, S02SerumSodium, S02SerumPotassium, S02WhiteCellCount, S02SerumAlbumin, S02Haemoglobin, S02PulseRate, S02SystolicBP, S02SpO2, S02RespiratoryHistoryFindings.combined, S02CardiacHistoryFindings.combined, S02NYHAHeartFailureClassification.combined, S02ECGFindings, S02PatientHadRespiratoryInfectionInTheLastMonth, S02PatientHasHistoryOfCerebrovascularDisease.combined, S02PatientHasDementia, S03HowManyOperationsInPast30Days.combined, Diabetes, S02HbA1c,S02PatientsSmokingHistory, S02PatientHasLiverDisease.combined,IMD_quintile_adjusted,log.Urea, log.Creatinine))
#rm(export_data)
# perform multiple imputation using MICE package, m=10
#mids <- parlmice(data_impute, m=10, cluster.seed = 26052021, ncore = 5)
#densityplot(mids)
#mids_data <- complete(mids, action = "long", include = TRUE) %>%
# mutate(Diabetes.control = ifelse(Diabetes == "N", "No diabetes",
# ifelse(Diabetes == "Y" & S02HbA1c <= 8.5, "Diabetes, good control",
# ifelse(Diabetes == "Y" & S02HbA1c >8.5, "Diabetes, poor control",NA)))) %>%
# select(c(-S14LookAfterPersonalToiletHygieneUnaided,S14AbleToBreatheEasily,
# -S14WorkOrUndertakeUsualHomeActivities,
# -EQ5D01Mobility,
# -EQ5D02Selfcare,
# -EQ5D03UsualActivities,
# -S15StandingForLongPeriodsSuchAs30Minutes,
# -S15TakingCareOfHouseholdResponsibilities,
# -S15HowMuchProblemJoiningCommunityActivitiesInTheSameWayAsAnyoneElseCan,
# -S15WalkingALongDistanceSuchAsAKilometreOrEquivalent,
# -S15WashingYourWholeBody,
# -S15GettingDressed,
# -S01PostcodeOut)) %>%
# as.mids(.)
#save(mids_data, file = "mids_data.RData")
load("mids_data.RData")
mids.centred <- complete(mids_data, action = "long", include = FALSE) %>%
summarise(S01AgeYears.mean = round(mean(S01AgeYears),0),
S01BMI.mean = round(mean(S01BMI),0),
S02SerumSodium.mean = round(mean(S02SerumSodium),0),
S02SerumPotassium.mean = round(mean(S02SerumPotassium),1),
log.Urea.mean = round(mean(log.Urea),1),
log.Creatinine.mean = round(mean(log.Creatinine),1),
S02SerumAlbumin.mean = round(mean(S02SerumAlbumin),0),
S02WhiteCellCount.mean = round(mean(S02WhiteCellCount),1),
S02Haemoglobin.mean = round(mean(S02Haemoglobin),1),
S02PulseRate.mean = round(mean(S02PulseRate),0),
S02SystolicBP.mean = round(mean(S02SystolicBP),0),
S02SpO2.mean = round(mean(S02SpO2),0))
mids_data <- complete(mids_data, action = "long", include = TRUE) %>%
mutate(S02PatientsSmokingHistory = relevel(S02PatientsSmokingHistory, ref = "NS")) %>%
mutate(S01AgeYears.centred = S01AgeYears - mids.centred$S01AgeYears.mean,
S01BMI.centred = S01BMI - mids.centred$S01BMI.mean,
S02SerumSodium.centred = S02SerumSodium - mids.centred$S02SerumSodium.mean,
S02SerumPotassium.centred = S02SerumPotassium - mids.centred$S02SerumPotassium.mean,
log.Urea.centred = log.Urea - mids.centred$log.Urea.mean,
log.Creatinine.centred = log.Creatinine - mids.centred$log.Creatinine.mean,
S02SerumAlbumin.centred = S02SerumAlbumin - mids.centred$S02SerumAlbumin.mean,
S02WhiteCellCount.centred = S02WhiteCellCount - mids.centred$S02WhiteCellCount.mean,
S02Haemoglobin.centred = S02Haemoglobin - mids.centred$S02Haemoglobin.mean,
S02PulseRate.centred = S02PulseRate - mids.centred$S02PulseRate.mean,
S02SystolicBP.centred = S02SystolicBP - mids.centred$S02SystolicBP.mean,
S02SpO2.centred = S02SpO2 - mids.centred$S02SpO2.mean) %>%
as.mids(.)
```
```{r}
## create summary statistics of dataframe for table 1
## add LOS column to dataframe
mids_data <- complete(mids_data, action = "long", include = TRUE) %>%
mutate(LengthOfStay = rep(export_data$LengthOfStay, 11)) %>%
as.mids(.)
median_LOS <- complete(mids_data, action = "long", include = TRUE) %>%
mutate(LengthOfStay = ifelse(LengthOfStay == 999, NA, LengthOfStay)) %>%
summarise(median.LOS = median(LengthOfStay, na.rm = TRUE),
IQR.25 = quantile(LengthOfStay, 0.25, na.rm=TRUE),
IQR.75 = quantile(LengthOfStay, 0.75, na.rm=TRUE))
summary_table_Age <- summary_variable_POMS_numerical(mids_data, S01AgeYears,
breaks = c(-Inf,39,49,59,69,79,Inf))
summary_table_Age
summary_Age <- paste0(mean(complete(mids_data, action = "long", include = FALSE)$S01AgeYears),
" (SD ", sd(complete(mids_data, action = "long", include = FALSE)$S01AgeYears), ")")
summary_table_Sex <- summary_variable_POMS_factor(mids_data, S01Gender)
summary_table_Sex
summary_table_ASA <- summary_variable_POMS_factor(mids_data, S02PatientsASAGrade.combined)
summary_table_ASA
summary_table_Cancer <- summary_variable_POMS_factor(mids_data, CancerDiagnosis)
summary_table_Cancer
summary_table_SORT <- summary_variable_POMS_factor(mids_data, SORT_severity.combined)
summary_table_SORT
summary_table_mode <- summary_variable_POMS_factor(mids_data, ModeSurgeryCombined)
summary_table_mode
summary_table_Urgency <- summary_variable_POMS_factor(mids_data, S02UrgencyOfSurgery)
summary_table_Urgency
summary_table_BMI <- summary_variable_POMS_numerical(mids_data, S01BMI,
breaks = c(-Inf,18.49,24.9,29.9,39.9,Inf))
summary_table_BMI
Desc(complete(mids_data, action = "long", include = FALSE)$S01BMI)
summary_BMI <- paste0(round(mean(complete(mids_data, action = "long", include = FALSE)$S01BMI),1),
" (SD ", round(sd(complete(mids_data, action = "long", include = FALSE)$S01BMI),1),")")
summary_table_Sodium <- summary_variable_POMS_numerical(mids_data, S02SerumSodium,
breaks = c(-Inf,133,146,Inf))
summary_table_Sodium
summary_table_Potassium <- summary_variable_POMS_numerical(mids_data, S02SerumPotassium,
breaks = c(-Inf,3.5,5.3,Inf))
summary_table_Potassium
summary_table_Urea <- summary_variable_POMS_numerical(mids_data, log.Urea,
breaks = c(-Inf,log(2.5),log(7.8),Inf))
summary_table_Urea
Desc(exp(complete(mids_data, action = "long", include = FALSE)$log.Urea))
summary_Urea <- paste0(exp(median(complete(mids_data, action = "long", include = FALSE)$log.Urea)),
" (IQR ", exp(quantile(complete(mids_data, action = "long", include = FALSE)$log.Urea, 0.25)), "-", exp(quantile(complete(mids_data, action = "long", include = FALSE)$log.Urea, 0.75)), " [range ", exp(min(complete(mids_data, action = "long", include = FALSE)$log.Urea)), "-", exp(max(complete(mids_data, action = "long", include = FALSE)$log.Urea)),"])")
summary_table_creatinine <- complete(mids_data, "long") %>%
as_tibble() %>%
select(S01Gender, log.Creatinine, POMS.overall, LengthOfStay) %>%
mutate(LengthOfStay == ifelse(LengthOfStay == 999, NA, LengthOfStay)) %>%
mutate(creat_level = ifelse(S01Gender == "M" & log.Creatinine < log(59),
"low",
ifelse(S01Gender == "F" & log.Creatinine < log(45),
"low",
ifelse(S01Gender == "M" & log.Creatinine > log(104),
"high",
ifelse(S01Gender == "F" & log.Creatinine > log(84),
"high",
"normal")))),
n=1) %>%
group_by(creat_level) %>%
summarise(POMS.n = sum(POMS.overall)/10,
n = sum(n)/10,
median.LOS = paste0(median(LengthOfStay, na.rm = TRUE), " - IQR ",
quantile(LengthOfStay, 0.25, na.rm = TRUE), "-",
quantile(LengthOfStay, 0.75, na.rm = TRUE)),
mean.LOS = paste0(round(mean(LengthOfStay, na.rm = TRUE),1), " +/- SD ",
round(SD(LengthOfStay, na.rm = TRUE),1))) %>%
mutate(perc = round(n/sum(n)*100,3),
perc.POMS = round(POMS.n/n*100,3))
summary_creatinine <- summary_Urea <- paste0(exp(median(complete(mids_data, action = "long", include = FALSE)$log.Creatinine)),
" (IQR ", exp(quantile(complete(mids_data, action = "long", include = FALSE)$log.Creatinine, 0.25)), "-", exp(quantile(complete(mids_data, action = "long", include = FALSE)$log.Creatinine, 0.75)), " [range ", exp(min(complete(mids_data, action = "long", include = FALSE)$log.Creatinine)), "-", exp(max(complete(mids_data, action = "long", include = FALSE)$log.Creatinine)),"])")
summary_table_WCC <- summary_variable_POMS_numerical(mids_data, S02WhiteCellCount,
breaks = c(-Inf,3.6,11.0,Inf))
summary_table_WCC
Desc(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount)
summary_WCC <- paste0(round(median(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount),1),
" (IQR ", round(quantile(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount, 0.25),1), "-", round(quantile(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount, 0.75),1), " [range ", round(min(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount),1), "-", round(max(complete(mids_data, action = "long", include = FALSE)$S02WhiteCellCount),1),"])")
summary_table_Albumin<- summary_variable_POMS_numerical(mids_data, S02SerumAlbumin,
breaks = c(-Inf,35,50,Inf))
summary_table_Albumin
summary_table_Hb<- summary_variable_POMS_numerical(mids_data, S02Haemoglobin,
breaks = c(-Inf,9.0,11.0,13.0,Inf))
summary_table_Hb
summary_table_Pulse<- summary_variable_POMS_numerical(mids_data, S02PulseRate,
breaks = c(-Inf,59,79,99,Inf))
summary_table_Pulse
summary_table_BP <- summary_variable_POMS_numerical(mids_data, S02SystolicBP,
breaks = c(-Inf,99,129,159,Inf))
summary_table_BP
summary_table_SpO2 <- summary_variable_POMS_numerical(mids_data, S02SpO2,
breaks = c(-Inf,93.9,Inf))
summary_table_SpO2
summary_table_Resp <- summary_variable_POMS_factor(mids_data, S02RespiratoryHistoryFindings.combined)