-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_consort_flow.R
415 lines (398 loc) · 12 KB
/
2_consort_flow.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
# 1_consort_flow.R
# CONSORT flow diagram of numbers of submissions and reviews
# called from within 1_analysis.Rmd
# October 2019
library(diagram)
## function to run same plot for submission and reviewer numbers
# had to do separately because of statistical reviews
flow.plot.submission = function(indata, actual.data){
# labels
l1 = paste(
'Submitted (n=',
format(
with(indata, n.bmj + n.bmjopen),
big.mark = ','
),
')\n',
'- BMJ (n=',
format(with(indata, n.bmj), big.mark = ','),
')\n',
'- BMJ Open (n=',
format(with(indata, n.bmjopen), big.mark = ','),
')',
sep = ''
)
l2 = paste(
'Excluded (n=',
format(
with(indata, n.bmj + n.bmjopen) - nrow(actual.data),
big.mark = ','
),
')\n',
'- No address data (n=',
format(
with(
indata,
n.bmj + n.bmjopen - n.missing.address
),
big.mark = ','
),
')\n',
'- Transfers between two\njournals (n=',
format(
with(
indata,
n.missing.address - n.excluded.transfer
),
big.mark = ','
),
')\n',
'- Countries with under 100\nresults (n=',
format(
with(
indata,
n.excluded.transfer - n.post.exclude.100
),
big.mark = ','
),
')\n',
'- No geocoded address (n=',
format(
with(
indata,
n.post.exclude.100 - n.after.geomatch
),
big.mark = ','
),
')\n',
'- Different country in geocoded\naddress (n=',
format(
with(
indata,
n.after.geomatch - n.post.exclude.differing.country
),
big.mark = ','), ')\n',
'- Countries with under 100 results\nwith updated address (n=',
format(
with(
indata,
n.post.exclude.differing.country - n.post.exclude.100.second
),
big.mark = ','), ')\n',
'- Results at start or end with\nincomplete weeks (n=',
format(
with(
indata,
n.post.exclude.100.second - n.after.windows
),
big.mark = ','), ')', sep = '')
# get numbers with holidays
with.holidays = filter(actual.data, holiday=='Yes') %>%
dplyr::select(country) %>%
unique()
n.hols = nrow(filter(actual.data, country %in% with.holidays$country))
l3 = paste('Analysed (n=', format(nrow(actual.data), big.mark = ','), ')\n',
'- With holiday data (n=', format(n.hols, big.mark = ','), ')' , sep =
'')
labels = c(l1, l2, l3)
n.labels = length(labels)
### make data frame of box chars
frame = read.table(
sep = '\t',
stringsAsFactors = F,
skip = 0,
header = T,
text = '
i x y box.col box.type box.prop box.size
1 0.27 0.85 white square 0.33 0.25
2 0.7 0.48 white square 0.94 0.28
4 0.27 0.11 white square 0.27 0.25
'
)
#
pos = as.matrix(subset(frame, select = c(x, y)))
M = matrix(
nrow = n.labels,
ncol = n.labels,
byrow = TRUE,
data = 0
)
M[3, 1] = "' '"
to.return = list()
to.return$M = M
to.return$pos = pos
to.return$labels = labels
to.return$frame = frame
return(to.return)
} # end of function for submissions
# version for reviews with stats reviewer and patient exclusions
flow.plot.review = function(indata, actual.data){
# labels
l1 = paste(
'Submitted (n=',
format(
with(indata, n.bmj + n.bmjopen),
big.mark = ','
),
')\n',
'- BMJ (n=',
format(with(indata, n.bmj), big.mark = ','),
')\n',
'- BMJ Open (n=',
format(with(indata, n.bmjopen), big.mark = ','),
')',
sep = ''
)
l2 = paste(
'Excluded (n=',
format(
with(indata, n.bmj + n.bmjopen) - nrow(actual.data),
big.mark = ','
),
')\n',
'- No address data (n=',
format(
with(
indata,
n.bmj + n.bmjopen - n.missing.address
),
big.mark = ','
),
')\n',
'- Statistical reviews (n=',
format(
with(
indata,
n.missing.address - n.excluded.stats
),
big.mark = ','
),
')\n',
'- Patient reviews (n=',
format(
with(
indata,
n.excluded.stats - n.excluded.patients
),
big.mark = ','
),
')\n',
'- Transfers between two\njournals (n=',
format(
with(
indata,
n.excluded.patients - n.excluded.transfer
),
big.mark = ','
),
')\n',
'- Countries with under 100\nresults (n=',
format(
with(
indata,
n.excluded.transfer - n.post.exclude.100
),
big.mark = ','
),
')\n',
'- No geocoded address (n=',
format(
with(
indata,
n.post.exclude.100 - n.after.geomatch
),
big.mark = ','
),
')\n',
'- Different country in geocoded\naddress (n=',
format(
with(
indata,
n.after.geomatch - n.post.exclude.differing.country
),
big.mark = ','), ')\n',
'- Countries with under 100 results\nwith updated address (n=',
format(
with(
indata,
n.post.exclude.differing.country - n.post.exclude.100.second
),
big.mark = ','), ')\n',
'- Results at start or end with\nincomplete weeks (n=',
format(
with(
indata,
n.post.exclude.100.second - n.after.windows
),
big.mark = ','), ')', sep = '')
# get numbers with holidays
with.holidays = filter(actual.data, holiday=='Yes') %>%
dplyr::select(country) %>%
unique()
n.hols = nrow(filter(actual.data, country %in% with.holidays$country))
l3 = paste('Analysed (n=', format(nrow(actual.data), big.mark = ','), ')\n',
'- With holiday data (n=', format(n.hols, big.mark = ','), ')' , sep =
'')
labels = c(l1, l2, l3)
n.labels = length(labels)
### make data frame of box chars
frame = read.table(
sep = '\t',
stringsAsFactors = F,
skip = 0,
header = T,
text = '
i x y box.col box.type box.prop box.size
1 0.27 0.85 white square 0.33 0.25
2 0.7 0.48 white square 1.05 0.28
4 0.27 0.11 white square 0.27 0.25
'
)
#
pos = as.matrix(subset(frame, select = c(x, y)))
M = matrix(
nrow = n.labels,
ncol = n.labels,
byrow = TRUE,
data = 0
)
M[3, 1] = "' '"
to.return = list()
to.return$M = M
to.return$pos = pos
to.return$labels = labels
to.return$frame = frame
return(to.return)
} # end of function for reviews
# run function for two data sources
sub = flow.plot.submission(indata = submission.numbers, actual.data = submission)
rev = flow.plot.review(indata = reviewer.numbers, actual.data = reviewer)
# function to repeat plot in Rmarkdown and tiff
plot.it = function(inlist, header, type='tiff') {
#
to.plot = inlist
if(type == 'rmarkdown'){
to.plot$frame$box.size = to.plot$frame$box.size * 1 # adjustment for rmarkdown (trial and error)
to.plot$frame$box.prop = to.plot$frame$box.prop * 1
}
par(mai = c(0, 0.04, 0.04, 0.04))
with(to.plot,
plotmat(
M,
pos = pos,
name = labels,
lwd = 1,
shadow.size = 0,
curve = 0,
box.lwd = 2,
cex.txt = 1,
box.size = frame$box.size,
box.prop = frame$box.prop,
box.col = frame$box.col,
box.type = frame$box.type,
arr.type = 'simple',
txt.col = 'black'
))
text(0.5, 0.98, header, font=2) # bold
# extra arrow to excluded
arrows(
x0 = 0.27,
x1 = 0.415,
y0 = 0.49,
length = 0.12
)
} # end of plotit function for reviews
#
#postscript('figures/consort.flow.eps', width=5, height=4.5, horiz=F)
tiff(
'figures/consort.flow.tif',
width = 10.5,
height = 5.5,
units = 'in',
res = 300,
compression = 'lzw'
)
layout(matrix(c(1,2), ncol=2), widths=c(1,1), heights=1)
plot.it(sub, header='Submissions')
plot.it(rev, header='Reviews')
dev.off()
layout(1) # restore default layout
# and jpeg
jpeg(
'figures/consort.flow.jpg',
width = 10.5,
height = 5.5,
units = 'in',
res = 300,
quality=100
)
layout(matrix(c(1,2), ncol=2), widths=c(1,1), heights=1)
plot.it(sub, header='Manuscripts')
plot.it(rev, header='Peer reviews')
dev.off()
layout(1) # restore default layout
# percents, plus numerators and denominators
show.percents = FALSE
if(show.percents==TRUE){
cat('Manuscript exclusions:\n')
with(submission.numbers, cat('Total = ', n.bmjopen + n.bmj, '\n', sep='') )
#
total = submission.numbers$n.bmjopen + submission.numbers$n.bmj
numerator = total - submission.numbers$n.missing.address
with(submission.numbers, cat('Missing address = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = submission.numbers$n.missing.address
numerator = total - submission.numbers$n.excluded.transfer
with(submission.numbers, cat('Transfer = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = submission.numbers$n.excluded.transfer
numerator = total - submission.numbers$n.post.exclude.100
with(submission.numbers, cat('Under 100 = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = submission.numbers$n.post.exclude.100
numerator = total - submission.numbers$n.after.geomatch
with(submission.numbers, cat('No geocoded address = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = submission.numbers$n.after.geomatch
numerator = total - submission.numbers$n.post.exclude.differing.country
with(submission.numbers, cat('Differing country = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = submission.numbers$n.post.exclude.differing.country
numerator = total - submission.numbers$n.post.exclude.100.second
with(submission.numbers, cat('Under 100 = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
##
cat('\nReviewer exclusions:\n')
with(reviewer.numbers, cat('Total = ', n.bmjopen + n.bmj, '\n', sep='') )
#
total = reviewer.numbers$n.bmjopen + reviewer.numbers$n.bmj
numerator = total - reviewer.numbers$n.missing.address
with(reviewer.numbers, cat('Missing address = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.missing.address
numerator = total - reviewer.numbers$n.excluded.stats
with(reviewer.numbers, cat('Stats reviewer = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.excluded.stats
numerator = total - reviewer.numbers$n.excluded.patients
with(reviewer.numbers, cat('Patient reviewer = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.excluded.patients
numerator = total - reviewer.numbers$n.excluded.transfer
with(reviewer.numbers, cat('Transfer = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.excluded.transfer
numerator = total - reviewer.numbers$n.post.exclude.100
with(reviewer.numbers, cat('Under 100 = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.post.exclude.100
numerator = total - reviewer.numbers$n.after.geomatch
with(reviewer.numbers, cat('No geocoded address = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.after.geomatch
numerator = total - reviewer.numbers$n.post.exclude.differing.country
with(reviewer.numbers, cat('Differing country = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
#
total = reviewer.numbers$n.post.exclude.differing.country
numerator = total - reviewer.numbers$n.post.exclude.100.second
with(reviewer.numbers, cat('Under 100 = ', round(100*numerator/total,1), '%, ', numerator, '/', total, '\n', sep='') )
}