generated from opensafely/research-template
/
analysis_wave2_severe.R
1024 lines (888 loc) · 56.1 KB
/
analysis_wave2_severe.R
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
# Import data
os_data <- read.csv('./output/input_w2.csv')
# WAVE 2 DATA
# On local computer, filepath is ~/Documents/GitHub/DISECT_UK_India_COVID/output
# Load Libraries
library(rms)
library(survival)
library(broom)
library(tidyverse)
####################################
# DATA PROCESSING
####################################
# To avoid complications later, may want to replace all empty strings with NA
# Otherwise, many NAs could to unnoticed
os_data[os_data == ""] <- NA
# Filter out bad records (missing sex, age, or IMD)
os_data <- os_data %>% filter(!is.na(sex), !is.na(age), !is.na(imdQ5), !imdQ5 == 'Unknown')
# Create household generational composition
# MUST be done before filtering out adults.
# Kevin Wing defined generations as
# 0-17 year olds, 18-29 year olds, 30-66 year olds and 67+ year olds
# The categorised into single occupant, single gen, 2 gen, 3 gen, or 4 gen household
# First create generation category
os_data <- os_data %>% mutate(gen_cat = case_when(age < 18 ~ "Child",
age >= 18 & age < 30 ~ "Young adult",
age >= 30 & age <67 ~ "Adult",
age >= 67 ~ "Elder",
TRUE ~ "Unknown"))
# Then create generation # for each HH
hh_gens <- os_data %>% group_by(hh_id) %>% dplyr::summarize(
children = I(sum(gen_cat == "Child") > 0),
young_adults = I(sum(gen_cat == "Young adult") > 0),
adults = I(sum(gen_cat == "Adult") > 0),
elders = I(sum(gen_cat == 'Elder') > 0)) %>% rowwise() %>%
mutate(gen_hh = sum(children + young_adults + adults + elders)) %>% select(hh_id, gen_hh)
# And merge this column to the dataset
os_data <- left_join(os_data, hh_gens, by = 'hh_id')
# NOTE: This variable currently does not distinguish between
# multiple people of SAME gen in hh and single occupant hh
# Could transform using info from hh_size?
# Note that we may want to add some flexibility
# e.g. household of just 29 year old and 30 year old is not multigenerational in reality
# Also, household cannot have more generations than members
# E.g. not possible to have 3 generation household if just 2 people live in it
# QUESTION: Do we want to have indicator of something like
# child AND senior in household?
# As one existing hypothesis is that transmission to elderly is FROM schoolchildren
# So a multigen household including 67+ and 0-17 may want to be modeled as distinct from, e.g.,
# 29 year old and 30 year old.
# Final note, may be possible that there are more members of the household
# Who aren't in the original data, or had missing age and were filtered out
# So, potential for measurement error exists. Interpret with caution!
# Filter for adults at baseline
os_data <- os_data %>% filter(age >= 18)
# Filter out those who had the outcome in previous wave
# Note, JUST filters out those who had covid admission before wave start
# Don't think we need to filter out death? Since if they died before wave start
# I don't think they would appear in the new data
os_data <- os_data %>% filter((is.na(covid_admission_date) | as.Date(covid_admission_date) >= "2020-11-01"))
# Correct labels for ethnicity variables
os_data <- os_data %>% mutate(ethnicity = case_when(ethnicity == 1 ~ "White",
ethnicity == 2 ~ "South Asian",
ethnicity == 3 ~ "Black",
ethnicity == 4 ~ "Mixed",
ethnicity == 5 ~ "Other",
is.na(ethnicity) ~ "Unknown",
TRUE ~ "Unknown"),
ethnicity_16 = case_when(ethnicity_16 == 1 ~ "White British",
ethnicity_16 == 2 ~ "White Irish",
ethnicity_16 == 3 ~ "Other White",
ethnicity_16 == 4 ~ "White + Caribbean",
ethnicity_16 == 5 ~ "White + African",
ethnicity_16 == 6 ~ "White + Asian",
ethnicity_16 == 7 ~ "Other mixed",
ethnicity_16 == 8 ~ "Indian",
ethnicity_16 == 9 ~ "Pakistani",
ethnicity_16 == 10 ~ "Bangladeshi",
ethnicity_16 == 11 ~ "Other Asian",
ethnicity_16 == 12 ~ "Caribbean",
ethnicity_16 == 13 ~ "African",
ethnicity_16 == 14 ~ "Other Black",
ethnicity_16 == 15 ~ "Chinese",
ethnicity_16 == 16 ~ "Other",
is.na(ethnicity_16) ~ "Unknown",
TRUE ~ "Unknown"))
# Create categories for vaccination
os_data <- os_data %>% mutate(vax_cat = case_when(is.na(covid_vaccine_1) ~ "No doses",
is.na(covid_vaccine_2) & !is.na(covid_vaccine_1) ~ "One Dose",
is.na(covid_vaccine_3) & !is.na(covid_vaccine_1) & !is.na(covid_vaccine_2) ~ "Two Doses",
!is.na(covid_vaccine_3) & !is.na(covid_vaccine_1) & !is.na(covid_vaccine_2) ~ "3+ Doses",
TRUE ~ "Unknown"))
# Binarise hypertension
os_data$hypertension_flag <- ifelse(!is.na(os_data$hypertension), 1, 0)
os_data$hypertension_flag_char <- ifelse(!is.na(os_data$hypertension), 'Hypertension', 'No hypertension') # For easier tables
# Binarise chronic cardiac disease
os_data$cardiac_flag <- ifelse(!is.na(os_data$chronic_cardiac_disease), 1, 0)
# Binarise chronic kidney disease
os_data$ckd_flag <- ifelse(!is.na(os_data$ckd), 1, 0)
# Binarise diabetes
os_data$diabetes_flag <- ifelse(is.na(os_data$diabetes_type) | os_data$diabetes_type == "NO_DM", 0, 1)
# BP Lowering
os_data$bp_lower <- ifelse(os_data$combination_bp_meds > 0, 1, 0)
# Binarise statin
os_data$statin_flag <- ifelse(!is.na(os_data$statin), 1, 0)
# Ace inhibitors
os_data$ace_flag <- ifelse(os_data$ace_inhibitors > 0, 1, 0)
# Alpha blockers
os_data$alpha_flag <- ifelse(os_data$alpha_blockers > 0, 1, 0)
# Arbs
os_data$arbs_flag <- ifelse(os_data$arbs > 0, 1, 0)
# Beta blockers
os_data$beta_flag <- ifelse(os_data$betablockers > 0, 1, 0)
# Calcium channel blockers
os_data$calc_flag <- ifelse(os_data$calcium_channel_blockers > 0, 1, 0)
# Spironolactone
os_data$spiro_flag <- ifelse(os_data$spironolactone > 0, 1, 0)
# Thiazide diruetics
os_data$thiaz_flag <- ifelse(os_data$thiazide_diuretics > 0, 1, 0)
# Insulin
os_data$insulin_flag <- ifelse(!is.na(os_data$insulin), 1, 0)
# OAD
os_data$oad_flag <- ifelse(os_data$oad_med > 0, 1, 0)
# Binarise obesity (Using WHO cutoff for Asian individuals)
os_data$obese <- ifelse((os_data$ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian") & os_data$bmi >= 27.5) | os_data$bmi >= 30, 'Obese', 'Not obese')
# Binarise Vit D deficiency OR medication
os_data$vit_d <- ifelse(is.na(os_data$vit_d_deficient) & is.na(os_data$vit_d_prescript), 0, 1)
# Create categories for BMI
os_data <- os_data %>% mutate(bmi_cat = case_when(bmi <18.5 ~ "Underweight",
(bmi >= 18.5 & bmi <23 & ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) | (bmi >= 18.5 & bmi < 25 & !ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) ~ "Normal weight",
(bmi >= 23 & bmi <27.5 & ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) | (bmi >= 25 & bmi < 30 & !ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) ~ "Overweight",
(bmi >= 27.5 & ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) | (bmi >= 30 & !ethnicity_16 %in% c("Indian", "Pakistani", "Bangladeshi", "Chinese", "Other Asian")) ~ "Obese",
TRUE ~ "no category"))
# Recall our objectives
# A.To describe the incidence rate of severe COVID-19 (hospitalization, death, and both combined) according to strata of: age group, sex, ethnicity group, NCD group (diabetes, hypertension, obesity), and time period/wave of the pandemic.
# B.To describe the incidence rate of Long COVID according to strata of: age group, sex, ethnicity group, NCD group (diabetes, hypertension, obesity), and time period/wave of the pandemic.
# Time periods of interest are defined as follows:
# 23rd March 2020 to 31st October 2020 (Wave 1),
# 1st November 2020 to 31st March 2021 (wave 2),
# 1st April 2021 to 31st November 2021 (easing restrictions and introduction of widespread vaccination)
# 1st December 2021 to 30th April 2022 (Omicron wave).
# Age reported in 5 year bands for stratification
os_data <- os_data %>% mutate(age_cat = case_when(age < 25 ~ "18-24",
age < 30 & age >= 25 ~ "25-29",
age < 35 & age >= 30 ~ "30-34",
age < 40 & age >= 35 ~ "35-39",
age < 45 & age >= 40 ~ "40-44",
age < 50 & age >= 45 ~ "45-49",
age < 55 & age >= 50 ~ "50-54",
age < 60 & age >= 55 ~ "55-59",
age < 65 & age >= 60 ~ "60-64",
age < 70 & age >= 65 ~ "65-69",
age < 75 & age >= 70 ~ "70-74",
age < 80 & age >= 75 ~ "75-79",
age < 85 & age >= 80 ~ "80-84",
age >= 85 ~ "85+"))
####################################
# CREATE OUTCOME VARIABLES
####################################
# OUTCOME A: Severe Covid
# Two criteria are:
# COVID-19 hospitalization (defined as a COVID-19 ICD-10 code in the primary diagnosis field, ascertained from SUS data)
# COVID-19 related death defined as a COVID-19 ICD-10 code anywhere on the death certificate (ascertained from ONS death certificate data).
# Set deregistration date, death, long covid date, or TPP linkage as outcome - whichever is EARLIEST
# Death date has DAY included, long covid and de-registration do NOT
# Add 15 as date to these
os_data$covid_hosp_date <- as.Date(os_data$covid_admission_date, format = "%Y-%m-%d")
#os_data$covid_death_date <- as.Date(paste(os_data$long_covid_date,"-15",sep=""), format = "%Y-%m-%d")
# covid_death_date variable is binary flag for now, use death date + flag to determine if outcome happened
os_data$dereg_date <- as.Date(paste(os_data$dereg_date,"-15",sep=""), format = "%Y-%m-%d")
os_data$died_date_ons <- as.Date(os_data$died_date_ons, format = "%Y-%m-%d")
# Give everyone an "End of wave" date, to use in calculating the min
os_data$wave_end <- rep(as.Date("2021-03-31", format = "%Y-%m-%d"), nrow(os_data))
# Determine minimum of these dates
os_data <- os_data %>% rowwise() %>%
mutate(severe_covid_outcome_date = as.Date(min(as.numeric(covid_hosp_date), as.numeric(dereg_date), as.numeric(died_date_ons), as.numeric(wave_end), na.rm = TRUE), format = "%Y-%m-%d", origin = "1970-01-01"))
# And create event flag
os_data$severe_covid_flag <- ifelse(!is.na(os_data$covid_hosp_date) | os_data$died_ons_covid_flag_any == 1, 1, 0)
# Generate survival object for Cox analyses
os_data$severe_covid_surv <- survival::Surv(as.numeric(os_data$severe_covid_outcome_date)-rep(as.numeric(as.Date("2020-11-01", format = "%Y-%m-%d")), nrow(os_data)),
os_data$severe_covid_flag)
# For sensitivity, create extra object where only covid death is outcome (not hospitalisation)
os_data <- os_data %>% rowwise() %>%
mutate(death_covid_outcome_date = as.Date(min(as.numeric(dereg_date), as.numeric(died_date_ons), as.numeric(wave_end), na.rm = TRUE), format = "%Y-%m-%d", origin = "1970-01-01"))
os_data$death_covid_flag <- ifelse(!is.na(os_data$died_date_ons) & os_data$died_date_ons < as.Date('2021-04-01', format = '%Y-%m-%d'), 1, 0)
os_data$death_covid_surv <- survival::Surv(as.numeric(os_data$death_covid_outcome_date)-rep(as.numeric(as.Date("2020-11-01", format = "%Y-%m-%d")), nrow(os_data)),
os_data$death_covid_flag)
####################################
# SUMMARY TABLES
####################################
# TABLE 1s
# We will describe the proportion of individuals within each ethnicity category and outcome category, and their baseline covariate status at the start of each study period
# Table 1a - Columns = ethnicity (5)
table1a <- os_data %>% group_by(ethnicity) %>%
dplyr::summarize(N = n(),
mean_age = mean(age),
sd_age = sd(age),
male = sum(sex == 'M', na.rm = TRUE),
male_p = sum(sex == 'M', na.rm = TRUE)/n(),
female = sum(sex == 'F', na.rm = TRUE),
female_p = sum(sex == 'F', na.rm = TRUE)/n(),
mean_bmi = mean(bmi, na.rm = TRUE),
sd_bmi = sd(bmi, na.rm = TRUE),
underweight = sum(bmi_cat == "Underweight", na.rm = TRUE),
underweight_p = sum(bmi_cat == "Underweight", na.rm = TRUE)/n(),
normalweight = sum(bmi_cat == "Normal weight", na.rm = TRUE),
normalweight_p = sum(bmi_cat == "Normal weight", na.rm = TRUE)/n(),
overweight = sum(bmi_cat == "Overweight", na.rm = TRUE),
overweight_p = sum(bmi_cat == "Overweight", na.rm = TRUE)/n(),
obese = sum(bmi_cat == "Obese", na.rm = TRUE),
obese_p = sum(bmi_cat == "Obese", na.rm = TRUE)/n(),
# Smoking
current_smoke = sum(smoking_status == 'S', na.rm = TRUE),
current_smoke_p = sum(smoking_status == 'S', na.rm = TRUE)/N,
ever_smoke = sum(smoking_status == 'E', na.rm = TRUE),
ever_smoke_p = sum(smoking_status == 'E', na.rm = TRUE)/N,
non_smoke = sum(smoking_status == 'N', na.rm = TRUE),
non_smoke_p = sum(smoking_status == 'N', na.rm = TRUE)/N,
missing_smoke = sum(smoking_status == 'M' | is.na(smoking_status)),
missing_smoke_p = sum(smoking_status == 'M' | is.na(smoking_status))/N,
# QUESTION - Missing as its own category or combine with non-smoker?
# IMD
imd_1 = sum(imdQ5 == "1 (most deprived)"),
imd_1_p = sum(imdQ5 == "1 (most deprived)")/N,
imd_2 = sum(imdQ5 == "2"),
imd_2_p = sum(imdQ5 == "2")/N,
imd_3 = sum(imdQ5 == "3"),
imd_3_p = sum(imdQ5 == "3")/N,
imd_4 = sum(imdQ5 == "4"),
imd_4_p = sum(imdQ5 == "4")/N,
imd_5 = sum(imdQ5 == "5 (least deprived)"),
imd_5_p = sum(imdQ5 == "5 (least deprived)")/N,
# Geography (STP)
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
# Eligibility for shielding
eligible_shield = sum(shielding == 1, na.rm = TRUE),
eligible_shield = sum(shielding == 1, na.rm = TRUE)/N,
# Co-morbidities: T1DM, T2DM, hypertension, CVD, CKD
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE),
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE)/N,
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE),
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE)/N,
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE),
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE)/N,
hypertens = sum(hypertension_flag == 1),
hypertens_p = sum(hypertension_flag == 1)/N,
chronic_cardiac = sum(cardiac_flag == 1),
chronic_cardiac_p = sum(cardiac_flag == 1)/N,
chronic_kidney = sum(ckd_flag == 1),
chronic_kidney_p = sum(ckd_flag == 1)/N,
# Medications: antidiabetic, BP lowering, lipid lowering
bp_meds = sum(combination_bp_meds > 0, na.rm = TRUE),
bp_meds_p = sum(combination_bp_meds > 0, na.rm = TRUE)/N,
statins = sum(statin_flag == 1),
statins_p = sum(statin_flag == 1)/N,
ace = sum(ace_flag == 1),
ace_p = sum(ace_flag == 1)/N,
alpha = sum(alpha_flag == 1),
alpha_p = sum(alpha_flag == 1)/N,
arbs = sum(arbs_flag == 1),
arbs_p = sum(arbs_flag == 1)/N,
beta = sum(beta_flag == 1),
beta_p = sum(beta_flag == 1)/N,
calcium = sum(calc_flag == 1),
calcium_p = sum(calc_flag == 1)/N,
spiro = sum(spiro_flag == 1),
spiro_p = sum(spiro_flag == 1)/N,
thiaz = sum(thiaz_flag == 1),
thiaz_p = sum(thiaz_flag == 1)/N,
insulin = sum(insulin_flag == 1),
insulin_p = sum(insulin_flag == 1)/N,
oad = sum(oad_flag == 1),
oad_p = sum(oad_flag == 1)/N,
# Date of all previous COVID-19 diagnoses in primary care
# first_positive_test_date variable, not sure how to report in table?
# Date of all COVID-19 vaccinations
# QUESTION: How to describe?
# Currently, provide categorical information on number of doses
no_vax = sum(vax_cat == "No doses", na.rm = TRUE),
no_vax_p = sum(vax_cat == "No doses", na.rm = TRUE)/n(),
one_vax = sum(vax_cat == "One dose", na.rm = TRUE),
one_vax_p = sum(vax_cat == "One dose", na.rm = TRUE)/n(),
two_vax = sum(vax_cat == "Two doses", na.rm = TRUE),
two_vax_p = sum(vax_cat == "Two doses", na.rm = TRUE)/n(),
three_vax = sum(vax_cat == "3+ doses", na.rm = TRUE),
three_vax_p = sum(vax_cat == "3+ doses", na.rm = TRUE)/n(),
# Household composition: Household size (number of people living in a household), generational composition (single generation, two generation, or multi-generation)
hh_size_mean = mean(hh_size, na.rm = TRUE),
hh_size_sd = sd(hh_size, na.rm = TRUE),
# Generational composition
hh_1gen = sum(gen_hh == 1, na.rm = TRUE),
hh_1gen_p = sum(gen_hh == 1, na.rm = TRUE)/n(),
hh_2gen = sum(gen_hh == 2, na.rm = TRUE),
hh_2gen_p = sum(gen_hh == 2, na.rm = TRUE)/n(),
hh_3gen = sum(gen_hh == 3, na.rm = TRUE),
hh_3gen_p = sum(gen_hh == 3, na.rm = TRUE)/n(),
hh_4gen = sum(gen_hh == 4, na.rm = TRUE),
hh_4gen_p = sum(gen_hh == 4, na.rm = TRUE)/n(),
# Care home residents
care_home = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE),
care_home_p = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE)/N,
# QUESTION: Didn't know what different codes meant, unfortunately, so just aggregated... Can correct as needed
# Vitamin D
vitd = sum(vit_d == 1, na.rm = TRUE),
vitd_p = sum(vit_d == 1, na.rm = TRUE)/n()
# Previous infections
)
# Add Overall column
table1a_overall <- os_data %>% mutate(ethnicity_all = 'Overall') %>%
group_by(ethnicity_all) %>%
dplyr::summarize(N = n(),
mean_age = mean(age),
sd_age = sd(age),
male = sum(sex == 'M', na.rm = TRUE),
male_p = sum(sex == 'M', na.rm = TRUE)/n(),
female = sum(sex == 'F', na.rm = TRUE),
female_p = sum(sex == 'F', na.rm = TRUE)/n(),
mean_bmi = mean(bmi, na.rm = TRUE),
sd_bmi = sd(bmi, na.rm = TRUE),
underweight = sum(bmi_cat == "Underweight", na.rm = TRUE),
underweight_p = sum(bmi_cat == "Underweight", na.rm = TRUE)/n(),
normalweight = sum(bmi_cat == "Normal weight", na.rm = TRUE),
normalweight_p = sum(bmi_cat == "Normal weight", na.rm = TRUE)/n(),
overweight = sum(bmi_cat == "Overweight", na.rm = TRUE),
overweight_p = sum(bmi_cat == "Overweight", na.rm = TRUE)/n(),
obese = sum(bmi_cat == "Obese", na.rm = TRUE),
obese_p = sum(bmi_cat == "Obese", na.rm = TRUE)/n(),
# Smoking
current_smoke = sum(smoking_status == 'S', na.rm = TRUE),
current_smoke_p = sum(smoking_status == 'S', na.rm = TRUE)/N,
ever_smoke = sum(smoking_status == 'E', na.rm = TRUE),
ever_smoke_p = sum(smoking_status == 'E', na.rm = TRUE)/N,
non_smoke = sum(smoking_status == 'N', na.rm = TRUE),
non_smoke_p = sum(smoking_status == 'N', na.rm = TRUE)/N,
missing_smoke = sum(smoking_status == 'M' | is.na(smoking_status)),
missing_smoke_p = sum(smoking_status == 'M' | is.na(smoking_status))/N,
# QUESTION - Missing as its own category or combine with non-smoker?
# IMD
imd_1 = sum(imdQ5 == "1 (most deprived)"),
imd_1_p = sum(imdQ5 == "1 (most deprived)")/N,
imd_2 = sum(imdQ5 == "2"),
imd_2_p = sum(imdQ5 == "2")/N,
imd_3 = sum(imdQ5 == "3"),
imd_3_p = sum(imdQ5 == "3")/N,
imd_4 = sum(imdQ5 == "4"),
imd_4_p = sum(imdQ5 == "4")/N,
imd_5 = sum(imdQ5 == "5 (least deprived)"),
imd_5_p = sum(imdQ5 == "5 (least deprived)")/N,
# Geography (STP)
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
# Eligibility for shielding
eligible_shield = sum(shielding == 1, na.rm = TRUE),
eligible_shield = sum(shielding == 1, na.rm = TRUE)/N,
# Co-morbidities: T1DM, T2DM, hypertension, CVD, CKD
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE),
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE)/N,
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE),
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE)/N,
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE),
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE)/N,
hypertens = sum(hypertension_flag == 1),
hypertens_p = sum(hypertension_flag == 1)/N,
chronic_cardiac = sum(cardiac_flag == 1),
chronic_cardiac_p = sum(cardiac_flag == 1)/N,
chronic_kidney = sum(ckd_flag == 1),
chronic_kidney_p = sum(ckd_flag == 1)/N,
# Medications: antidiabetic, BP lowering, lipid lowering
bp_meds = sum(combination_bp_meds > 0, na.rm = TRUE),
bp_meds_p = sum(combination_bp_meds > 0, na.rm = TRUE)/N,
statins = sum(statin_flag == 1),
statins_p = sum(statin_flag == 1)/N,
ace = sum(ace_flag == 1),
ace_p = sum(ace_flag == 1)/N,
alpha = sum(alpha_flag == 1),
alpha_p = sum(alpha_flag == 1)/N,
arbs = sum(arbs_flag == 1),
arbs_p = sum(arbs_flag == 1)/N,
beta = sum(beta_flag == 1),
beta_p = sum(beta_flag == 1)/N,
calcium = sum(calc_flag == 1),
calcium_p = sum(calc_flag == 1)/N,
spiro = sum(spiro_flag == 1),
spiro_p = sum(spiro_flag == 1)/N,
thiaz = sum(thiaz_flag == 1),
thiaz_p = sum(thiaz_flag == 1)/N,
insulin = sum(insulin_flag == 1),
insulin_p = sum(insulin_flag == 1)/N,
oad = sum(oad_flag == 1),
oad_p = sum(oad_flag == 1)/N,
# Date of all previous COVID-19 diagnoses in primary care
# first_positive_test_date variable, not sure how to report in table?
# Date of all COVID-19 vaccinations
# QUESTION: How to describe?
# Currently, provide categorical information on number of doses
no_vax = sum(vax_cat == "No doses", na.rm = TRUE),
no_vax_p = sum(vax_cat == "No doses", na.rm = TRUE)/n(),
one_vax = sum(vax_cat == "One dose", na.rm = TRUE),
one_vax_p = sum(vax_cat == "One dose", na.rm = TRUE)/n(),
two_vax = sum(vax_cat == "Two doses", na.rm = TRUE),
two_vax_p = sum(vax_cat == "Two doses", na.rm = TRUE)/n(),
three_vax = sum(vax_cat == "3+ doses", na.rm = TRUE),
three_vax_p = sum(vax_cat == "3+ doses", na.rm = TRUE)/n(),
# Household composition: Household size (number of people living in a household), generational composition (single generation, two generation, or multi-generation)
hh_size_mean = mean(hh_size, na.rm = TRUE),
hh_size_sd = sd(hh_size, na.rm = TRUE),
# Generational composition
hh_1gen = sum(gen_hh == 1, na.rm = TRUE),
hh_1gen_p = sum(gen_hh == 1, na.rm = TRUE)/n(),
hh_2gen = sum(gen_hh == 2, na.rm = TRUE),
hh_2gen_p = sum(gen_hh == 2, na.rm = TRUE)/n(),
hh_3gen = sum(gen_hh == 3, na.rm = TRUE),
hh_3gen_p = sum(gen_hh == 3, na.rm = TRUE)/n(),
hh_4gen = sum(gen_hh == 4, na.rm = TRUE),
hh_4gen_p = sum(gen_hh == 4, na.rm = TRUE)/n(),
# Care home residents
care_home = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE),
care_home_p = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE)/N,
# QUESTION: Didn't know what different codes meant, unfortunately, so just aggregated... Can correct as needed
# Vitamin D
vitd = sum(vit_d == 1, na.rm = TRUE),
vitd_p = sum(vit_d == 1, na.rm = TRUE)/n()
# Previous infections
)
# Modify column name so tables will join properly
colnames(table1a_overall)[1] <- 'ethnicity'
# Paste together with rbind
table1a <- rbind(table1a, table1a_overall)
# Note, probably should also round the decimals. Otherwise, very difficult to read.
# QUESTION: Remove care home residents at which step?
# Table 1b - Columns = ethnicity (16)
# Replicate code for 1a once complete
table1b <- os_data %>% group_by(ethnicity_16) %>%
dplyr::summarize(N = n(),
mean_age = mean(age),
sd_age = sd(age),
male = sum(sex == 'M', na.rm = TRUE),
male_p = sum(sex == 'M', na.rm = TRUE)/n(),
female = sum(sex == 'F', na.rm = TRUE),
female_p = sum(sex == 'F', na.rm = TRUE)/n(),
mean_bmi = mean(bmi, na.rm = TRUE),
sd_bmi = sd(bmi, na.rm = TRUE),
underweight = sum(bmi_cat == "Underweight", na.rm = TRUE),
underweight_p = sum(bmi_cat == "Underweight", na.rm = TRUE)/n(),
normalweight = sum(bmi_cat == "Normal weight", na.rm = TRUE),
normalweight_p = sum(bmi_cat == "Normal weight", na.rm = TRUE)/n(),
overweight = sum(bmi_cat == "Overweight", na.rm = TRUE),
overweight_p = sum(bmi_cat == "Overweight", na.rm = TRUE)/n(),
obese = sum(bmi_cat == "Obese", na.rm = TRUE),
obese_p = sum(bmi_cat == "Obese", na.rm = TRUE)/n(),
# Smoking
current_smoke = sum(smoking_status == 'S', na.rm = TRUE),
current_smoke_p = sum(smoking_status == 'S', na.rm = TRUE)/N,
ever_smoke = sum(smoking_status == 'E', na.rm = TRUE),
ever_smoke_p = sum(smoking_status == 'E', na.rm = TRUE)/N,
non_smoke = sum(smoking_status == 'N', na.rm = TRUE),
non_smoke_p = sum(smoking_status == 'N', na.rm = TRUE)/N,
missing_smoke = sum(smoking_status == 'M' | is.na(smoking_status)),
missing_smoke_p = sum(smoking_status == 'M' | is.na(smoking_status))/N,
# QUESTION - Missing as its own category or combine with non-smoker?
# IMD
imd_1 = sum(imdQ5 == "1 (most deprived)"),
imd_1_p = sum(imdQ5 == "1 (most deprived)")/N,
imd_2 = sum(imdQ5 == "2"),
imd_2_p = sum(imdQ5 == "2")/N,
imd_3 = sum(imdQ5 == "3"),
imd_3_p = sum(imdQ5 == "3")/N,
imd_4 = sum(imdQ5 == "4"),
imd_4_p = sum(imdQ5 == "4")/N,
imd_5 = sum(imdQ5 == "5 (least deprived)"),
imd_5_p = sum(imdQ5 == "5 (least deprived)")/N,
# Geography (STP)
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
# Eligibility for shielding
eligible_shield = sum(shielding == 1, na.rm = TRUE),
eligible_shield = sum(shielding == 1, na.rm = TRUE)/N,
# Co-morbidities: T1DM, T2DM, hypertension, CVD, CKD
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE),
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE)/N,
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE),
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE)/N,
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE),
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE)/N,
hypertens = sum(hypertension_flag == 1),
hypertens_p = sum(hypertension_flag == 1)/N,
chronic_cardiac = sum(cardiac_flag == 1),
chronic_cardiac_p = sum(cardiac_flag == 1)/N,
chronic_kidney = sum(ckd_flag == 1),
chronic_kidney_p = sum(ckd_flag == 1)/N,
# Medications: antidiabetic, BP lowering, lipid lowering
bp_meds = sum(combination_bp_meds > 0, na.rm = TRUE),
bp_meds_p = sum(combination_bp_meds > 0, na.rm = TRUE)/N,
statins = sum(statin_flag == 1),
statins_p = sum(statin_flag == 1)/N,
ace = sum(ace_flag == 1),
ace_p = sum(ace_flag == 1)/N,
alpha = sum(alpha_flag == 1),
alpha_p = sum(alpha_flag == 1)/N,
arbs = sum(arbs_flag == 1),
arbs_p = sum(arbs_flag == 1)/N,
beta = sum(beta_flag == 1),
beta_p = sum(beta_flag == 1)/N,
calcium = sum(calc_flag == 1),
calcium_p = sum(calc_flag == 1)/N,
spiro = sum(spiro_flag == 1),
spiro_p = sum(spiro_flag == 1)/N,
thiaz = sum(thiaz_flag == 1),
thiaz_p = sum(thiaz_flag == 1)/N,
insulin = sum(insulin_flag == 1),
insulin_p = sum(insulin_flag == 1)/N,
oad = sum(oad_flag == 1),
oad_p = sum(oad_flag == 1)/N,
# Date of all previous COVID-19 diagnoses in primary care
# first_positive_test_date variable, not sure how to report in table?
# Date of all COVID-19 vaccinations
# QUESTION: How to describe?
# Currently, provide categorical information on number of doses
no_vax = sum(vax_cat == "No doses", na.rm = TRUE),
no_vax_p = sum(vax_cat == "No doses", na.rm = TRUE)/n(),
one_vax = sum(vax_cat == "One dose", na.rm = TRUE),
one_vax_p = sum(vax_cat == "One dose", na.rm = TRUE)/n(),
two_vax = sum(vax_cat == "Two doses", na.rm = TRUE),
two_vax_p = sum(vax_cat == "Two doses", na.rm = TRUE)/n(),
three_vax = sum(vax_cat == "3+ doses", na.rm = TRUE),
three_vax_p = sum(vax_cat == "3+ doses", na.rm = TRUE)/n(),
# Household composition: Household size (number of people living in a household), generational composition (single generation, two generation, or multi-generation)
hh_size_mean = mean(hh_size, na.rm = TRUE),
hh_size_sd = sd(hh_size, na.rm = TRUE),
# Generational composition
hh_1gen = sum(gen_hh == 1, na.rm = TRUE),
hh_1gen_p = sum(gen_hh == 1, na.rm = TRUE)/n(),
hh_2gen = sum(gen_hh == 2, na.rm = TRUE),
hh_2gen_p = sum(gen_hh == 2, na.rm = TRUE)/n(),
hh_3gen = sum(gen_hh == 3, na.rm = TRUE),
hh_3gen_p = sum(gen_hh == 3, na.rm = TRUE)/n(),
hh_4gen = sum(gen_hh == 4, na.rm = TRUE),
hh_4gen_p = sum(gen_hh == 4, na.rm = TRUE)/n(),
# Care home residents
care_home = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE),
care_home_p = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE)/N,
# QUESTION: Didn't know what different codes meant, unfortunately, so just aggregated... Can correct as needed
# Vitamin D
vitd = sum(vit_d == 1, na.rm = TRUE),
vitd_p = sum(vit_d == 1, na.rm = TRUE)/n()
# Previous infections
)
# Add overall column
table1b_overall <- os_data %>% mutate(ethnicity_16_all = 'All') %>%
group_by(ethnicity_16_all) %>%
dplyr::summarize(N = n(),
mean_age = mean(age),
sd_age = sd(age),
male = sum(sex == 'M', na.rm = TRUE),
male_p = sum(sex == 'M', na.rm = TRUE)/n(),
female = sum(sex == 'F', na.rm = TRUE),
female_p = sum(sex == 'F', na.rm = TRUE)/n(),
mean_bmi = mean(bmi, na.rm = TRUE),
sd_bmi = sd(bmi, na.rm = TRUE),
underweight = sum(bmi_cat == "Underweight", na.rm = TRUE),
underweight_p = sum(bmi_cat == "Underweight", na.rm = TRUE)/n(),
normalweight = sum(bmi_cat == "Normal weight", na.rm = TRUE),
normalweight_p = sum(bmi_cat == "Normal weight", na.rm = TRUE)/n(),
overweight = sum(bmi_cat == "Overweight", na.rm = TRUE),
overweight_p = sum(bmi_cat == "Overweight", na.rm = TRUE)/n(),
obese = sum(bmi_cat == "Obese", na.rm = TRUE),
obese_p = sum(bmi_cat == "Obese", na.rm = TRUE)/n(),
# Smoking
current_smoke = sum(smoking_status == 'S', na.rm = TRUE),
current_smoke_p = sum(smoking_status == 'S', na.rm = TRUE)/N,
ever_smoke = sum(smoking_status == 'E', na.rm = TRUE),
ever_smoke_p = sum(smoking_status == 'E', na.rm = TRUE)/N,
non_smoke = sum(smoking_status == 'N', na.rm = TRUE),
non_smoke_p = sum(smoking_status == 'N', na.rm = TRUE)/N,
missing_smoke = sum(smoking_status == 'M' | is.na(smoking_status)),
missing_smoke_p = sum(smoking_status == 'M' | is.na(smoking_status))/N,
# QUESTION - Missing as its own category or combine with non-smoker?
# IMD
imd_1 = sum(imdQ5 == "1 (most deprived)"),
imd_1_p = sum(imdQ5 == "1 (most deprived)")/N,
imd_2 = sum(imdQ5 == "2"),
imd_2_p = sum(imdQ5 == "2")/N,
imd_3 = sum(imdQ5 == "3"),
imd_3_p = sum(imdQ5 == "3")/N,
imd_4 = sum(imdQ5 == "4"),
imd_4_p = sum(imdQ5 == "4")/N,
imd_5 = sum(imdQ5 == "5 (least deprived)"),
imd_5_p = sum(imdQ5 == "5 (least deprived)")/N,
# Geography (STP)
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
stp_1 = sum(stp == "STP1", na.rm = TRUE),
stp_1_p = sum(stp == "STP1", na.rm = TRUE)/n(),
stp_2 = sum(stp == "STP2", na.rm = TRUE),
stp_2_p = sum(stp == "STP2", na.rm = TRUE)/n(),
stp_3 = sum(stp == "STP3", na.rm = TRUE),
stp_3_p = sum(stp == "STP3", na.rm = TRUE)/n(),
stp_4 = sum(stp == "STP4", na.rm = TRUE),
stp_4_p = sum(stp == "STP4", na.rm = TRUE)/n(),
stp_5 = sum(stp == "STP5", na.rm = TRUE),
stp_5_p = sum(stp == "STP5", na.rm = TRUE)/n(),
# Eligibility for shielding
eligible_shield = sum(shielding == 1, na.rm = TRUE),
eligible_shield = sum(shielding == 1, na.rm = TRUE)/N,
# Co-morbidities: T1DM, T2DM, hypertension, CVD, CKD
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE),
t1dm = sum(diabetes_type == 'T1DM', na.rm = TRUE)/N,
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE),
t2dm = sum(diabetes_type == 'T2DM', na.rm = TRUE)/N,
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE),
dm_unknown = sum(diabetes_type == 'UNKNOWN_DM', na.rm = TRUE)/N,
hypertens = sum(hypertension_flag == 1),
hypertens_p = sum(hypertension_flag == 1)/N,
chronic_cardiac = sum(cardiac_flag == 1),
chronic_cardiac_p = sum(cardiac_flag == 1)/N,
chronic_kidney = sum(ckd_flag == 1),
chronic_kidney_p = sum(ckd_flag == 1)/N,
# Medications: antidiabetic, BP lowering, lipid lowering
bp_meds = sum(combination_bp_meds > 0, na.rm = TRUE),
bp_meds_p = sum(combination_bp_meds > 0, na.rm = TRUE)/N,
statins = sum(statin_flag == 1),
statins_p = sum(statin_flag == 1)/N,
ace = sum(ace_flag == 1),
ace_p = sum(ace_flag == 1)/N,
alpha = sum(alpha_flag == 1),
alpha_p = sum(alpha_flag == 1)/N,
arbs = sum(arbs_flag == 1),
arbs_p = sum(arbs_flag == 1)/N,
beta = sum(beta_flag == 1),
beta_p = sum(beta_flag == 1)/N,
calcium = sum(calc_flag == 1),
calcium_p = sum(calc_flag == 1)/N,
spiro = sum(spiro_flag == 1),
spiro_p = sum(spiro_flag == 1)/N,
thiaz = sum(thiaz_flag == 1),
thiaz_p = sum(thiaz_flag == 1)/N,
insulin = sum(insulin_flag == 1),
insulin_p = sum(insulin_flag == 1)/N,
oad = sum(oad_flag == 1),
oad_p = sum(oad_flag == 1)/N,
# Date of all previous COVID-19 diagnoses in primary care
# first_positive_test_date variable, not sure how to report in table?
# Date of all COVID-19 vaccinations
# QUESTION: How to describe?
# Currently, provide categorical information on number of doses
no_vax = sum(vax_cat == "No doses", na.rm = TRUE),
no_vax_p = sum(vax_cat == "No doses", na.rm = TRUE)/n(),
one_vax = sum(vax_cat == "One dose", na.rm = TRUE),
one_vax_p = sum(vax_cat == "One dose", na.rm = TRUE)/n(),
two_vax = sum(vax_cat == "Two doses", na.rm = TRUE),
two_vax_p = sum(vax_cat == "Two doses", na.rm = TRUE)/n(),
three_vax = sum(vax_cat == "3+ doses", na.rm = TRUE),
three_vax_p = sum(vax_cat == "3+ doses", na.rm = TRUE)/n(),
# Household composition: Household size (number of people living in a household), generational composition (single generation, two generation, or multi-generation)
hh_size_mean = mean(hh_size, na.rm = TRUE),
hh_size_sd = sd(hh_size, na.rm = TRUE),
# Generational composition
hh_1gen = sum(gen_hh == 1, na.rm = TRUE),
hh_1gen_p = sum(gen_hh == 1, na.rm = TRUE)/n(),
hh_2gen = sum(gen_hh == 2, na.rm = TRUE),
hh_2gen_p = sum(gen_hh == 2, na.rm = TRUE)/n(),
hh_3gen = sum(gen_hh == 3, na.rm = TRUE),
hh_3gen_p = sum(gen_hh == 3, na.rm = TRUE)/n(),
hh_4gen = sum(gen_hh == 4, na.rm = TRUE),
hh_4gen_p = sum(gen_hh == 4, na.rm = TRUE)/n(),
# Care home residents
care_home = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE),
care_home_p = sum(care_home_type %in% c('PC', 'PN', 'PS'), na.rm = TRUE)/N,
# QUESTION: Didn't know what different codes meant, unfortunately, so just aggregated... Can correct as needed
# Vitamin D
vitd = sum(vit_d == 1, na.rm = TRUE),
vitd_p = sum(vit_d == 1, na.rm = TRUE)/n()
# Previous infections
)
# Modify column name so tables will join properly
colnames(table1b_overall)[1] <- 'ethnicity_16'
# Paste together with rbind
table1b <- rbind(table1b, table1b_overall)
# Table 1c - Columns = outcomes?
# Create summary table with denominators (number of participants or person-days?) and number of events
# For now, maybe can have BOTH?
outcome_summary_overall <- os_data %>% mutate(Category = 'All') %>% group_by(Category) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_ethnicity <- os_data %>% group_by(ethnicity) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_ethnicity_16 <- os_data %>% group_by(ethnicity_16) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
# Also for age strata, sex, comorbidities (diabetes, hypertension, obesity),
outcome_summary_age <- os_data %>% group_by(age_cat) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_sex <- os_data %>% group_by(sex) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_diabetes <- os_data %>% group_by(diabetes_type) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_hypertension <- os_data %>% group_by(hypertension_flag_char) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
outcome_summary_obese <- os_data %>% group_by(obese) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death
)
# Combine all into single table
# Need to give first column a generic name, like "Category" first
colnames(outcome_summary_ethnicity)[1] <- "Category"
colnames(outcome_summary_ethnicity_16)[1] <- "Category"
colnames(outcome_summary_age)[1] <- "Category"
colnames(outcome_summary_sex)[1] <- "Category"
colnames(outcome_summary_diabetes)[1] <- "Category"
colnames(outcome_summary_hypertension)[1] <- "Category"
colnames(outcome_summary_obese)[1] <- "Category"
table1c <- rbind(outcome_summary_overall, outcome_summary_ethnicity, outcome_summary_ethnicity_16, outcome_summary_age, outcome_summary_sex, outcome_summary_diabetes, outcome_summary_hypertension, outcome_summary_obese)
# Table 1d - Multiple Stratification of outcomes
# Groups are ethnicity/age/sex/diabetes/htn
table1d <- os_data %>% group_by(ethnicity, age_cat, sex, diabetes_flag, hypertension_flag) %>%
dplyr::summarize(N = n(),
person_days_severe = sum(severe_covid_surv[,1]),
cases_severe = sum(severe_covid_surv[,2]),
ir_severe = 1000*cases_severe/person_days_severe,
person_days_death = sum(death_covid_surv[,1]),
cases_death = sum(death_covid_surv[,2]),
ir_death = 1000*cases_death/person_days_death) %>%
ungroup() %>%
complete(ethnicity, age_cat, sex, diabetes_flag, hypertension_flag, fill = list(N = 0))
# Censor any sparse rows
# Saved as separate copy
table1d_cens <- table1d
table1d_cens$N <- as.character(table1d_cens$N)
table1d_cens$N <- ifelse(as.numeric(table1d_cens$N) <= 5, '<5', table1d_cens$N)
####################################
# ANALYSES - OUTCOME A - SEVERE COVID
####################################
# Unadjusted ratios, reported within each strata
# generate absolute rates of each outcome stratified by age, sex, ethnicity, and co-morbidity status
# "NCD group (diabetes, hypertension, obesity), and time period/wave of the pandemic."
# First, set reference ethnicities, ages, and co-morbid
os_data$ethnicity <- relevel(factor(os_data$ethnicity), ref = "White")
os_data$ethnicity_16 <- relevel(factor(os_data$ethnicity_16), ref = "White British")
# Ethnicity
severe_eth_un <- tidy(coxph(severe_covid_surv ~ as.factor(ethnicity), data = os_data), conf.int = TRUE)
# Ethnicity 16
severe_eth_16_un <- tidy(coxph(severe_covid_surv ~ as.factor(ethnicity_16), data = os_data), conf.int = TRUE)
# Age categories
severe_age_un <- tidy(coxph(severe_covid_surv ~ age_cat, data = os_data), conf.int = TRUE)
# Sex
severe_sex_un <- tidy(coxph(severe_covid_surv ~ sex, data = os_data), conf.int = TRUE)
# BMI Categories
severe_bmi_un <- tidy(coxph(severe_covid_surv ~ bmi_cat, data = os_data), conf.int = TRUE)
# Co-morbidity (diabetes, hypertension, obesity)
# How to code this? Since some people will have more than 1 of each...
# 3 separate models?
# Diabetes
severe_diab_un <- tidy(coxph(severe_covid_surv ~ diabetes_type, data = os_data), conf.int = TRUE)
# Hypertension
severe_htn_un <- tidy(coxph(severe_covid_surv ~ hypertension_flag_char, data = os_data), conf.int = TRUE)
# Obesity
severe_obese_un <- tidy(coxph(severe_covid_surv ~ obese, data = os_data), conf.int = TRUE)