-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMeta-Analysis-Cox-PH-Sensitivity-Analysis.Rmd
732 lines (614 loc) · 26.9 KB
/
Meta-Analysis-Cox-PH-Sensitivity-Analysis.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
---
title: "Meta-Analysis: Cox-PH Sensitivity Analysis"
author: "Meg Hutch"
date: "2022-12-06"
output: html_document
---
This notebook evaluates the performance of Cox proportional hazard models constructed using three censor cutoff periods (30, 60, and 90 days) and three methods of adjusting for pre-admission health conditions (i.e., pre-existing comorbidity burden): (1) the inclusion of the 29 individual covariates (i.e., health conditions) comprising the Elixhauser Comorbidity Index, (2) the Elixhauser summary score, and (3) the top 10 principal components computed from logistic principal component analysis (LPCA).
We also perform additional meta-analyses in order to evaluate the estimates of the individual covariates (e.g., age, comoridities, etc) on each outcome.
Of note, this analysis is performed only on adult patients due to the pediatric cohort's low incidence of both poor health outcomes and neurological diagnoses during COVID-19 hospitalization.
```{r message=FALSE, warning=FALSE}
library(tidyverse)
library(metafor)
library(meta)
library(cowplot)
library(DT)
library(ggbreak)
library(RColorBrewer)
library(viridis)
devtools::install_github("rdboyes/forester")
devtools::install_github("thomasp85/patchwork")
source("R/forester_custom.R")
source("R/analyze_survival.R")
```
# Import Data from each Healthcare system
```{r message=FALSE, warning=FALSE}
# read in files from results folder
# this folder contains all of the local healthcare system level analyses
rdas <- list.files(
path = "results",
pattern = ".rda",
full.names = TRUE
)
for (rda in rdas) {
load(rda)
}
rm(rdas, rda)
# create a list of participating healthcare systems from our study tracking spreadsheet
site_google_url <- "https://docs.google.com/spreadsheets/d/1epcYNd_0jCUMktOHf8mz5v651zy1JALD6PgzobrGWDY/edit?usp=sharing"
# load site parameters
site_params <- googlesheets4::read_sheet(site_google_url, sheet = 1)
site_avails <- googlesheets4::read_sheet(site_google_url, sheet = 2)
# filter the list of sites who ran the analysis
sorted_sites <- site_avails %>%
filter(!is.na(date_v4_received)) %>%
pull(siteid) %>%
paste("results", sep = "_")
# list sites without race
sites_wo_race <- site_params %>%
filter(!include_race) %>%
pull(siteid)
# combine all rda files with 'results' in name
results <- mget(ls(pattern = "results"))
## read in pt counts
pt_counts_df <- read.csv('tables/site_pt_counts.csv')
```
## Identify sites to include in the analysis
We will only include a site if they have \>= 3 neuro patients
```{r}
sites_adult <- pt_counts_df %>%
filter(population == "Adult") %>%
mutate(neuro_sum = n_var_Central + n_var_Peripheral) %>%
filter(!neuro_sum < 3) %>%
distinct(site) %>%
mutate(site = gsub("_results", "", site))
sites_adult_results <- sites_adult %>% mutate(site = paste0(site, "_results")) %>% as.vector()
adult_results <- results[grepl(paste(sites_adult_results$site, collapse = "|"), names(results))]
```
## Define parameters
```{r}
outcomes <- c("time_first_discharge_reg_elix", "deceased_reg_elix")
comorb_adj <- c("lpca", "score", "ind")
censor_cut <- c("30", "60", "90")
```
## Get Cox model results - Adults
```{r}
cox_results_adults <- list()
for (outcome_i in outcomes) {
for (comorb_adj_i in comorb_adj) {
for (censor_cut_i in censor_cut) {
cox_results_adults[[outcome_i]][[comorb_adj_i]][[censor_cut_i]] <-
adult_results %>%
lapply(get_cox_row, population = "adults", comorb_method = comorb_adj_i, censor_cutoff = censor_cut_i, outcome = outcome_i) %>%
bind_rows() %>%
mutate(outcome = outcome_i,
comorb_method = comorb_adj_i,
censor_cutoff = censor_cut_i)
}
}
}
```
## Evaluate concordance
```{r}
cox_concordance_results_adults <- list()
for (outcome_i in outcomes) {
for (comorb_adj_i in comorb_adj) {
for (censor_cut_i in censor_cut) {
cox_concordance_results_adults[[outcome_i]][[comorb_adj_i]][[censor_cut_i]] <-
adult_results %>%
lapply(get_summary_stats, population = "adults", comorb_method = comorb_adj_i, censor_cutoff = censor_cut_i, outcome = outcome_i, cox_stat = "concordance") %>%
bind_rows()
}
}
}
```
**Bind all concordance results together**
```{r}
bind_results <- function(results_list) {
lpca_discharge <- results_list[["time_first_discharge_reg_elix"]][["lpca"]] %>% bind_rows()
score_discharge <- results_list[["time_first_discharge_reg_elix"]][["score"]] %>% bind_rows()
ind_discharge <- results_list[["time_first_discharge_reg_elix"]][["ind"]] %>% bind_rows()
lpca_mortality <- results_list[["deceased_reg_elix"]][["lpca"]] %>% bind_rows()
score_mortality <- results_list[["deceased_reg_elix"]][["score"]] %>% bind_rows()
ind_mortality <- results_list[["deceased_reg_elix"]][["ind"]] %>% bind_rows()
combined_results <- bind_rows(lpca_discharge, score_discharge, ind_discharge,
lpca_mortality, score_mortality, ind_mortality)
return(combined_results)
}
cox_results <- bind_results(results_list = cox_results_adults)
concordance_results <- bind_results(results_list = cox_concordance_results_adults)
```
### **Concordance**
```{r fig.height=7, fig.width=12}
c_plot <- ggplot(concordance_results %>%
mutate(comorb_method = factor(comorb_method,
levels = c("ind", "score", "lpca")) %>%
fct_recode(
`Individual\nCovariates` = "ind",
`Summary\nScore` = "score",
`LPCA` = "lpca"
),
outcome = as.factor(outcome) %>%
fct_recode(
Mortality = "deceased_reg_elix",
Discharge = "time_first_discharge_reg_elix"),
censor_cutoff = as.factor(censor_cutoff) %>%
fct_recode(
`30 Days` = "30",
`60 Days` = "60",
`90 Days` = "90")),
aes(x = comorb_method, y = C, group = comorb_method, fill = comorb_method)) +
geom_violin(trim = FALSE) +
facet_grid(outcome ~ censor_cutoff, scales = "free") +
scale_y_continuous("Concordance", position="left") +
xlab("") +
theme_bw() +
theme(legend.position = "none") +
scale_fill_brewer(palette="Dark2") +
geom_boxplot(width=0.3, fill="white", outlier.shape=NA) +
geom_jitter(size = 0.4, alpha = 0.5, color = "black") +
theme(strip.text.x = element_text(size = 15, face = "bold"),
strip.text.y = element_text(size = 15, face = "bold"),
axis.title.y = element_text(size = 15, face = "bold"),
axis.text.x = element_text(size = 13, face = "bold", color = "black"),
axis.text.y = element_text(size = 12, face = "bold"))
c_plot
ggsave("figures/Comorbidity_adjustment.png", c_plot, width = 12, height = 7, dpi = 300)
```
```{r}
c_results <- concordance_results %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
summarize(min = min(C),
q1 = quantile(C, 0.25),
median = median(C),
mean = mean(C),
q3 = quantile(C, 0.75),
max = max(C)) %>%
select(outcome, censor_cutoff, comorb_method, median, mean)
write.csv(c_results, "tables/comorbidity_adj_c_results.csv", row.names=FALSE)
# summary stats
datatable(concordance_results %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
summarize(min = min(C),
q1 = quantile(C, 0.25),
median = median(C),
mean = mean(C),
q3 = quantile(C, 0.75),
max = max(C)),
filter="top")
```
## Evaluate comorb_method with highest OR for CNS and PNS
```{r}
# summary stats
datatable(cox_results %>%
filter(variable == "neuro_postCentral" | variable == "neuro_postPeripheral") %>%
group_by(outcome, variable, censor_cutoff, comorb_method) %>%
mutate(exp.coef. = round(exp.coef.)) %>%
summarize(min = min(exp.coef., na.rm = TRUE),
q1 = quantile(exp.coef., 0.25, na.rm = TRUE),
median = median(exp.coef., na.rm = TRUE),
mean = mean(exp.coef. , na.rm = TRUE),
q3 = quantile(exp.coef., 0.75, na.rm = TRUE),
max = max(exp.coef., na.rm = TRUE)),
filter="top")
```
## Random effects meta-analysis - CNS
set `sm = "HR"` when estimate is logHR (which is coef in our model): <https://cran.r-project.org/web/packages/meta/meta.pdf> - (search logHR in cran to see example)
\*Note: We excluded sites with \< 3 neuro patients in a category
```{r message=FALSE, warning=FALSE}
## adults
meta_results_adults_cns <- list()
for (outcome_i in outcomes) {
for (comorb_adj_i in comorb_adj) {
for (censor_cut_i in censor_cut) {
meta_results_adults_cns[[outcome_i]][[comorb_adj_i]][[censor_cut_i]] <-
cox_results %>%
filter(outcome == outcome_i,
comorb_method == comorb_adj_i,
censor_cutoff == censor_cut_i
) %>%
bind_rows() %>%
data.frame() %>%
filter(variable == "neuro_postCentral") %>%
metagen(
TE = coef,
seTE = se.coef.,
data = .,
sm = "HR", # hazard ratios
comb.random = TRUE,
comb.fixed = FALSE,
method.tau = "DL", # default tau method
hakn = FALSE,
prediction = TRUE,
studlab = site
)
}
}
}
```
## Random effects meta-analysis - PNS
```{r message=FALSE, warning=FALSE}
## adults
meta_results_adults_pns <- list()
for (outcome_i in outcomes) {
for (comorb_adj_i in comorb_adj) {
for (censor_cut_i in censor_cut) {
meta_results_adults_pns[[outcome_i]][[comorb_adj_i]][[censor_cut_i]] <-
cox_results %>%
filter(outcome == outcome_i,
comorb_method == comorb_adj_i,
censor_cutoff == censor_cut_i
) %>%
bind_rows() %>%
data.frame() %>%
filter(variable == "neuro_postPeripheral") %>%
metagen(
TE = coef,
seTE = se.coef.,
data = .,
sm = "HR", # hazard ratios
comb.random = TRUE,
comb.fixed = FALSE,
method.tau = "DL", # default tau method
hakn = FALSE,
prediction = TRUE,
studlab = site
)
}
}
}
```
## Format meta results
```{r}
format_meta <- function(meta_results) {
ma_combine <- list()
for (outcome_i in outcomes) {
for (comorb_adj_i in comorb_adj) {
for (censor_cut_i in censor_cut) {
ma_combine[[outcome_i]][[comorb_adj_i]][[censor_cut_i]] <- data.frame(
TE = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["TE"]],
#seTE =meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["seTE"]],
studlab = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["studlab"]],
upper = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper"]],
lower = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower"]],
TE.random = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["TE.random"]],
lower.random = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower.random"]],
upper.random = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper.random"]],
pval.random = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["pval.random"]],
Weight.random = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["w.random"]],
lower.predict = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower.predict"]],
upper.predict = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper.predict"]],
I2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["I2"]],
lower.I2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower.I2"]],
upper.I2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper.I2"]],
H = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["H"]],
lower.H = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower.H"]],
upper.H = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper.H"]],
tau2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["tau2"]],
lower.tau2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["lower.tau2"]],
upper.tau2 = meta_results[[outcome_i]][[comorb_adj_i]][[censor_cut_i]][["upper.tau2"]],
analysis = paste0(outcome_i,"_", comorb_adj_i, "_", censor_cut_i)
) %>%
mutate(outcome = outcome_i,
comorb_method = comorb_adj_i,
censor_cutoff = censor_cut_i) %>%
select(studlab, outcome, comorb_method, censor_cutoff, everything())
}
}
}
return(ma_combine)
}
```
```{r}
meta_results_adults_cns_list = format_meta(meta_results_adults_cns)
meta_results_adults_pns_list = format_meta(meta_results_adults_pns)
```
```{r}
meta_results_cns <- bind_results(results_list = meta_results_adults_cns_list)
meta_results_pns <- bind_results(results_list = meta_results_adults_cns_list)
```
```{r}
meta_results_cns_table <- meta_results_cns %>%
distinct(TE.random, outcome, comorb_method, censor_cutoff) %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
mutate(TE.random = as.numeric(TE.random))
write.csv(meta_results_cns_table, "tables/comorbidity_adj_cns_metanalysis_TE.csv", row.names=FALSE)
# summary stats
datatable(meta_results_cns %>%
distinct(TE.random, outcome, comorb_method, censor_cutoff) %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
mutate(TE.random = as.numeric(TE.random)),
filter="top")
```
```{r}
meta_results_pns_table <- meta_results_pns %>%
distinct(TE.random, outcome, comorb_method, censor_cutoff) %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
mutate(TE.random = as.numeric(TE.random))
write.csv(meta_results_pns_table, "tables/comorbidity_adj_pns_metanalysis_TE.csv", row.names=FALSE)
# summary stats
datatable(meta_results_pns %>%
distinct(TE.random, outcome, comorb_method, censor_cutoff) %>%
group_by(outcome, censor_cutoff, comorb_method) %>%
mutate(TE.random = as.numeric(TE.random)),
filter="top")
```
### **Hazard-Ratio**
```{r fig.height=7, fig.width=12}
pd <- position_dodge(width = 0.6)
meta_results_cns$neuro <- "CNS"
meta_results_pns$neuro <- "PNS"
meta_mortality_results <- rbind(meta_results_cns, meta_results_pns)
meta_comorb_comparison <- ggplot(meta_mortality_results %>%
mutate(comorb_method = factor(comorb_method,
levels = c("lpca", "score", "ind")) %>%
fct_recode(
`LPCA` = "lpca",
`Summary\nScore` = "score",
`Individual\nCovariates` = "ind"
),
outcome = as.factor(outcome) %>%
fct_recode(
Mortality = "deceased_reg_elix",
Discharge = "time_first_discharge_reg_elix"),
censor_cutoff = as.factor(censor_cutoff) %>%
fct_recode(
`30 Days` = "30",
`60 Days` = "60",
`90 Days` = "90"),
TE.random = exp(TE.random),
lower.random = exp(lower.random),
upper.random = exp(upper.random)) %>%
rename(`Days since admission` = "censor_cutoff") %>%
distinct(TE.random, lower.random, upper.random, outcome, comorb_method, `Days since admission`, neuro),
aes(x=TE.random, y=comorb_method, colour=`Days since admission`, group=`Days since admission`)) +
scale_color_viridis(discrete=TRUE, direction = 1) +
geom_point(aes(x=TE.random), shape=15, size=3, position = pd) +
geom_linerange(aes(xmin=lower.random, xmax=upper.random), position = pd) +
labs(x = "Hazard Ratio", y = "") +
geom_vline(xintercept = 1, linetype="dashed") +
facet_grid(outcome ~ neuro) +
theme_bw() +
theme(strip.text.x = element_text(size = 15, face = "bold"),
strip.text.y = element_text(size = 15, face = "bold"),
axis.title.x = element_text(size = 15, face = "bold"),
axis.text.x = element_text(size = 13, face = "bold", color = "black"),
axis.text.y = element_text(size = 12, face = "bold"),
legend.title = element_text(size = 15, face = "bold"),
legend.text = element_text(size = 13, face = "bold"))
meta_comorb_comparison
ggsave("figures/Comorbidity_adjustment_HR.png", meta_comorb_comparison, width = 12, height = 7, dpi = 300)
```
## Evaluate individual covariates
```{r message=FALSE, warning=FALSE}
variables <- cox_results %>%
filter(comorb_method == "ind") %>%
distinct(variable)
variables <- unique(variables$variable)
meta_results_all <- list()
for(variable_i in variables) {
for (outcome_i in outcomes) {
meta_results_all[[outcome_i]][[variable_i]] <-
cox_results %>%
filter(outcome == outcome_i,
comorb_method == "ind",
censor_cutoff == "90",
variable == variable_i) %>%
bind_rows() %>%
data.frame() %>%
metagen(
TE = coef,
seTE = se.coef.,
data = .,
sm = "HR", # hazard ratios
comb.random = TRUE,
comb.fixed = FALSE,
method.tau = "DL", # default tau method
hakn = FALSE,
prediction = TRUE,
studlab = site
)
}
}
```
```{r}
format_meta_ind <- function(meta_results) {
ma_ind_combine <- list()
for(variable_i in variables) {
for (outcome_i in outcomes) {
ma_ind_combine[[outcome_i]][[variable_i]] <- data.frame(
TE = meta_results[[outcome_i]][[variable_i]][["TE"]],
#seTE =meta_results[[outcome_i]][[variable_i]][["seTE"]],
studlab = meta_results[[outcome_i]][[variable_i]][["studlab"]],
upper = meta_results[[outcome_i]][[variable_i]][["upper"]],
lower = meta_results[[outcome_i]][[variable_i]][["lower"]],
TE.random = meta_results[[outcome_i]][[variable_i]][["TE.random"]],
lower.random = meta_results[[outcome_i]][[variable_i]][["lower.random"]],
upper.random = meta_results[[outcome_i]][[variable_i]][["upper.random"]],
pval.random = meta_results[[outcome_i]][[variable_i]][["pval.random"]],
Weight.random = meta_results[[outcome_i]][[variable_i]][["w.random"]],
lower.predict = meta_results[[outcome_i]][[variable_i]][["lower.predict"]],
upper.predict = meta_results[[outcome_i]][[variable_i]][["upper.predict"]],
I2 = meta_results[[outcome_i]][[variable_i]][["I2"]],
lower.I2 = meta_results[[outcome_i]][[variable_i]][["lower.I2"]],
upper.I2 = meta_results[[outcome_i]][[variable_i]][["upper.I2"]],
H = meta_results[[outcome_i]][[variable_i]][["H"]],
lower.H = meta_results[[outcome_i]][[variable_i]][["lower.H"]],
upper.H = meta_results[[outcome_i]][[variable_i]][["upper.H"]],
tau2 = meta_results[[outcome_i]][[variable_i]][["tau2"]],
lower.tau2 = meta_results[[outcome_i]][[variable_i]][["lower.tau2"]],
upper.tau2 = meta_results[[outcome_i]][[variable_i]][["upper.tau2"]]
) %>%
mutate(outcome = outcome_i,
variable = variable_i) %>%
select(studlab, outcome, variable, everything())
}
}
return(ma_ind_combine)
}
```
```{r}
meta_ind_results_all <- format_meta_ind(meta_results_all)
```
```{r}
meta_ind_discharge <- bind_rows(meta_ind_results_all[['time_first_discharge_reg_elix']]) %>%
distinct(variable, TE.random, lower.random, upper.random, pval.random) %>%
mutate(TE.random = exp(TE.random),
lower.random = exp(lower.random),
upper.random = exp(upper.random)) %>%
filter(!variable == "DMcx") %>%
mutate(`Estimate` = round(TE.random, 2),
lower.random = round(lower.random, 2),
upper.random = round(upper.random, 2),
"Hazard Ratio" = paste(Estimate, "(", lower.random, ",", upper.random, ")"),
p.value_format = ifelse(pval.random > 0.01, round(pval.random, 2), round(pval.random, 3)),
"P-value" = ifelse(pval.random < 0.001, "< .001*", as.character(p.value_format)),
"P-value" = ifelse(pval.random >= 0.001 & round(pval.random,2) < 0.05, paste(`P-value`, "*"), `P-value`)
) %>%
select(-p.value_format) %>%
rename(Covariate = "variable")
meta_ind_deceased <- bind_rows(meta_ind_results_all[['deceased_reg_elix']]) %>%
distinct(variable, TE.random, lower.random, upper.random, pval.random) %>%
mutate(TE.random = exp(TE.random),
lower.random = exp(lower.random),
upper.random = exp(upper.random)) %>%
filter(!variable == "DMcx") %>%
mutate(Estimate = round(TE.random, 2),
lower.random = round(lower.random, 2),
upper.random = round(upper.random, 2),
"Hazard Ratio" = paste(Estimate, "(", lower.random, ",", upper.random, ")"),
p.value_format = ifelse(pval.random > 0.01, round(pval.random, 2), round(pval.random, 3)),
"P-value" = ifelse(pval.random < 0.001, "< .001*", as.character(p.value_format)),
"P-value" = ifelse(pval.random >= 0.001 & round(pval.random,2) < 0.05, paste(`P-value`, "*"), `P-value`)
) %>%
select(-p.value_format) %>%
rename(Covariate = "variable")
```
### Evaluating Outcomes by Age
```{r}
meta_ind_deceased_age <- meta_ind_deceased %>%
filter(grepl(x = Covariate, pattern = "(age|neuro)")) %>%
mutate(
Covariate = as.factor(Covariate),
Covariate = factor(Covariate,
levels = rev(c("neuro_postPeripheral",
"neuro_postCentral",
"age_group26to49",
"age_group50to69",
"age_group70to79",
"age_group80plus")),
labels = rev(c("PNS", "CNS", "26-49", "50-69", "70-79", "80+"))
),
Outcome = "Mortality"
)
meta_ind_discharge_age <- meta_ind_discharge %>%
filter(grepl(x = Covariate, pattern = "(age|neuro)")) %>%
mutate(
Covariate = as.factor(Covariate),
Covariate = factor(Covariate,
levels = rev(c("neuro_postPeripheral",
"neuro_postCentral",
"age_group26to49",
"age_group50to69",
"age_group70to79",
"age_group80plus")),
labels = rev(c("PNS", "CNS", "26-49", "50-69", "70-79", "80+"))
),
Outcome = "Discharge"
)
meta_ind_age <- rbind(meta_ind_deceased_age, meta_ind_discharge_age)
color_palette <- c(PNS = "slateblue", CNS ="tomato", `26-49` = "#fde725",
`50-69` = "#35b779", `70-79` = "#31688e", `80+` = "#440154")
age_hr <- ggplot(meta_ind_age, aes(x=TE.random, y=Covariate, colour=Covariate, group = Outcome)) +
scale_color_manual("", values = color_palette) +
geom_point(aes(x=TE.random), shape=15, size=3, position = pd) +
geom_linerange(aes(xmin=lower.random, xmax=upper.random), position = pd) +
labs(x = "Hazard Ratio", y = "") +
geom_vline(xintercept = 1, linetype="dashed") +
facet_grid(~Outcome, scales = "free_x") +
theme_bw() +
theme(strip.text.x = element_text(size = 15, face = "bold"),
strip.text.y = element_text(size = 15, face = "bold"),
axis.title.x = element_text(size = 15, face = "bold"),
axis.text.x = element_text(size = 13, face = "bold", color = "black"),
axis.text.y = element_text(size = 12, face = "bold"),
legend.position = "none")
ggsave("figures/Hazard_ratio_age.png", age_hr, width = 12, height = 6, dpi = 300)
```
### Evaluate all covariates
Create a scale function to identify the min and max CI for each site, excluding sites with values of 'Inf' or our invalid sites
```{r}
scale_plot <- function(combined_results_df) {
scale <- combined_results_df %>%
filter(
!lower.random == "Inf",
!upper.random == "Inf"
) %>%
mutate(
min_est = min(lower.random, na.rm = TRUE) - 1,
max_est = max(upper.random, na.rm = TRUE) + 1,
min_est = if_else(min_est + 1 >= -1, min(lower.random, na.rm = TRUE)-0.1, min_est),
min_est = if_else(min_est > 1, 0.5, min_est),
max_est = if_else(max_est - 1 < 1, 1.1, max_est)) %>%
distinct(min_est, max_est)
return(scale)
}
```
### **Mortality Results**
```{r fig.width=8, height=20, message=FALSE, warning=FALSE}
## define forest plot shapes
# shape #16 is normal circle; #18 is diamond
shapes <- rep(16, times = nrow(meta_ind_deceased))
#shapes[length(shapes)] <- 18
sizes <- rep(3.25, times = nrow(meta_ind_deceased))
#sizes[length(sizes)] <- 5
scale <- scale_plot(meta_ind_deceased)
forester(
left_side_data = meta_ind_deceased %>% select(Covariate),
estimate = meta_ind_deceased$Estimate,
ci_low = meta_ind_deceased$lower.random,
ci_high = meta_ind_deceased$upper.random,
right_side_data = meta_ind_deceased[, c("Hazard Ratio", "P-value")],
display = TRUE,
font_family = "arial",
arrows = TRUE,
arrow_labels = c("Decreased Risk", "Increased Risk"),
null_line_at = 1,
xlim = c(scale$min_est,25),
point_sizes = sizes,
point_shapes = shapes,
x_scale_linear = FALSE,
add_plot_width = 5,
ggplot_width = 100,
set_png_height = 12.5,
file_path = here::here(paste0("figures/meta-analysis-coefficients-ind-90-mortality.png")))
```
### **Discharge Results**
```{r fig.width=8, height=20, message=FALSE, warning=FALSE}
## define forest plot shapes
# shape #16 is normal circle; #18 is diamond
shapes <- rep(16, times = nrow(meta_ind_discharge))
#shapes[length(shapes)] <- 18
sizes <- rep(3.25, times = nrow(meta_ind_discharge))
#sizes[length(sizes)] <- 5
scale <- scale_plot(meta_ind_discharge)
forester(
left_side_data = meta_ind_discharge %>% select(Covariate),
estimate = meta_ind_discharge$Estimate,
ci_low = meta_ind_discharge$lower.random,
ci_high = meta_ind_discharge$upper.random,
right_side_data = meta_ind_discharge[, c("Hazard Ratio", "P-value")],
display = TRUE,
font_family = "arial",
arrows = TRUE,
arrow_labels = c("Decreased Risk", "Increased Risk"),
null_line_at = 1,
xlim = c(scale$min_est, 3.5),
point_sizes = sizes,
point_shapes = shapes,
x_scale_linear = FALSE,
add_plot_width = 5,
ggplot_width = 100,
set_png_height = 12.5,
file_path = here::here(paste0("figures/meta-analysis-coefficients-ind-90-discharge.png")))
```