-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.R
322 lines (279 loc) · 10.4 KB
/
script.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
# Load required libraries
library(metafor)
library(metaviz)
library(readr)
library(ggplot2)
library(ggthemes)
library(patchwork)
library(TOSTER)
library(dplyr)
library(tidyr)
library(devtools)
library(ggrepel)
devtools::install_github("MathiasHarrer/dmetar")
library(dmetar)
# Create required functions
# This function takes effect size data and standard errors from a reported meta-analysis
ma_pipe_sei <-
function(dat,
true_effect,
rep_upper,
rep_lower,
analysis_title,
plot = TRUE) {
dat <- read.csv(dat) # Read the file
res <- rma(yi,
sei = sei,
data = dat,
method = "DL") # Perform a meta-analysis
sunset <- viz_sunset(
x = dat[, c("yi", "sei")],
contours = FALSE,
true_effect = true_effect,
power_contours = "continuous"
) # Create sunset plot
dat[["power_observed"]] <-
(1 - stats::pnorm(stats::qnorm(1 - 0.05 / 2) * dat[["sei"]],
abs(true_effect), dat[["sei"]])) +
stats::pnorm(stats::qnorm(0.05 / 2) *
dat[["sei"]], abs(true_effect),
dat[["sei"]]) # Calculate power for each study
dat[["power_e33"]] <-
(1 - stats::pnorm(stats::qnorm(1 - 0.05 / 2) * dat[["sei"]],
abs(0.33), dat[["sei"]])) +
stats::pnorm(stats::qnorm(0.05 / 2) *
dat[["sei"]], abs(0.33),
dat[["sei"]]) # Calculate power for each study for an effect of 0.33
dat[["power_e66"]] <-
(1 - stats::pnorm(stats::qnorm(1 - 0.05 / 2) * dat[["sei"]],
abs(0.66), dat[["sei"]])) +
stats::pnorm(stats::qnorm(0.05 / 2) *
dat[["sei"]], abs(0.66),
dat[["sei"]]) # Calculate power for each study for an effect of 0.66
power_median_dat <- data.frame(observed=numeric(1),e33=numeric(1),e66=numeric(1))
power_median_dat[["observed"]] <- median(dat[["power_observed"]])
power_median_dat[["e33"]] <- median(dat[["power_e33"]])
power_median_dat[["e66"]] <- median(dat[["power_e66"]])
power_median_dat <- as.data.frame(power_median_dat)
power_median_dat <- mutate(power_median_dat,
analysis = analysis_title) # Calculate median power
rep_se <-
((rep_upper) - (rep_lower)) / (2 * 1.96) # Calculate SE for the summary effect
sink("/dev/null")
et <- TOSTmeta(
ES = true_effect,
se = rep_se,
low_eqbound_d = -0.2,
high_eqbound_d = 0.2,
plot = TRUE
) # Perform an equivalence test
et <- as.data.frame(et)
et <- mutate(et, Analysis = analysis_title) # Calculate median power
sink()
if (plot == TRUE) {
effect_size <- et$ES
et <- as.data.frame(et)
et_plot <-
ggplot(et,
aes(
x = "",
y = ES,
ymin = low_eqbound_d,
ymax = high_eqbound_d
)) +
geom_hline(aes(yintercept = 0), linetype = 'solid', size = 0.5) +
geom_linerange(size = 5,
colour = "#00AFBB",
alpha = 0.5) +
annotate(
geom = "point",
x = "",
y = effect_size,
color = "black",
shape = 18,
size = 4
) +
theme(axis.text.x = element_text(size = 8)) +
coord_flip() +
theme_minimal() +
theme(strip.text = element_text(
size = 8,
face = "bold",
angle = 90
)) +
theme(strip.background = element_rect(colour = "black", fill = "white")) +
theme(axis.title.y = element_text(face = "bold", size = 12)) +
theme(axis.title.x = element_text(face = "bold", size = 12)) +
theme(axis.title.y = element_blank()) +
ylab(expression("Effect size"))
et_plot <-
et_plot + geom_linerange(aes(ymin = UL_CI_ZTEST, ymax = LL_CI_ZTEST), size = 0.5)
et_plot <-
et_plot + geom_linerange(aes(ymin = UL_CI_TOST, ymax = LL_CI_TOST),
size = 1.5,
colour = "black")
et_plot # Creates an equivalence test plot
}
value <- list(
res = res,
dat = dat,
power_median_dat = power_median_dat,
sunset = sunset,
et = et,
et_plot = et_plot
) # Create a list of output objects
attr(value, "class") <- "ma_pipe_sei"
value
}
# This function takes equivalence test results from the first function to create an equivalence test forest plot
combine_et <-
function(dat){
et_plot_combine <-
ggplot(dat,
aes(
x = reorder(Analysis, -ES),
y = ES,
ymin = -0.6,
ymax = 0.6
)) +
geom_rect(xmin = -Inf, ymin = -0.1, xmax = Inf, ymax = 0.1,
fill = "#00AFBB", alpha = 0.2) +
geom_rect(xmin = -Inf, ymin = -0.2, xmax = Inf, ymax = 0.2,
fill = "#00AFBB", alpha = 0.1) +
geom_rect(xmin = -Inf, ymin = -0.5, xmax = Inf, ymax = 0.5,
fill = "#00AFBB", alpha = 0.05) +
geom_point(color = "black",
shape = 18,
size = 4) +
theme(axis.text.x = element_text(size = 8)) +
coord_flip() +
theme_minimal() +
theme(strip.text = element_text(
size = 8,
face = "bold",
angle = 90
)) +
theme(strip.background = element_rect(colour = "black", fill = "white")) +
theme(axis.title.y = element_text(face = "bold", size = 12)) +
theme(axis.title.x = element_text(face = "bold", size = 12)) +
theme(axis.title.y = element_blank()) +
ylab(expression("Effect size"))
et_plot_combine <-
et_plot_combine + geom_linerange(aes(ymin = UL_CI_ZTEST, ymax = LL_CI_ZTEST), size = 0.5)
et_plot_combine <-
et_plot_combine + geom_linerange(aes(ymin = UL_CI_TOST, ymax = LL_CI_TOST),
size = 1.5,
colour = "black")
et_plot_combine <-
et_plot_combine + scale_y_continuous(breaks=c(-.5, -.20,-.1, 0, .1, 0.2, 0.5))
et_plot_combine <-
et_plot_combine + geom_hline(yintercept=0, linetype="dashed", color = "black")
et_plot_combine # Creates an equivalence test plot
}
# These scripts perform the required analyses on the meta-analysis data
leppanen_2017_1_results <- ma_pipe_sei(
"dat_leppanen_2017_1.csv",
true_effect = 0.09,
rep_lower = -0.06,
rep_upper = 0.24,
analysis_title = "Leppanen_2017_1",
plot = TRUE
)
leppanen_2017_1_power_median_dat <- leppanen_2017_1_results$power_median_dat
leppanen_2017_1_power_median_dat$ES <- 0.09
leppanen_2017_1_et_dat <- leppanen_2017_1_results$et
# One outlier was removed from the dataset in the original analysis
dat_leppanen_2017_2 <-
read.csv("dat_leppanen_2017_2.csv") # Load raw data
dat_leppanen_2017_2 <-
dat_leppanen_2017_2[!(dat_leppanen_2017_2$Trial %in% c(16)), ] # Remove outlier
write.csv(dat_leppanen_2017_2,
"dat_leppanen_2017_2_outlier_removed.csv") # Create new .csv file
leppanen_2017_2_results <- ma_pipe_sei(
"dat_leppanen_2017_2_outlier_removed.csv",
true_effect = 0.18,
rep_lower = 0.06,
rep_upper = 0.29,
analysis_title = "Leppanen_2017_2",
plot = TRUE
)
leppanen_2017_2_power_median_dat <- leppanen_2017_2_results$power_median_dat
leppanen_2017_2_power_median_dat$ES <- 0.18
leppanen_2017_2_et_dat <- leppanen_2017_2_results$et
leppanen_2017_3_results <- ma_pipe_sei(
"dat_leppanen_2017_3.csv",
true_effect = 0.05,
rep_lower = -0.05,
rep_upper = 0.15,
analysis_title = "Leppanen_2017_3",
plot = TRUE
)
leppanen_2017_3_power_median_dat <- leppanen_2017_3_results$power_median_dat
leppanen_2017_3_power_median_dat$ES <- 0.05
leppanen_2017_3_et_dat <- leppanen_2017_3_results$et
leppanen_2017_4_results <- ma_pipe_sei(
"dat_leppanen_2017_4.csv",
true_effect = 0.21,
rep_lower = 0.07,
rep_upper = 0.34,
analysis_title = "Leppanen_2017_4",
plot = TRUE
)
leppanen_2017_4_power_median_dat <- leppanen_2017_4_results$power_median_dat
leppanen_2017_4_power_median_dat$ES <- 0.21
leppanen_2017_4_et_dat <- leppanen_2017_4_results$et
leppanen_2017_5_results <- ma_pipe_sei(
"dat_leppanen_2017_5.csv",
true_effect = 0.18,
rep_lower = -0.02,
rep_upper = 0.39,
analysis_title = "Leppanen_2017_5",
plot = TRUE
)
leppanen_2017_5_power_median_dat <- leppanen_2017_5_results$power_median_dat
leppanen_2017_5_power_median_dat$ES <- 0.18
leppanen_2017_5_et_dat <- leppanen_2017_5_results$et
leppanen_2017_6_results <- ma_pipe_sei(
"dat_leppanen_2017_6.csv",
true_effect = 0.04,
rep_lower = -0.1,
rep_upper = 0.17,
analysis_title = "Leppanen_2017_6",
plot = TRUE
)
leppanen_2017_6_power_median_dat <- leppanen_2017_6_results$power_median_dat
leppanen_2017_6_power_median_dat$ES <- 0.04
leppanen_2017_6_et_dat <- leppanen_2017_6_results$et
# Create the equivalence forest plots
com1 <- rbind(leppanen_2017_1_et_dat,
leppanen_2017_2_et_dat,
leppanen_2017_3_et_dat,
leppanen_2017_4_et_dat,
leppanen_2017_5_et_dat,
leppanen_2017_6_et_dat)
com1 <- combine_et(com1)
com1 <- com1 + ggtitle("Summary effect sizes and equivalence bounds") +
theme(plot.title = element_text(hjust = 0.5))
# Create the meta-analysis power tile supplement
power_med <- rbind(leppanen_2017_1_power_median_dat,
leppanen_2017_2_power_median_dat,
leppanen_2017_3_power_median_dat,
leppanen_2017_4_power_median_dat,
leppanen_2017_5_power_median_dat,
leppanen_2017_6_power_median_dat)
power_med_long <- gather(power_med, effect, power, observed:e66, factor_key=TRUE)
tile <- ggplot(data = power_med_long, aes(x = effect, y = reorder(analysis, -ES),)) +
geom_tile(aes(fill = power)) +
coord_equal(ratio = 0.8) +
scale_fill_gradient(name = "Power", low = "#FDF0FF", high = "#E200FD") + theme_tufte(base_family="Helvetica")
tile <- tile + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank(),
axis.title.y = element_blank())
tile <- tile + ggtitle("Median statistical power") +
xlab("Effect size") +
theme(plot.title = element_text(hjust = 0.5))
tile <- tile + scale_x_discrete(labels=c("observed" = "Observed \n effect", "e33" = "0.33",
"e66" = "0.66"))
tile
# Combine the two plots
com1 + tile