-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_analysis_weekends.Rmd
1554 lines (1303 loc) · 68.3 KB
/
2_analysis_weekends.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
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
---
title: "Analysis of BMJ submission data over time. Are there more papers and reviews submitted on weekends, holidays and late nights?"
author: "Adrian Barnett"
date: "`r format(Sys.time(), '%d %B %Y')`"
output: word_document
---
```{r setup, include=FALSE}
# basic set up
knitr::opts_chunk$set(echo = FALSE, warning=FALSE, message=FALSE, error=FALSE, comment='', dpi=400)
options(width=1000, scipen = 999) # Wide pages and no scientific numbers
library(R2WinBUGS)
library(season) # for yrfrac and phasecalc
library(lme4) # for glmer
library(broom)
library(stringr)
library(tables)
source('3_tidy_table.R') # for my table tidying
library(pander)
panderOptions('table.emphasize.rownames', FALSE)
panderOptions('keep.trailing.zeros', TRUE)
panderOptions('table.split.table', Inf)
panderOptions('table.split.cells', Inf)
panderOptions('big.mark', ',')
library(dplyr)
library(tidyr)
library(ggplot2)
library(viridis) # for colour schemes
library(gridExtra)
g.theme = theme_bw() + theme(panel.grid.minor = element_blank())
# set up colours
cbPalette = c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")
library(RColorBrewer)
top.ten.colours = brewer.pal(n = 10, name = "Paired") # for top ten, from diverging palette
## load the author and reviewer data
load('data/BMJAnalysisReadyAuthors.RData') # authors from 1_bmj_submission_data.R
load('data/BMJAnalysisReadyReviewers.RData') # reviewers from 1_bmj_reviewer_data.R
reviewer = dplyr::select(reviewer, -lon, -lat, -timezoneId, -city, -address) %>% # drop variables not used here
mutate(type='Reviews')
submission = dplyr::select(submission, -lon, -lat, -timezoneId, -city, -address) %>% # drop variables not used here
mutate(type='Submission')
both = bind_rows(reviewer, submission)
# dates for text below
min.date = min(as.Date(submission$local.date))
max.date = max(as.Date(submission$local.date))
# top ten countries for reviews and submissions (used below)
tab = table(submission$country)
top.ten = names(tab[order(-tab)])[1:10]
tab = table(reviewer$country)
top.ten.reviews = names(tab[order(-tab)])[1:10]
# dates from windows for seasonal analysis (used below)
for.merge = data.frame(window = seq(1,400,1)) %>%
mutate(date = as.Date('2012-01-02')+(window*7)) # start on Jan 2nd
```
# Modelling approach
All statistical models were fitted using a Bayesian approach and therefore show 95% credible intervals instead of confidence intervals. Credible intervals have the more intuitive interpretation of having a 95% probability of containing the true estimate. We do not use p-values.
When describing changes over time we sometimes use the word "slope".
# Flow diagrams of data
The diagrams below show what journal submissions and reviews were included in the final analyses.
## Diagram for submissions
```{r flow.diagram, fig.width=5, fig.height=6}
source('2_consort_flow.R')
plot.it(sub, header='Submissions', type='rmarkdown')
```
## Diagram for reviews
```{r flow.diagram.reviews, fig.width=5, fig.height=5}
plot.it(rev, header='Reviews', type='rmarkdown')
```
# Summary data on numbers
## Journal numbers
The data are from the journals _BMJ_ and _BMJ Open_.
```{r}
tab = tabular(Heading('Type')*factor(type) ~ (Heading('Journal')*journal + 1)*((n=1) + Percent('row')), data=both)
pander(tab, digits=0)
```
## Journal submissions and reviews over time
```{r plot.over.time, fig.width=9, fig.height=6}
# prepare data for plot
over.time = mutate(both, year = as.numeric(format(local.date, '%Y')), # make month and year
month = as.numeric(format(local.date, '%m')),
yrmon = year + ((month-1)/12)) %>%
filter(year < 2019) %>% # remove few papers submitted on 31 December that fall into next time year after timezone adjustment
group_by(type, journal, yrmon) %>%
summarise(count = n())
tplot = ggplot(data=over.time, aes(x=yrmon, y=count, col=journal))+
geom_point()+
geom_line()+
scale_color_manual('Journal', values=cbPalette[3:4])+
xlab('Time')+
ylab('Monthly number of submissions/reviews')+
g.theme +
theme(legend.position = c(0.14,0.8))+
facet_wrap(~type, scales='free_y')
tplot
```
The plot shows the number of submissions and reviews over time for the two journals.
There has been a clear increase in monthly submissions for _BMJ Open_ with a mirrored increase in review numbers, although on a much larger scale.
This plot is potentially commercial-in-confidence and we should check if _BMJ_ are happy for it to appear in reports.
# Times of day
Here we examine the time-of-day pattern of submissions and reviews by weekdays vs weekends. Using all the countries created plots that were too busy, hence we only show the top ten countries.
The percents are by country and weekday/weekend, so the percents add to 100% for each country on weekdays, and also add to 100% on weekends.
## Star plots of submissions by hour of day for top ten countries
The star plots show the percentages of submissions made in each country and also split by the weekday and weekend.
The aim is to see what times of the day researchers are most active and if there are noticeable differences between countries.
```{r star.plots, fig.width=13, fig.height=13}
## star plots
# join lines from midnight, see here https://stackoverflow.com/questions/41842249/join-gap-in-polar-line-ggplot-plot
# prepare the data for the plot by calculating percents within country and weekend/weekday
to.plot.star = filter(submission, country %in% top.ten) %>%
mutate(local.hour = floor(local.hour)) %>%
group_by(country, local.hour, weekend) %>%
summarise(count = n()) %>%
group_by(country, weekend) %>%
mutate(n = sum(count),
percent = 100*count/n) %>%
ungroup()
# add extra grouping of Europe to help separate lines
to.plot.star = mutate(to.plot.star,
Europe = as.numeric(country %in% c('Denmark','France','Germany','Italy','Netherlands','United Kingdom','Sweden')),
Europe = factor(Europe, levels=0:1, labels=c('Non-Europe','Europe')))
# make bridges to join circles
bridges = filter(to.plot.star, local.hour==0) %>%
mutate(local.hour = 23.99) # just before midnight
to.plot.star.bridges = bind_rows(to.plot.star, bridges) %>%
arrange(country, local.hour)
# plot
hour.star = ggplot(data=to.plot.star.bridges, aes(x=local.hour, y=percent, col=country)) +
geom_path()+
# geom_point()+
coord_polar(start=0)+
scale_x_continuous(limits = c(0,24), minor_breaks = seq(0, 24, 1), breaks=seq(0,24,3))+
xlab('Hour of day')+
ylab('Frequency')+
facet_grid(Europe ~ weekend)+
ylab('Percent')+
scale_color_manual('', values=top.ten.colours)+
g.theme +
theme(text = element_text(size=20))
hour.star
```
The lines are smoother on weekdays because of the larger sample size.
### Line plots of submission times
This plot shows the same information as the star plot, but using a linear time axis.
```{r non-star, fig.width=13, fig.height=13}
hour.nonstar = ggplot(data=to.plot.star, aes(x=local.hour, y=percent, col=country)) +
geom_line(size=1.1)+
scale_x_continuous(limits = c(0,24), minor_breaks = seq(0, 24, 1), breaks=seq(0,24,6))+
xlab('Hour of day')+
ylab('Frequency')+
facet_grid(Europe~weekend)+
ylab('Percent')+
scale_color_manual('', values=top.ten.colours)+
g.theme +
theme(text = element_text(size=20))
hour.nonstar
```
As well as the obvious diurnal pattern, there does appear to be a slight increase in submissions just before midnight.
## Star plots of reviews by hour of day for top ten countries
The star plots show the percentages of reviews made in each country and also split by the weekday and weekend.
```{r star.plots.reviews, fig.width=12, fig.height=12}
## star plots
# prepare the data for the plot by calculating percents within country and weekend/weekday
to.plot.star.review = filter(reviewer, country %in% top.ten.reviews) %>%
mutate(local.hour = floor(local.hour)) %>% # re-format Yes/No categories, but just for these plots
group_by(country, local.hour, weekend) %>%
summarise(count = n()) %>%
group_by(country, weekend) %>%
mutate(n = sum(count),
percent = 100*count/n) %>%
ungroup()
# add extra grouping of Europe to help separate lines
to.plot.star.review = mutate(to.plot.star.review,
Europe = as.numeric(country %in% c('Denmark','France','Germany','Italy','Netherlands','United Kingdom','Sweden')),
Europe = factor(Europe, levels=0:1, labels=c('Non-Europe','Europe')))
# make bridges to join circles
bridges = filter(to.plot.star.review, local.hour==0) %>%
mutate(local.hour = 23.99) # just before midnight
to.plot.star.review.bridges = bind_rows(to.plot.star.review, bridges) %>%
arrange(country, local.hour)
# plot
hour.star = ggplot(data=to.plot.star.review.bridges, aes(x=local.hour, y=percent, col=country)) +
geom_path()+
# geom_point()+
coord_polar(start=0)+
scale_x_continuous(limits = c(0,24), minor_breaks = seq(0, 24, 1), breaks=seq(0,24,3))+
xlab('Hour of day')+
ylab('Frequency')+
facet_grid(Europe ~ weekend)+
ylab('Percent')+
scale_color_manual('', values=top.ten.colours)+
g.theme +
theme(text = element_text(size=20))
hour.star
```
### Line plots of review times
This plot shows the same information as the star plot, but using a linear time axis.
```{r non-star.review, fig.width=12, fig.height=12}
hour.nonstar = ggplot(data=to.plot.star.review, aes(x=local.hour, y=percent, col=country)) +
geom_line(size=1.1)+
scale_x_continuous(limits = c(0,24), minor_breaks = seq(0, 24, 1), breaks=seq(0,24,6))+
xlab('Hour of day')+
ylab('Frequency')+
facet_grid(Europe~weekend)+
ylab('Percent')+
scale_color_manual('', values=top.ten.colours)+
g.theme +
theme(text = element_text(size=20))
hour.nonstar
```
As well as the obvious diurnal pattern, there may be small lunch time peaks in some countries.
## Line plots of the ratio of submissions to reviews by hour of day for the top ten countries
The plot below shows the ratio of the percentage of submissions to reviews, so it combines the data from the above line plots. The aim is to show times when relatively more submissions are received than reviews. The plot uses percents and not absolute numbers, so it looks at the relative difference in activity. There are far more reviews than submissions, so if we used absolute numbers any relative change would be lost.
```{r star.plots.ratio, fig.width=12, fig.height=7}
## make ratio of star plots,
to.plot.star = rename(to.plot.star, 'submission' = 'percent') %>%
dplyr::select(-count, -n)
to.plot.star.review = rename(to.plot.star.review, 'review' = 'percent') %>%
dplyr::select(-count, -n)
ratio = left_join(to.plot.star, to.plot.star.review, by=c('country','local.hour','Europe','weekend')) %>%
mutate(ratio = submission / review)
# plot
ratio.plot = ggplot(data=ratio, aes(x=local.hour, y=ratio, col=country)) +
geom_line(size=1.05)+
geom_hline(yintercept=1, lty=2)+
scale_x_continuous(limits = c(0,24), minor_breaks = seq(0, 24, 1), breaks=seq(0,24,3))+
xlab('Hour of day')+
ylab('Frequency')+
facet_grid(Europe~weekend)+
ylab('Ratio')+
annotate('text', x=0, y=1.9, label='More submissions', hjust=0)+
annotate('text', x=0, y=0.1, label='More reviews', hjust=0)+
scale_color_manual('', values=top.ten.colours)+
coord_cartesian(ylim=c(0,2))+ # truncate because of few extremes in early mornings on weekends
g.theme +
theme(text = element_text(size=20))
ratio.plot
```
The percent axis has been truncated as there were a few very large estimates in early mornings on weekends, but these had small sample sizes.
# Weekends
In this section we tabulate, plot and model the data on weekend submissions and reviews.
## Submissions
The table shows the overall frequency of submissions on weekdays and weekends in the top ten submitting countries.
```{r table.weekends}
to.table = filter(submission, country %in% top.ten) %>%
mutate(country = factor(as.character(country))) # remove empty categories
tab = tabular(Heading('Country')*country + 1 ~ Heading('')*weekend*( (n=1) + Heading('%')*Percent('row')*Format(digits=3)), data=to.table)
pander(tab)
```
## Reviews
The table shows the overall frequency of reviews on weekdays and weekends in the top ten reviewing countries.
```{r table.weekends.reviews}
to.table = filter(reviewer, country %in% top.ten.reviews) %>%
mutate(country = factor(as.character(country))) # remove empty categories
tab = tabular(Heading('Country')*country + 1 ~ Heading('')*weekend*( (n=1) + Heading('%')*Percent('row')*Format(digits=3)), data=to.table)
pander(tab)
```
## Plots of weekdays by year
The aim is to look for a trend over time in the percent of weekend submissions and reviews.
The plots show the annual numbers of submissions and reviews by day of the week from 2012 to 2018.
### Submissions
```{r plot.submissions, fig.width=11, fig.height=7}
# combine into weekends vs weekdays
wdays = c('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')
wdays2 = c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')
to.plot = mutate(submission,
year = as.numeric(format(local.date, '%Y')), # make year and weekday
weekday = as.numeric(format(local.date, '%w')),
weekday = factor(weekday, levels=0:6, labels=wdays),
weekday = ordered(weekday, levels=wdays2)) %>% # order with Monday first
filter(year < 2019) %>% # remove papers from 2019 for this plot so that we have full years
group_by(year, journal, weekday) %>% # stratify by year and journal
summarise(count = n()) %>%
group_by(year, journal) %>%
mutate(sum = sum(count), # counts by year and journal
percent = 100*count/sum) %>%
ungroup()
# plot
wplot = ggplot(data=to.plot, aes(x=year, y=percent, col=weekday))+
geom_line(lwd=1.1)+
scale_color_manual(NULL, values=cbPalette[1:7])+
ylab('Submission percentages')+
xlab('Year')+
g.theme +
theme(legend.position = 'right', legend.direction = 'vertical', text=element_text(size=16))+
facet_wrap(~journal)
wplot
```
### Reviews
```{r plot.reviews, fig.width=11, fig.height=7}
to.plot = mutate(reviewer, year = as.numeric(format(local.date, '%Y')), # make year and weekday
weekday = as.numeric(format(local.date, '%w')),
weekday = factor(weekday, levels=0:6, labels=wdays),
weekday = ordered(weekday, levels=wdays2)) %>% # order with Monday first
filter(year < 2019) %>% # remove papers from 2019 for this plot so that we have full years
group_by(year, journal, weekday) %>% # stratify by year and journal
summarise(count = n()) %>%
group_by(year, journal) %>%
mutate(sum = sum(count), # counts by year and journal
percent = 100*count/sum) %>%
ungroup()
# plot
wplot = ggplot(data=to.plot, aes(x=year, y=percent, col=weekday))+
geom_line(lwd=1.1)+
scale_color_manual(NULL, values=cbPalette[1:7])+
ylab('Review percentages')+
xlab('Year')+
g.theme +
theme(legend.position = 'right', legend.direction = 'vertical', text=element_text(size=16))+
facet_wrap(~journal)
wplot
```
The most common day for reviews was Monday and the least common day was Saturday.
## Plot of weekend percents by week-to-week results
The plots below aim to examine the trend over time in weekend submissions and reviews. They show the Weekly percentage of submitted papers and reviewers on the weekend. The blue line is a non-linear smooth using a loess with a span of 0.75.
### Submissions
```{r week2week.submissions, fig.width=12, fig.height=7}
# first get axis labels in years by window numbers
axis.labels = mutate(submission,
year=format(local.date, '%Y'),
month=format(local.date, '%m'),
day=format(local.date, '%d')) %>%
filter(month=='01', day=='02') %>% # use Jan 2nd because Jan 1st was excluded as it was not a full week
dplyr::select(year, window) %>%
unique()
# plot weekends by week-to-week
for.plot = arrange(submission, local.date) %>%
group_by(window, journal, weekend) %>%
summarise(count = n()) %>%
tidyr::spread(key=weekend, value=count) %>% # put weekends and weekdays on same row
mutate(Weekday = ifelse(is.na(Weekday), 0, Weekday), # replace missing with zero
Weekend = ifelse(is.na(Weekend), 0, Weekend),
denom = Weekday + Weekend,
percent = 100*Weekend/denom)
tplot = ggplot(data=for.plot, aes(x=window, y=percent))+
geom_line()+
geom_smooth(col='skyblue', se = FALSE, method='loess', span=0.75)+
g.theme+
scale_x_continuous(breaks=axis.labels$window, labels=axis.labels$year)+
ylab('Weekly percent')+
xlab('Time')+
facet_wrap(~journal)+
theme(text = element_text(size=16))
tplot
```
The estimated trends shows a small increase in weekend submissions over time.
### Reviews
```{r week2week.reviewers, fig.width=12, fig.height=7}
# plot weekends by week-to-week
for.plot = arrange(reviewer, local.date) %>%
group_by(window, journal, weekend) %>%
summarise(count = n()) %>%
tidyr::spread(key=weekend, value=count) %>% # put weekends and weekdays on same row
mutate(Weekday = ifelse(is.na(Weekday), 0, Weekday), # replace missing with zero
Weekend = ifelse(is.na(Weekend), 0, Weekend),
denom = Weekday + Weekend,
percent = 100*Weekend/denom)
tplot = ggplot(data=for.plot, aes(x=window, y=percent))+
geom_line()+
geom_smooth(col='skyblue', se = FALSE, method='loess', span=0.75)+
g.theme+
scale_x_continuous(breaks=axis.labels$window, labels=axis.labels$year)+
ylab('Weekly percent')+
xlab('Time')+
facet_wrap(~journal)+
theme(text = element_text(size=16))
tplot
```
There does appear to be a small increase over time in weekend reviews, especially for BMJ Open.
# Statistical models - weekend submissions
Here we examine a relative increase in weekend submissions over time using a binomial model.
We run separate models in each of the two journals.
We used a country-specific intercept for each country to control for differences between countries in the probability of submitting on the weekend.
We plot the country-specific intercepts to show the differences between countries. We exclude countries with small numbers from the plots.
In terms of the change over time in weekend submissions, we use two models.
The simpler model assumes the change is the same in every country.
The more complex model allows a country-specific change over time.
We plot the country-specific changes.
We examine a seasonal pattern in submissions using a sinusoidal model with an annual cycle. We allow the seasonal pattern to vary by country. We plot the overall season pattern and the phase and amplitude in each country. The phase is the timing of the seasonal peak and the amplitude is its height.
We compare the fit of the models using the deviance information criterion.
## BMJ weekend submissions
This section examines journal submissions on the weekend to the BMJ.
### Best fitting model
First we examine the deviance information criterion (DIC) to find the best model
```{r best.bmj.weekend.submissions}
DIC = DIC.best = NULL
which.outcome = 'weekend'
which.data.text = 'submissions' # data with windows
which.data.text.update = 'submissions.weekend'
which.data = get(which.data.text.update)
which.journal = 'BMJ'
for (type in c('slope','intercept')){
for (season in c(TRUE, FALSE)){
source('99_jags_filename.R') # create filenames for data, chains and results
l = length(dir('Z:/weekend', pattern=jags.filename.results)) # flag that results exist
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
DIC = bind_rows(DIC, dic.frame)
}
}
DIC = mutate(DIC, Difference = DIC - min(DIC))
to.table = dplyr::select(DIC, -journal, -outcome, -data) %>% # information already in title
arrange(DIC)
pander(to.table, digits=0, style='simple')
# load the results for the best model and store best DIC for later use
best = filter(DIC, Difference==0)
DIC.best = bind_rows(DIC.best, best)
type = best$model
season = ifelse(best$season=='Season', TRUE, FALSE)
source('99_jags_filename.R') # create filenames for data, chains and results
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
```
The best model (smallest DIC) has both a country-specific slope and a seasonal pattern. Hence we show the results for this model below.
### Table of parameter estimates for best model for weekend submissions to BMJ
```{r best.bmj.weekend.submission.results}
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
The intercept is the overall average and the change is the annual change in probability. Both are on a logit scale because we used a binomial model.
The two estimated probabilities are for 2012 and 2013 and are used to show the annual difference in weekend submissions. The difference is the absolute increase in probability per year. The ratio is the relative change in probability per year.
There was little change over time in the probability of submitting on the weekend.
### Plot of country-specific intercepts and 95% credible intervals for weekend submissions to BMJ
The plot below shows the estimated weekend probability in each country.
The aim is to look for interesting differences between countries in the probability of submitting papers on the weekend.
The 95% credible intervals are wider for countries with fewer submissions.
The countries are ordered by their mean probability, making it easier to spot patterns which countries have similar means.
```{r plot.intercepts.bmj.submissions}
source('2_plot_intercepts.R')
iplot
best.plot.bmj.weekend.manuscripts = iplot # store for later multi-panel plot
```
There are large differences between countries in the probability of submitting on the weekend. The lowest average probability is in India and the highest average in China. In China the probability is very high and almost equivalent to an equal probability on any day of the week as 2 days out of 7 is a probability of 0.29.
### Plot of country-specific slopes and 95% credible intervals for weekend submissions to BMJ
```{r plot.slopes.bmj.submissions}
source('2_plot_slopes.R')
splot
```
The dotted vertical line is the average change over time, which is close to zero indicating no change across all countries. Japan has the largest average increase over time in weekend submissions and Austria the smallest average.
### Plot of seasonal estimates for weekend submissions to BMJ
The plots are: i) the average sinusoidal seasonal pattern, ii) the country-specific seasonal pattern using a circular plot. The position of the dot shows the phase, which is the location of the peak. January is at 12 o'clock on the circle and July at 6 o'clock. Dots close to the centre have only a weak seasonal pattern, whereas those further towards the edge have a stronger seasonal pattern (amplitude).
```{r plot.season.bmj.weekend.submissions, fig.width=13, fig.height=6.5}
source('2_plot_season.R')
grid.arrange(mplot, seasonplot, nrow = 1)
```
The seasonal pattern in submissions peaks in January with an odds ratio of 1.1. The country-specific estimates show a number of countries close to the centre, meaning they have little seasonal pattern. The strongest seasonal patterns are in Israel, Iran, Finland, New Zealand, and Norway.
## BMJ Open weekend submissions
This section examines journal submissions on the weekend to BMJ Open.
### Best fitting model
First we examine the deviance information criterion (DIC) to find the best model
```{r best.bmjopen.weekend.submissions}
DIC = NULL
which.outcome = 'weekend'
which.data.text = 'submissions' # data with windows
which.data.text.update = 'submissions.weekend' #
which.data = get(which.data.text.update)
which.journal = 'BMJ Open'
for (type in c('slope','intercept')){
for (season in c(TRUE, FALSE)){
source('99_jags_filename.R') # create filenames for data, chains and results
l = length(dir('Z:/weekend', pattern=jags.filename.results)) # flag that results exist
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
DIC = bind_rows(DIC, dic.frame)
}
}
DIC = mutate(DIC, Difference = DIC - min(DIC))
to.table = dplyr::select(DIC, -journal, -outcome, -data) %>% # information already in title
arrange(DIC)
pander(to.table, digits=0, style='simple')
# load the results for the best model
best = filter(DIC, Difference==0)
DIC.best = bind_rows(DIC.best, best)
type = best$model
season = ifelse(best$season=='Season', TRUE, FALSE)
source('99_jags_filename.R') # create filenames for data, chains and results
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
```
The best model has a country-specific slope and season, hence we show the results for this model below.
### Table of parameter estimates for best model for weekend submissions to BMJ Open
```{r best.bmjopen.weekend.submission.results}
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
There was almost no difference in the overall probability of weekend submissions over time.
### Plot of country-specific intercepts and 95% credible intervals for weekend submissions to BMJ Open
```{r plot.intercepts.bmjopen.weekend.submissions}
source('2_plot_intercepts.R')
iplot
best.plot.bmjopen.weekend.manuscripts = iplot # store for later multi-panel plot
```
There is a very large difference between countries in the probability of weekend submissions to BMJ Open. China and Taiwan both also have relatively high probabilities of weekend submissions.
### Plot of country-specific slopes and 95% credible intervals for weekend submissions to BMJ Open
```{r plot.slopes.bmjopen.weekend.submissions}
source('2_plot_slopes.R')
splot
```
The dotted vertical line is the mean which is close to zero meaning no change across all countries. Malaysia had the largest mean increase in weekend submissions over time, but the uncertainty around this mean was large.
# Statistical models - weekend reviews
In this section we examine reviews on the weekend.
## BMJ weekend reviews
This section examines journal reviews on the weekend to the BMJ.
### Best fitting model for BMJ weekend reviews
First we examine the deviance information criterion (DIC) to find the best model
```{r best.bmj.weekend.reviews}
DIC = NULL
which.outcome = 'weekend'
which.data.text = 'reviews' # data with windows
which.data.text.update = 'reviews.weekend'
which.data = get(which.data.text.update)
which.journal = 'BMJ'
for (type in c('slope','intercept')){
for (season in c(TRUE, FALSE)){
source('99_jags_filename.R') # create filenames for data, chains and results
l = length(dir('Z:/weekend', pattern=jags.filename.results)) # flag that results exist
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
DIC = bind_rows(DIC, dic.frame)
}
}
DIC = mutate(DIC, Difference = DIC - min(DIC))
to.table = dplyr::select(DIC, -journal, -outcome, -data) %>% # information already in title
arrange(DIC)
pander(to.table, digits=0, style='simple')
# load the results for the best model
best = filter(DIC, Difference==0)
DIC.best = bind_rows(DIC.best, best) # store best DIC for later use
type = best$model
season = ifelse(best$season=='Season', TRUE, FALSE)
source('99_jags_filename.R') # create filenames for data, chains and results
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
```
### Table of parameter estimates for best model for weekend reviews to BMJ
```{r best.bmj.weekend.reviews.results}
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
There was no change in the probability of weekend reviews over time.
### Plot of country-specific intercepts and 95% credible intervals for weekend reviews to BMJ
```{r plot.intercepts.bmj.weekends.reviews}
source('2_plot_intercepts.R')
iplot
best.plot.bmj.weekend.reviews = iplot # store for later multi-panel plot
```
Finland had the lowest probability of weekend reviews and Austria the highest.
### Plot of country-specific slopes and 95% credible intervals for weekend reviews to BMJ
```{r plot.slopes.bmj.weekends.reviews}
source('2_plot_slopes.R')
splot
```
There was a relatively small variation in slopes between countries.
### Plot of seasonal estimates for weekend reviews to BMJ
```{r plot.season.bmj.weekend.reviews, fig.width=13, fig.height=6.5}
source('2_plot_season.R')
grid.arrange(mplot, seasonplot, nrow = 1)
```
The seasonal pattern was mixed. A relatively large number of countries peaked in December and January. Sweden was a notable outlier with a peak in late May.
## BMJ Open weekend reviews
This section examines journal reviews on the weekend to the BMJ Open.
### Best fitting model for BMJ Open weekend reviews
First we examine the deviance information criterion (DIC) to find the best model
```{r best.bmjopen.weekend.reviews}
DIC = NULL
which.outcome = 'weekend'
which.data.text = 'reviews' # data with windows
which.data.text.update = 'reviews.weekend'
which.data = get(which.data.text.update)
which.journal = 'BMJ Open'
for (type in c('slope','intercept')){
for (season in c(TRUE, FALSE)){
source('99_jags_filename.R') # create filenames for data, chains and results
l = length(dir('Z:/weekend', pattern=jags.filename.results)) # flag that results exist
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
DIC = bind_rows(DIC, dic.frame)
}
}
DIC = mutate(DIC, Difference = DIC - min(DIC))
to.table = dplyr::select(DIC, -journal, -outcome, -data) %>% # information already in title
arrange(DIC)
pander(to.table, digits=0, style='simple')
# load the results for the best model
best = filter(DIC, Difference==0)
if(any(DIC$Difference>0 & DIC$Difference<1)){
best = filter(DIC, Difference>0, Difference<1) # shift to second best because hardly any difference
}
DIC.best = bind_rows(DIC.best, best) # store best DIC for later use
type = best$model
season = ifelse(best$season=='Season', TRUE, FALSE)
source('99_jags_filename.R') # create filenames for data, chains and results
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R on HPC
```
There is almost a tie for the best model between a seasonal model with a country-specific slope and common slope. We choose the common slope because this is the simpler model.
### Table of parameter estimates for best model for weekend reviews to BMJ Open
```{r best.bmjopen.weekend.reviews.results}
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
There was a very small increase in weekend reviews over time.
### Plot of country-specific intercepts and 95% credible intervals for weekend reviews to BMJ Open
```{r plot.intercepts.bmjopen.weekends.reviews}
source('2_plot_intercepts.R')
iplot
best.plot.bmjopen.weekend.reviews = iplot # store for later multi-panel plot
```
There is a large variability between countries in the probability of weekend reviews. The highest probability is in Israel and the lowest in Ireland.
### Plot of seasonal estimates for weekend reviews to BMJ Open
```{r plot.season.bmjopen.weekend.reviews, fig.width=13, fig.height=6.5}
source('2_plot_season.R')
grid.arrange(mplot, seasonplot, nrow = 1)
```
There is a relatively weak season pattern of a peak in odds of over 1.02 in August. The strongest seasonal patterns are in Norway, Japan and South Korea.
# Holidays
In this section we examine the probability of submissions and reviews on national holidays. We only examine weeks that included a holiday and model the probability of a submission or review on a holiday compared with the other days in that week.
## Submissions to BMJ
```{r bmj.holiday.submission.results}
# write out filename
jags.filename.results = 'JAGS.holiday.submission.BMJ.intercept.NoSeason.results.RData'
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
### Plot of country-specific intercepts and 95% credible intervals for holiday submissions to BMJ
```{r plot.intercepts.bmj.submissions.holidays}
source('2_plot_intercepts_holiday.R')
iplot
```
## Submissions to BMJ Open
```{r bmjopen.holiday.submission.results}
# write out filename
jags.filename.results = 'JAGS.holiday.submission.BMJ Open.intercept.NoSeason.results.RData'
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
### Plot of country-specific intercepts and 95% credible intervals for holiday submissions to BMJ Open
```{r plot.intercepts.bmjopen.submissions.holidays}
source('2_plot_intercepts_holiday.R')
iplot
```
## Reviews to BMJ
```{r bmj.holiday.reviews.results}
# write out filename
jags.filename.results = 'JAGS.holiday.reviewer.BMJ.intercept.NoSeason.results.RData'
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
### Plot of country-specific intercepts and 95% credible intervals for holiday reviews to BMJ
```{r plot.intercepts.bmj.reviews.holidays}
source('2_plot_intercepts_holiday.R')
iplot
```
## Reviews to BMJ Open
```{r bmjopen.holiday.reviews.results}
# write out filename
jags.filename.results = 'JAGS.holiday.reviewer.BMJ Open.intercept.NoSeason.results.RData'
load(paste('Z:/weekend/', jags.filename.results, sep='')) # from process.jags.R
# output table
to.table = tidy.table(ests)
pander(to.table, digits=3)
```
### Plot of country-specific intercepts and 95% credible intervals for holiday reviews to BMJ Open
```{r plot.intercepts.bmjopen.reviews.holidays}
source('2_plot_intercepts_holiday.R')
iplot
```
# Late nights and early mornings
In this section we examine late nights and early mornings. We previously used a simple dichotomous definition of late nights and early mornings versus working hours, which was after 6pm or before 7am. Here we instead examine the results over the 24-hour clock and examine differences between countries.
We use a Poisson model for submissions and reviews:
$n_{h,j} \sim Poisson(\mu_{h,j}), \qquad h = 1\ldots 24, \, j=1,\ldots,C$,
where $n_{h,j}$ is the number of reviews or submissions in hour $h$ in country $j$ and there are $C$ countries in total. The regression equation is:
$\log(\mu_{h,j}) = \log(N_j) + \alpha + (\beta_h - \overline{\beta}) + \gamma_{j,1}\cos[2\pi (h-1)/24] + \gamma_{j,2}\sin[2\pi (h-1)/24]$,
where $N_j$ is an offset as it is the total number of reviews or submissions in country $j$ and $\alpha$ is the overall intercept with non-informative prior $\alpha \sim N(0, 10^4)$. The $\beta$'s are the average effect in each hour defined as:
$\beta_h \sim N(0,\tau_\beta^{-1}), \qquad h=1,\ldots, 24,$
and we subtract the overall mean $\beta$ in the regression equation so that these estimates are the difference from the average. The prior for the inverse variance uses a Gamma distribution $\tau_\beta \sim Ga(1, 1)$.
The cosine and sine functions combine to create a smooth sinusoidal wave for each country that has one peak at any time during the 24-hour clock. To ensure that the sinusoid was centred around the average, we subtracted the overall mean using:
$\gamma_{j,k} = \gamma^*_{j,k} - \overline{\gamma}_k$,
with non-informative priors for the $\gamma^*$'s:
$\gamma^*_{j,k} \sim N(0, 10^4), \qquad j = 1,\ldots,C,\, k=1,2$.
This meant that for a country with $\gamma_{j,1}=\gamma_{j,2}=0$, that country had no difference in submission or reviews times over the 24-hour clock from the overall average.
```{r, include=FALSE}
# Needed for statement below about chains
load('data/bugs.results.country.difference.Submissions.RData') # from 2_country_difference_from_average.R
# make credible intervals for amplitude
source('2_amplitude_CIs.R')
# calculate R-squared
source('2_r_square.R')
```
We used `r num.chains` chains each with `r MCMC` estimates thinned by `r thin`.
## Peak time for submissions by country
The scatter plot below shows the timing and size of the peak in reviews for each country.
```{r reconstruct.country.amplitude.phase.submissions}
# calculate the phase and amplitude of the sinusoid
cosine = data.frame(bugs.results$summary[grep('^cosine.c', row.names(bugs.results$summary)), c(1,3,7)]); names(cosine)=c('mean','lower','upper')
cosine = mutate(cosine, country.num = 1:n(),
type = 'cosine')
sine = data.frame(bugs.results$summary[grep('^sine.c', row.names(bugs.results$summary)), c(1,3,7)]); names(sine)=c('mean','lower','upper')
sine = mutate(sine, country.num = 1:n(),
type = 'sine')
# check for statistical significance - no longer used, but kept code
stat.sig = bind_rows(sine, cosine) %>%
mutate(country = country.list[country.num],
sig = lower > 0 | upper < 0) %>%
dplyr::select(country.num, country, type, sig) %>%
tidyr::spread(type, sig) %>%
mutate(stat.sig = cosine + sine > 0)
both.results.submissions = bind_rows(sine, cosine) %>%
dplyr::select(-lower, -upper) %>%
tidyr::spread(type, mean) %>%
mutate(
country = country.list[country.num],
country = ifelse(country=='United States', 'USA', country), # to reduce clutter
country = ifelse(country=='United Kingdom', 'UK', country), # to reduce clutter
phase = NA, # did not work in mutate
amp = sqrt(cosine^2 +sine^2))
both.results.submissions = left_join(both.results.submissions, dplyr::select(stat.sig, country.num, stat.sig), by="country.num") %>%
left_join(amp.stats, by="country.num") # add credible intervals for amplitude
# filter on significance or not?
# %>% filter(stat.sig == TRUE) # just the statistically significant results
for (k in 1:nrow(both.results.submissions)){
both.results.submissions$phase[k] = phasecalc(both.results.submissions$cosine[k], both.results.submissions$sine[k])
}
both.results.submissions = mutate(both.results.submissions, phase.time = 24*phase/(2*pi)) # convert phase to hours
# scatter plot
splot = ggplot(data=both.results.submissions, aes(x=phase.time, y=exp(amp), label=country))+
geom_point(col='skyblue')+
ggrepel::geom_label_repel(label.size=NA, fill='transparent')+ # avoid overlap; no border
scale_x_continuous(breaks=seq(0,24,6), limits=c(0,24), labels=c('0am','6am','12pm','6pm',''))+
xlab('Peak time (24-hour clock)')+
ylab('Probability ratio')+
scale_y_continuous(limits=c(1, NA))+ # start at 1
theme_bw()
splot
```
The R-squared of the model is `r round(rsq)`%.
### Table of peak time and height for submissions
The table below gives the same information as the above plot. The rows are ordered by the probability ratio.
```{r table.phase.amplitude.submissions}
to.table = dplyr::select(both.results.submissions, country, phase.time, meana, lowera, uppera) %>%
arrange(-meana) %>%
mutate(`95% CI` = paste(sprintf(lowera, fmt='%4.2f'), ', ', sprintf(uppera, fmt='%4.2f'), sep=''),
phase.time = floor(phase.time), # hour
phase.plus = phase.time + 1,
phase.plus = ifelse(phase.plus==24, 0, phase.plus),
phase.time = paste('[', floor(phase.time), '-', phase.plus, ')', sep=''),
meana = sprintf(meana, fmt='%4.2f')) %>% # transform to ratio
rename('Probability ratio' = 'meana',
'Peak hour'='phase.time') %>%
dplyr::select(-phase.plus, -lowera, -uppera)
pander(to.table, style='simple')
```
Submissions from China were 86% higher than the average during the hours of midnight to just before 1am. Germany had the smallest increase in submissions at just 7% higher than the average from 10am to just before 11am.
## Difference in journal submissions (late nights and early mornings)
The plot below shows the predicted means for each hour of the day for the two journals. This combines the overall estimates for each hour with the smooth sinusoid used to model the differences between the two journals.
```{r sinusoid.journal.outofhours.submission}
# reconstruct country means ##
oframe = data.frame(hour=0:23, country='Overall', country.num=0, est = bugs.results$median$intercept + bugs.results$median$beta, stringsAsFactors = FALSE)
# now get the journal specific curve
journal.smooth = bugs.results$median$cosine.j*cos(0:23*2*pi/24) +
bugs.results$median$sine.j*sin(0:23*2*pi/24)
bmj.open.ests = mutate(oframe, journal = 'BMJ Open')
bmj.ests = mutate(oframe, journal = 'BMJ', est = est + journal.smooth)
to.plot = bind_rows(bmj.open.ests, bmj.ests)
ggplot(data=to.plot, aes(x=hour+0.5, y=exp(est), col=factor(journal)))+
geom_line(size=1.1)+
scale_x_continuous(breaks=c(0,6,12,18,24), minor_breaks = 0:24)+
xlab('Hour')+
ylab('Probability')+
scale_color_manual(NULL, values = cbPalette[3:4])+
theme_bw()+
theme(legend.position = c(0.2,0.8),
panel.grid.minor.y = element_blank())
```
As the plot shows, there was little difference in the timing of reviews between the two journals. There were slightly more reviews for the BMJ Open around midday.
## Peak time for reviews by country
```{r reconstruct.country.amplitude.phase.reviews}
# get the results and calculate the phase and amplitude of the sinusoid
load('data/bugs.results.country.difference.Reviews.RData') # from 2_country_difference_from_average.R
# make credible intervals for amplitude
source('2_amplitude_CIs.R')
# calculate R-squared
source('2_r_square.R')
#
cosine = data.frame(bugs.results$summary[grep('^cosine.c', row.names(bugs.results$summary)), c(1,3,7)]); names(cosine)=c('mean','lower','upper')
cosine = mutate(cosine, country.num = 1:n(),
type = 'cosine')
sine = data.frame(bugs.results$summary[grep('^sine.c', row.names(bugs.results$summary)), c(1,3,7)]); names(sine)=c('mean','lower','upper')
sine = mutate(sine, country.num = 1:n(),
type = 'sine')
# check for statistical significance
stat.sig = bind_rows(sine, cosine) %>%
mutate(country = country.list[country.num],
sig = lower>0 | upper < 0) %>%
dplyr::select(country.num, country, type, sig) %>%
tidyr::spread(type, sig) %>%
mutate(stat.sig = cosine + sine > 0)
both.results.reviews = bind_rows(sine, cosine) %>%
dplyr::select(-lower, -upper) %>%
tidyr::spread(type, mean) %>%
mutate(
country = country.list[country.num],
country = ifelse(country=='United States', 'USA', country), # to reduce clutter
country = ifelse(country=='United Kingdom', 'UK', country), # to reduce clutter
phase = NA, # did not work in mutate
amp = sqrt(cosine^2 +sine^2))
both.results.reviews = left_join(both.results.reviews, dplyr::select(stat.sig, country.num, stat.sig), by="country.num") %>%
left_join(amp.stats, by="country.num") # add credible intervals for amplitude
# option to filter on statistical significance
#%>% filter(stat.sig == TRUE) # just the statistically significant results
for (k in 1:nrow(both.results.reviews)){