-
Notifications
You must be signed in to change notification settings - Fork 16
/
meta_analysis.R
154 lines (141 loc) · 6.4 KB
/
meta_analysis.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
# using metafor from CRAN
# and metawho from https://github.com/ShixiangWang/metawho
load("report/results/unicox.RData")
library(metawho)
library(forestmodel)
library(tidyverse)
df_summary = df_summary %>%
mutate_at(vars(medianAPMn, medianTMBn, medianTIGS),
list(status = ~ifelse(. > median(.), "High", "Low")))
cox_APM = cox_APM %>%
left_join(df_summary %>% select(Project, medianAPMn_status, medianAPM)) %>%
rename(status = medianAPMn_status) %>%
arrange(medianAPM)
cox_TMB = cox_TMB %>%
left_join(df_summary %>% select(Project, medianTMBn_status, medianTMBn)) %>%
rename(status = medianTMBn_status) %>%
arrange(medianTMBn) %>%
mutate(medianTMB = exp(medianTMBn) - 1)
cox_TIGS = cox_TIGS %>%
left_join(df_summary %>% select(Project, medianTIGS_status, medianTIGS)) %>%
rename(status = medianTIGS_status) %>%
arrange(medianTIGS)
# Set custom forest panels
custom_panel = function(model = NULL, factor_separate_line = FALSE,
headings = list(study = "Study", n = "N", measure = "HR", ci = NULL, p = "Pvalue"),
pvalue=NULL) {
if (inherits(model, "rma")) {
panels <- list(
forest_panel(width = 0.01),
forest_panel(
width = 0.01, display = study, fontface = "bold", heading = headings$study,
width_group = 1
),
forest_panel(
width = 0.18, display = stat, parse = TRUE,
width_group = 1
),
forest_panel(width = 0.03, display = n, hjust = 1, heading = headings$n),
forest_panel(width = 0.03, item = "vline", hjust = 0.5),
forest_panel(
width = 0.45, item = "forest", hjust = 0.5, heading = headings$measure,
linetype = "dashed", line_x = 0
),
forest_panel(width = 0.03, item = "vline", hjust = 0.5),
forest_panel(
width = 0.20,
display = sprintf("%0.2f (%0.2f, %0.2f)", exp(estimate), exp(conf.low), exp(conf.high)),
heading = headings$ci,
display_na = NA
),
forest_panel(width = 0.01, item = "vline", hjust = 0.5),
forest_panel(
width = 0.1, display = round(pvalue, digits = 3),
heading = headings$p,
display_na = NA
)
)
} else {
stop("This function only support rma object.")
}
panels
}
APS_df = cox_APM %>%
rename(hr = Coef,
ci.lb = Lower,
ci.ub = Upper,
ni = N,
subgroup = status) %>%
mutate(trial = Project,
entry = paste(trial, subgroup, sep = "-")) %>%
deft_prepare()
model_APS = APS_df %>%
rma(yi = yi, sei = sei, ni = ni, data = .)
model_APS %>% forestmodel::forest_rma(.,
panels = custom_panel(., headings = list(study = "Project", p = "P.value",
n = "N", measure = "log Hazard Ratio",
ci = "HR (95% CI)"),
pvalue = c(p.adjust(APS_df$Pvalue, method = "fdr"), model_APS$pval)),
study_labels = APS_df$Project,
limits = c(-4, 5)) -> p_aps
TMB_df = cox_TMB %>%
rename(hr = Coef,
ci.lb = Lower,
ci.ub = Upper,
ni = N,
subgroup = status) %>%
mutate(trial = Project,
entry = paste(trial, subgroup, sep = "-")) %>%
deft_prepare()
model_TMB = TMB_df %>%
rma(yi = yi, sei = sei, ni = ni, data = .)
model_TMB %>%
forestmodel::forest_rma(.,
panels = custom_panel(., headings = list(study = "Project", p = "P.value",
n = "N", measure = "log Hazard Ratio",
ci = "HR (95% CI)"),
pvalue = c(p.adjust(TMB_df$Pvalue, method = "fdr"), model_TMB$pval)),
study_labels = TMB_df$Project,
limits = c(-2, 3)) -> p_tmb
TIGS_df = cox_TIGS %>%
rename(hr = Coef,
ci.lb = Lower,
ci.ub = Upper,
ni = N,
subgroup = status) %>%
mutate(trial = Project,
entry = paste(trial, subgroup, sep = "-")) %>%
deft_prepare()
model_TIGS = TIGS_df %>%
rma(yi = yi, sei = sei, ni = ni, data = .)
model_TIGS %>%
forestmodel::forest_rma(.,
panels = custom_panel(., headings = list(study = "Project", p = "P.value",
n = "N", measure = "log Hazard Ratio",
ci = "HR (95% CI)"),
pvalue = c(p.adjust(TIGS_df$Pvalue, method = "fdr"), model_TIGS$pval)),
study_labels = TIGS_df$Project,
limits = c(-4, 7)) -> p_tigs
ggsave("Meta_APS.pdf", plot = p_aps, width = 7, height = 7)
ggsave("Meta_TMB.pdf", plot = p_tmb, width = 7, height = 7)
ggsave("Meta_TIGS.pdf", plot = p_tigs, width = 7, height = 7)
# Plot correlation between median value and HR
plot_df = dplyr::bind_rows(
cox_APM %>% select(Project, Coef, medianAPM, N) %>%
rename(Median = medianAPM) %>% mutate(type = "APS"),
cox_TMB %>% select(Project, Coef, medianTMB, N) %>%
rename(Median = medianTMB) %>% mutate(type = "TMB"),
cox_TIGS %>% select(Project, Coef, medianTIGS, N) %>%
rename(Median = medianTIGS) %>% mutate(type = "TIGS")
) %>% rename(HR = Coef) %>%
mutate(type = factor(type, levels = c("APS", "TMB", "TIGS")))
library(ggpubr)
#ggpubr::ggscatter(plot_df, x = "Median", y = "HR", facet.by = "type")
ggplot(plot_df %>% filter(HR < 10), aes(x = Median, y = HR)) +
geom_point() +
geom_smooth(method = "lm") +
facet_wrap(~type, scales = "free") +
stat_cor(method = "pearson") +
geom_hline(yintercept = 1, linetype = 2) +
cowplot::theme_cowplot() + ylab("Hazard ratio per unit increase") + xlab(label = "Tumor type APS/TMB/TIGS median") -> p
ggsave("HR_vs_median_APS_TMB_TIGS.pdf", plot = p, width = 8, height = 3)