-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
1691 lines (1316 loc) · 71.7 KB
/
app.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
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
### TO DO
# - add data
# - add option to select findings and have the meta-analytical effect size calculated
# - add moderators
# - allow authors to have a second name listed in the Reference
# - repair tooltip for checker violin plot (=scatter plot); it seems that this doesn't refresh when changing the table input
# - modify summarizer so that computation of the REMLs doesn't take so long
# - discipline and effect need to be added in SoSCi
# - once the new ReD variables are set, the SoSci-Script (at least the output) needs to be corrected
source("helpers.R")
required_packages <- c(
"shiny", "readxl", "shinycssloaders", "dplyr", "DT", "ggplot2",
"forcats", "gridExtra", "reshape", "plotly", "httr",
"metafor", "openxlsx", "plyr", "pwr", "psychometric", "zcurve", "bslib", "stringr",
"rcrossref")
# Offer users to install missing packages or fail explicitly
.check_req_packages(required_packages)
# Also need plain library calls for rsconnect
library(shiny)
library(readxl)
library(shinycssloaders)
library(dplyr)
library(DT)
library(ggplot2)
library(forcats)
library(gridExtra)
#library(ggpubr)
library(reshape)
library(plotly)
library(httr)
library(metafor)
library(openxlsx)
library(plyr)
library(pwr)
library(psychometric)
library(zcurve)
library(bslib)
library(stringr)
library(rcrossref) # not needed here but listed so that it gets cited (was used to get DOIs for all original studies and some replication studies)
# BASIC INFO --------------------------------------------------------------
version <- "Version 0.4.61"
date <- "09 February, 2024" # enter last update here
forestplotheight <- "17000px" # make it so that forest plot is readable
red_link <- "https://osf.io/z5u9b/download"
source("changelog.R", local = TRUE) # Evaluate in calling environment, otherwise may fail on app start
### Variable explanations
variables <- c("description"
, "es_original"
, "es_replication"
, "n_original"
, "n_replication"
, "osf_link"
, "contributors"
, "result"
, "ref_original
", "ref_replication"
, "tags"
, "notes")
explanations <- c("Short description of the main phenomenon/hypothesis of the replication study"
, "Original effect size converted to Bravais Pearson correlation"
, "Replication effect size converted to Bravais Pearson correlation"
, "Original sample size"
, "Replication sample size"
, "Link to the OSF project or post-completion results report"
, "Contributors of the replication study (first name, last name; separated by comma)"
, "Result of the replication study (informative failure to replicate, informative success to replciate, or inconclusive"
, "Full APA7 reference to the report describing the original study (including study number if necessary)"
, "Full APA7 reference to the report describing the replication study (if possible; including study number if necessary)"
, "Tags to make the study easily findable"
, "Any further notes")
dataset_variables <- data.frame("Variable" = variables, "Description" = explanations)
# DATA --------------------------------------------------------------------
## Static dataset ----------------------------------------------------------
message("Loading data")
data_file <- tempfile(fileext = ".xlsx")
download.file(red_link, data_file)
# Open processed dataset
red <- openxlsx::read.xlsx(data_file, sheet = "Data") # .xlsx file
red <- red[-(1:2), ] # exclude labels and "X" column
# additional studies
as <- openxlsx::read.xlsx(data_file, sheet = "Additional Studies to be added", startRow = 2)
as$id <- paste("uncoded_studies_", rownames(as), sep = "")
forrt <- openxlsx::read.xlsx(data_file, sheet = "FORRT R&R (editable)", startRow = 1)
forrt <- forrt[-(1:2), ] # exclude labels and "X" column
message("Loaded data")
## Submissions ------------------------------------------------------
# ### comment this in to have data from the submission portal downloaded directly into the app; note that some of the code is deprecated and should be replaced by code from soscisubmissions.R
# link <- "https://www.soscisurvey.de/replicate/?act=BhquqCVmVnqokhQEVCCaAfrS"
# rd <- read.csv(link, sep = "\t", encoding = "latin1", na.strings = "-9")[1:4, ] # only read first 4 lines so that the app cannot be broken by r > 1 or similar entries XXX
#
# # rd[rd == -9] <- NA # replace -9 values with NAs
#
# rd <- rd[!is.na(rd$EN02_05), ] # remove empty entries
# rd <- rd[rd$STARTED != "2023-03-10 14:06:34", ]
#
# rd$n_original <- as.numeric(rd$EN02_05)
# rd$n_replication <- as.numeric(rd$EN02_06)
# rd$ref_original <- rd$EN01_01
# rd$ref_replication <- rd$EN01_02
# rd$es_orig_value <- as.numeric(as.character(gsub("\'", "", rd$EN02_01)))
# rd$es_rep_value <- as.numeric(as.character(gsub("\'", "", rd$EN02_02)))
# rd$es_orig_estype <- rd$EN02_03
# rd$es_rep_estype <- rd$EN02_04
# rd$published_rep <- rd$EN03-1
# rd$validated <- NA
# rd$validated_person <- ""
# rd$description <- rd$EN04_01
# rd$contributors <- rd$EN05_01
# rd$result <- dplyr::recode(rd$EN08, "1" = "success", "2" = "informative failure to replicate", "3" = "practical failure to replicate", "4" = "inconclusive")
# rd$id_sample <- ifelse(rd$EN09 == "1", paste("sosci_", row_number(rd$EN09), sep = "")
# , paste("sosci_", row_number(rd$EN09), "_sample", gsub(" ", ".", rd$EN09_02), sep = ""))
# rd$id <- rd$id_sample
# rd$osf_link <- rd$EN10_01
# rd$notes <- rd$EN11_01
# rd$same_design <- as.numeric(dplyr::recode(rd$EN12_01, "1" = "0", "2" = "1"))
# rd$same_test <- as.numeric(dplyr::recode(rd$EN12_02, "1" = "0", "2" = "1"))
# rd$original_authors <- as.numeric(dplyr::recode(rd$EN14, "1" = "0", "2" = "1"))
# rd$tags <- gsub(", ,", "", paste(rd$EN06_01 # put tags behind each other and avoid empty tags (", ,")
# , rd$EN06_02
# , rd$EN06_03
# , rd$EN06_04
# , rd$EN06_05
# , sep = ", "))
# rd$date_entered <- rd$LASTDATA
# rd$preregistration <- rd$EN13_01
# rd$closeness_instructions <- rd$EN27_01
# rd$closeness_measures <- rd$EN27_02
# rd$closeness_stimuli <- rd$EN27_03
# rd$closeness_procedure <- rd$EN27_04
# rd$closeness_location <- rd$EN27_05
# rd$closeness_renumeration <- rd$EN27_06
# rd$closeness_participants <- rd$EN27_07
# rd$closeness_exclusions <- rd$EN27_08
# rd$closeness_language <- rd$EN27_09
# rd$closeness_nationality <- rd$EN27_10
# rd$differences <- rd$EN28_01
# rd$source <- "Individual submissions"
#
# # remove cryptic variables
# rd <- rd[ , 46:ncol(rd)]
#
# numeric_variables <- c("n_original"
# , "n_replication"
# , "es_orig_value"
# , "es_rep_value"
# , "validated"
# , "published_rep"
# , "same_design"
# , "same_test"
# , "original_authors"
# # , "es_original"
# # , "es_replication"
# # , "ci.lower_original"
# # , "ci.upper_original"
# # , "ci.lower_replication"
# # , "ci.upper_replication"
# # , "significant_original"
# # , "significant_replication"
# # , "power"
# # , "es_orig"
# # , "es_rep"
# # , "es_orig_RRR"
# # , "es_rep_RRR"
# )
#
# rd[, numeric_variables] <- sapply(rd[ , numeric_variables], as.numeric)
#
#
#
#
#
# ## Merge datasets ----------------------------------------------------------
#
# red <- base::merge(rd, red, all = TRUE)
numeric_variables <- c("n_original"
, "n_replication"
, "es_orig_value"
, "es_rep_value"
, "validated"
, "published_rep"
, "same_design"
, "same_test"
, "original_authors"
, "es_original"
, "es_replication"
, "ci.lower_original"
, "ci.upper_original"
, "ci.lower_replication"
, "ci.upper_replication"
, "significant_original"
, "significant_replication"
, "power"
# , "es_orig"
# , "es_rep"
, "es_orig_RRR"
, "es_rep_RRR"
)
red[, numeric_variables] <- sapply(red[ , numeric_variables], as.numeric)
# exclusions
red <- red[is.na(red$exclusion), ] # remove entries with reasons for exclusions
## Compute dataset values --------------------------------------------------
# remove effect size types for which conversion is not integrated yet
# red <- red[tolower(red$es_orig_estype) %in% (c("or", "r", "η²" ,"r²", "d")), ]
# red <- red[!is.na(red$es_orig_estype)]
#
# red <- red[tolower(red$es_orig_estype) %in% (c("or", "r", "η²" ,"r²", "d")), ]
# red <- red[!is.na(red$es_orig_estype)]
## convert effect sizes
# original
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "or", "es_original"] <- try(esc::pearsons_r(or = red[!is.na(red$es_orig_estype) & red$es_orig_estype == "OR", "es_orig_value"]), silent = TRUE)
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "d", "es_original"] <- try(esc::pearsons_r(d = red[!is.na(red$es_orig_estype) & red$es_orig_estype == "d", "es_orig_value"]), silent = TRUE)
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "η²", "es_original"] <- try(esc::pearsons_r(eta = red[!is.na(red$es_orig_estype) & red$es_orig_estype == "η²", "es_orig_value"]), silent = TRUE)
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "etasq", "es_original"] <- try(esc::pearsons_r(eta = red[!is.na(red$es_orig_estype) & red$es_orig_estype == "etasq", "es_orig_value"]), silent = TRUE)
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "r", "es_original"] <- try( red[!is.na(red$es_orig_estype) & red$es_orig_estype == "r", "es_orig_value"], silent = TRUE)
red[!is.na(red$es_orig_estype) & tolower(red$es_orig_estype) == "r²", "es_original"] <- try(sqrt( red[!is.na(red$es_orig_estype) & red$es_orig_estype == "r²", "es_orig_value"]), silent = TRUE)
# replication
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "or", "es_replication"] <- try(esc::pearsons_r(or = red[!is.na(red$es_rep_estype) & red$es_rep_estype == "OR", "es_rep_value"]), silent = TRUE)
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "d", "es_replication"] <- try(esc::pearsons_r(d = red[!is.na(red$es_rep_estype) & red$es_rep_estype == "d", "es_rep_value"]), silent = TRUE)
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "η²", "es_replication"] <- try(esc::pearsons_r(eta = red[!is.na(red$es_rep_estype) & red$es_rep_estype == "η²", "es_rep_value"]), silent = TRUE)
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "etasq", "es_replication"] <- try(esc::pearsons_r(eta = red[!is.na(red$es_rep_estype) & red$es_rep_estype == "etasq", "es_rep_value"]), silent = TRUE)
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "r", "es_replication"] <- try( red[!is.na(red$es_rep_estype) & red$es_rep_estype == "r", "es_rep_value"], silent = TRUE)
red[!is.na(red$es_rep_estype) & tolower(red$es_rep_estype) == "r²", "es_replication"] <- try(sqrt( red[!is.na(red$es_rep_estype) & red$es_rep_estype == "R²", "es_rep_value"]), silent = TRUE)
## compute effect sizes from test statistics
# # original, f
# red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "f", "es_original"] <- try(esc::esc_f(f =
# as.numeric(sub(".*=", "\\1", red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "f", "teststatistic_orig"]))
# , totaln = as.numeric(red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "f", "n_original"]), es.type = "r"), silent = TRUE)
#
# # replication f
# red[!is.na(red$teststatistic_rep) & is.na(red$es_replication) & tolower(substr(red$teststatistic_rep,1 ,1)) == "f", "es_replication"] <- try(esc::esc_f(f =
#
# # original, t
# red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "t", "es_original"] <- try(esc::esc_t(t = as.numeric(sub(".*=", "\\1", red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "t", "teststatistic_orig"])), totaln = as.numeric(red[!is.na(red$teststatistic_orig) & is.na(red$es_original) & tolower(substr(red$teststatistic_orig,1 ,1)) == "t", "n_original"]), es.type = "r"), silent = TRUE)
# # replication t
# red[!is.na(red$teststatistic_rep) & is.na(red$es_replication) & tolower(substr(red$teststatistic_rep,1 ,1)) == "t", "es_replication"] <- try(esc::esc_t(t = as.numeric(sub(".*=", "\\1", red[!is.na(red$teststatistic_rep) & is.na(red$es_replication) & tolower(substr(red$teststatistic_rep,1 ,1)) == "t", "teststatistic_rep"])), totaln = as.numeric(red[!is.na(red$teststatistic_rep) & is.na(red$es_replication) & tolower(substr(red$teststatistic_rep,1 ,1)) == "t", "n_replication"]), es.type = "r"), silent = TRUE)
# windsorize values
red$es_original <- ifelse(red$es_original > 1, 1, ifelse(red$es_original < -1, -1, red$es_original))
red$es_replication <- ifelse(red$es_replication > 1, 1, ifelse(red$es_replication < -1, -1, red$es_replication))
# compute standared error for correlations
red$vi_orig <- metafor::escalc(ri = red$es_original, ni = red$n_original, measure = "COR")$vi
red$vi_rep <- metafor::escalc(ri = red$es_replication, ni = red$n_replication, measure = "COR")$vi
# recode variables for app to work
red$pc_tags <- NA
red$pc_contributors <- NA
red$description <- ifelse(is.na(red$description), "", red$description)
red$contributors <- ifelse(is.na(red$contributors), red$pc_contributors, red$contributors)
red$tags <- ifelse(is.na(red$tags), red$pc_tags, red$tags)
red$subjects <- NA
red$description <- ifelse(is.na(red$description), red$pc_title, red$description)
red$closeness <- NA
red$result <- ifelse(red$result == "0", NA, red$result)
# make it so that original effects are always positive and replication effects are positive if they are in the same direction as the original finding
red$es_replication <- ifelse(red$es_original < 0, red$es_replication * -1, red$es_replication)
red$es_original <- abs(red$es_original)
# compute year the original study was published
red$orig_year <- as.numeric(substr(gsub("\\D", "", red$ref_original), 1, 4))
red$orig_year <- ifelse(red$orig_year > 2100, NA, red$orig_year)
# # delete duplicates and non-replication studies
red <- red[red$notes != "duplicate" | is.na(red$notes), ] # ADDED: study exclusions due to duplicates
red <- red[red$notes != "No actual replication conducted" | is.na(red$notes), ] # ADDED: some registrations had no corresponding replication study
# compute CIs
for (i in 1:nrow(red)) {
# original effect
ci_original <- psychometric::CIr(r = as.numeric(red[i, "es_original"]), n = as.numeric(red[i, "n_original"]))
red[i, "ci.lower_original"] <- ci_original[1]
red[i, "ci.upper_original"] <- ci_original[2]
# replication effect
ci_replication <- psychometric::CIr(r = as.numeric(red[i, "es_replication"]), n = as.numeric(red[i, "n_replication"]))
red[i, "ci.lower_replication"] <- ci_replication[1]
red[i, "ci.upper_replication"] <- ci_replication[2]
}
red$significant_original <- as.factor(ifelse(red$ci.lower_original > 0 | red$ci.upper_original < 0, "1", "0"))
red$significant_replication <- as.factor(ifelse(red$ci.lower_replication > 0 | red$ci.upper_replication < 0, "1", "0"))
for (i in 1:nrow(red)) {
if ( !is.na(red[i, "es_original"]) & !is.na(red[i, "n_replication"]) ) {
red[i, "power"] <- pwr::pwr.r.test(n = red[i, "n_replication"], r = red[i, "es_original"]
, power = NULL, alternative = "greater")$power
}
}
red$power <- round(red$power, digits = 3)
## validate entries
red$validated <- ifelse(red$validated == 1 | red$validated == 2, 1, red$validated) # 2: error detected and corrected
### code result with alternative terminology by Lebel et al., 2018; https://etiennelebel.com/documents/lebeletal%282018,ampss%29a-unified-framework-to-quantify-the-credibility-of-scientific-findings.pdf
# signal / no signal
red$signal <- ifelse(red$significant_replication == 1, "signal", "no signal")
red$consistent <- NULL
# # consistent / smaller / larger
# # is.na(red$significant_original) | is.na(red$significant_replication) | red$significant_original == 0 # NA
# # red$ci.upper_replication > red$es_original & red$ci.lower_replication < red$es_original # consistent
# # red$signal == "signal" & red$ci.lower_replication > red$es_original # inconsistent, larger
# # red$signal == "signal" & red$ci.upper_replication < red$es_original # inconsistent, smaller
# # red$signal == "signal" & red$es_replication < 0 # inconsistent, opposite
# # red$signal == "no signal" & red$ci.upper_replication > red$es_original # consistent
# # red$signal == "no signal" & red$significant_replication == 0 # inconsistent
#
# # is.na(red$significant_original) | is.na(red$significant_replication) | red$significant_original == 0 ~ "OS n.s."
# # , red$ci.upper_replication > red$es_original & red$ci.lower_replication < red$es_original ~ "consistent"
# # , red$signal == "signal" & red$ci.lower_replication > red$es_original ~ "inconsistent, larger"
# # , red$signal == "signal" & red$ci.upper_replication < red$es_original ~ "inconsistent, smaller"
# # , red$signal == "signal" & red$es_replication < 0 ~ "inconsistent, opposite"
# # , red$signal == "no signal" & red$ci.upper_replication > red$es_original ~ "consistent"
# # , red$signal == "no signal" & red$significant_replication == 0 ~ "inconsistent"
red <- dplyr::mutate(red, consistent = case_when(
is.na(red$significant_original) | is.na(red$significant_replication) | red$significant_original == 0 ~ "OS n.s."
, red$ci.upper_replication > red$es_original & red$ci.lower_replication < red$es_original ~ "consistent"
, red$signal == "signal" & red$ci.lower_replication > red$es_original ~ "inconsistent, larger"
, red$signal == "signal" & red$ci.upper_replication < red$es_original ~ "inconsistent, smaller"
, red$signal == "signal" & red$es_replication < 0 ~ "inconsistent, opposite"
, red$signal == "no signal" & red$ci.upper_replication > red$es_original ~ "consistent"
, red$signal == "no signal" & red$significant_replication == 0 ~ "inconsistent"
))
red$result <- ifelse(as.numeric(red$significant_original) == 1 & as.numeric(red$significant_replication) == 1, "success", red$result)
red$result2 <- paste(red$signal, red$consistent, sep = " - ")
table(red$result2)
### Values for Z-Curve analysis
## compute standard error
red$se <- sqrt((1-abs(red$es_original)^2)/(red$n_original-2))
## compute z-score
red$z <- abs(red$es_original/red$se)
# create datasets for filtering and display
red_temp <- red
red_display <- red[, c("description", "es_original", "es_replication", "n_original", "n_replication", "osf_link", "contributors", "result", "result2", "ref_original", "ref_replication")]
red_display$es_original <- round(red_display$es_original, 3)
red_display$es_replication <- round(red_display$es_replication, 3)
red$ref_original <- gsub("(.{70,}?)\\s", "\\1\n", red$ref_original) # line breaks
# WEBSITE TEXT --------------------------------------------------------------
message("Source text")
source("website_text.R", local = TRUE) # Evaluate in calling environment, otherwise fails on app start
message("Sourced text")
## Add custom theme (formatting)
custom_theme <- bs_theme(
version = 5,
bg = "#FFFFFF",
fg = "#382f2f",
primary = "#a62828",
secondary = "#FF374B",
base_font = "Calibri"
)
# APP ----------------------------------------------------------------------
ui <- fluidPage(
theme = custom_theme
, navbarPage(title = ""
, tabPanel(img(src = "fred.png", height = 67/2.5, width = 715/2.5), fluidRow(
column(6, info)
))
, tabPanel("Replicability Tracker"
, fluidRow(
sidebarPanel(
# textInput("titles", "Titles (e.g., Heat-Priming):")
# , textInput("tags", "Tags (e.g., anchoring):")
# , textInput("contributors", "Contributors (e.g., Smith):")
sliderInput("minpower", "Minimum Power", min = .05, max = .999, value = .05)
, selectInput("source", "Browse Large-Scale Projects:"
, choices = c("All studies" = "All studies"
, "Individual submissions" = "Individual submissions"
, "FORRT Replications and Reversals" = "FORRT"
, "CORE (Feldman JDM Replications)" = "CORE"
, "CRSP special issue"
, "Data Replicada" = "datareplicada"
, "Many Labs 1" = "ML1"
, "Many Labs 2" = "ML2"
, "Many Labs 3" = "ML3"
, "OpAQ (Anchoring Effects)" = "OpAQ"
, "OpenMKT.org Replications Catalog" = "openmkt"
, "OSF Registries" = "OSF Registries"
, "Reproducibility Project Psychology (OSC, 2015)" = "OSC 2015"
, "RRR1 (verbal overshadowing)" = "RRR1"
# , "RRR2 (X)" = "RRR2"
, "RRR3 (grammar on intentionality effect)" = "RRR3"
, "RRR4 (ego depletion)" = "RRR4"
, "RRR8 (professor priming)" = "RRR8"
, "RRR9 (hostility priming)" = "RRR9"
, "Soto (Big5 Correlations)" = "Soto"
, "SSRP (Camerer et al., 2018)" = "SSRP"
)
, selected = "All studies")
, checkboxInput("validated", "Show validated entries only", value = TRUE)
, checkboxInput("codedentries", "Show coded entries only", value = TRUE)
, width = 2)
, column(8
, dataset_info
# Red-and-green Barplot
, withSpinner(plotly::plotlyOutput("barplot", width = "100%", height = "250px"))
# Table for filtering
, withSpinner(DT::DTOutput("table"))
# RPP-Scatterplot
, scatterplot_title
, withSpinner(plotly::plotlyOutput("overviewplot", width = "100%", height = 800))
, scatterplot_explanation
# Barplot 2
, barplot2_title
, withSpinner(plotly::plotlyOutput("barplot2", width = "100%", height = "250px"))
, barplot2_explanation
# Z-Curve
, breaks
, zcurve_title, breaks
, withSpinner(shiny::plotOutput("zcurve_plot"))
, zcurve_explanation, breaks
# , withSpinner(shiny::tableOutput("overview")), dataset_info1b
)))
, tabPanel("Study Overview"
, fluidRow(
column(8, forest_info, withSpinner(plotly::plotlyOutput("forestplot", width = "100%", height = forestplotheight)))
# , withSpinner(shiny::tableOutput("overview")), dataset_info1b
))
, tabPanel("Dataset", dataset_explanation, breaks
, downloadButton("reddownload", label = "Download dataset")
, breaks
, dataset_headline
, withSpinner(DT::DTOutput("dataset"))
, breaks
, variables_headline
, withSpinner(DT::DTOutput("variables"))
)
, tabPanel("Correlates of Replicability"
, correlates_info
, correlates_decade
, withSpinner(plotly::plotlyOutput("correlate_decade"))
, correlates_journal
, withSpinner(plotly::plotlyOutput("correlate_journal", width = "100%", height = "2000px"))
)
, tabPanel("Moderators [alpha]"
, moderators_info
, shiny::selectInput("moderator", label = "Moderators"
, choices = list(
"Original Effect Size" = "es_original"
, "Journal" = "orig_journal"
, "Year of Original Publication" = "orig_year"
, "Power of Replication Study" = "power"
))
, fluidRow(withSpinner(plotly::plotlyOutput("flexibleplot", width = "100%", height = 600))
)
, fluidRow(
column(6, withSpinner(DT::DTOutput("flexiblemodtable")))
, column(6, withSpinner(shiny::htmlOutput("flexiblemoderatortext")))
)
)
# , tabPanel("Summarizer [alpha]"
# , fluidRow(
# column(12
# , checker_info
# , withSpinner(DT::DTOutput("checkertable"))
# , withSpinner(DT::DTOutput("flexiblecheckertable"))
# , withSpinner(shiny::htmlOutput("flexiblesummarizertext"))
# ), column(6
#
# , withSpinner(plotly::plotlyOutput("checker_violin", width = "100%", height = "400px"))
# )
# , column(6
# # , withSpinner(plotly::plotlyOutput("checker_maplot")
# , withSpinner(plotly::plotlyOutput("checker_bar")
# # , checker_matable
# )
# )
# ))
, tabPanel("References-Checker [alpha]"
, rc_info
, textAreaInput("refcheck", "References"
, value = "Judge, T. A., & Bono, J. E. (2000). Five-factor model of personality and transformational leadership. Journal of Applied Psychology, 85, 751-765. 10.1037/0021-9010.85.5.751"
, width = "1000px"
, height = "200px"
, placeholder = NULL
)
, withSpinner(plotly::plotlyOutput("references_barplot"))
, withSpinner(tableOutput("references_doi"))
)
, tabPanel("References"
, references_headline, references_list
, references_redpublications, references_list_redpublications
, packages_headline, packages_list
)
, tabPanel("FAQ"
, faqs
)
, tabPanel("About"
, about, breaks
, img(src = "ub.png", height = 100)
, img(src = "um.png", height = 50)
, img(src = "nwo.png", height = 100)
, breaks
, breaks
, changelog
, img(src = "fred.png", height = 80)
# , breaks
# , img(src = "FORRT.svg", height = 100)
, tags$style(HTML("
.navbar-default .navbar-brand {color:black;}
.navbar-default .navbar-brand:hover {color:black;}
.navbar { background-color:#EAEAEA;}
.navbar-default .navbar-nav > li > a {color: dark grey;}
.navbar-default .navbar-nav > .active > a,
.navbar-default .navbar-nav > .active > a:focus,
.navbar-default .navbar-nav > .active > a:hover {color:black;background-color:#fc2d2d;}
.navbar-default .navbar-nav > li > a:hover {color:black;background-color:#A6A6A6;text-decoration}
"))
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
# Overview Table ----------------------------------------------------------
output$table <- DT::renderDT(server = FALSE, {
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
red_temp <- red_temp[red_temp$power >= input$minpower, ]
# source
if (input$source == "All studies") {
red_temp <- red_temp
} else {
red_temp <- red_temp[red_temp$source == input$source, ]
}
# validated
if (input$validated == TRUE) {
red_temp <- red_temp[!is.na(red_temp$validated), ]
}
# only show show coded entries?
if (input$codedentries == TRUE) {
red_temp <- red_temp[!is.na(red_temp$result), ]
}
red_temp[is.na(red_temp$result), "result"] <- "not coded"
# exclude NAs
# red_temp <- red_temp[!is.na(red_temp$result), ]
# red_temp_filtered <- red_temp[, c("description", "n_original", "n_replication", "power", "result")]
red_temp_filtered <- red_temp[, c("description", "tags", "contributors"
# , "es_original", "es_replication"
, "result", "ref_original", "ref_replication")]
DT::datatable(
red_temp_filtered
, extensions = "Buttons"
, selection = "none"
, options = list(scrollX = TRUE
, dom = "Bfrtip"
, buttons = c('copy', 'csv', 'excel')
, pageLength = 5
# , lengthMenu = c(5, 10, 100) # XXX not working yet
), rownames = FALSE
# , options = list(pageLength = 5)
# , rownames = FALSE
)
# DT::datatable(
# red_temp[, c("description", "tags", "result", "ref_original", "ref_replication")]
# , extensions = "Buttons"
# , options = list(scrollX = TRUE
# , dom = "Bfrtip"
# , buttons = c('copy', 'csv', 'excel')
# , pageLength = 5
# # , lengthMenu = c(5, 10, 100) # XXX not working yet
# ), rownames = FALSE
# )
}
)
# Overview Plot -----------------------------------------------------------
output$overviewplot <- plotly::renderPlotly({
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
red_temp <- red_temp[red_temp$power >= input$minpower, ]
# source
if (input$source == "All studies") {
red_temp <- red_temp
} else {
red_temp <- red_temp[red_temp$source == input$source, ]
}
# validated
if (input$validated == TRUE) {
red_temp <- red_temp[!is.na(red_temp$validated), ]
}
# exclude NAs
red_temp <- red_temp[!is.na(red_temp$result), ]
red_temp$significant_original <- as.factor(red_temp$significant_original)
red_temp$significant_replication <- as.factor(red_temp$significant_replication)
## Choose only entries that are also displayed in the table
s1 <- input$table_rows_current # rows on the current page
s2 <- input$table_rows_all # rows on all pages (after being filtered)
s3 <- input$table_rows_selected # selected rows
red_temp <- red_temp[s2, ]
red_temp$scatterplotdescription <- paste(red_temp$description, "\nr(original) = "
, round(red_temp$es_original, 3)
, ", r(replication) = "
, round(red_temp$es_replication, 3)
, sep = "")
pointsize <- ifelse(nrow(red_temp) < 10, 5, ifelse(nrow(red_temp) < 100, 4, 3))
scatterplot <-
ggplot(red_temp, aes(x = es_original, y = es_replication, text = scatterplotdescription)) +
geom_hline(aes(yintercept = 0),linetype = 2) +
geom_abline(intercept = 0, slope = 1, color = "Grey60") +
geom_point(aes(fill = significant_replication), color = "Grey30", shape = 21, alpha = .8) +
# geom_point(aes(size = power, fill=significant_replication), color = "Grey30", shape = 21,alpha = .8) +
geom_point(aes(fill = significant_replication), size = pointsize, color="Grey30", shape = 21, alpha = .8) +
# highlighted studies
# geom_point(data = red_temp[s3, ], mapping = aes(size = power), fill= "Grey30",color="Grey30",shape=4) +
geom_point(data = red_temp[s3, ], fill = "#0077d9",color = "#f2ef1b", shape = 4) +
geom_rug(aes(color=significant_original),size=1,sides="b",alpha=.6) +
geom_rug(aes(color=significant_replication),size=1,sides="l",alpha=.6) +
scale_x_continuous(name="Original Effect Size",limits=c(0,1),breaks=c(0,.25,.5,.75,1)) +
scale_y_continuous(name="Replication Effect Size",limits=c(-.5,1),breaks=c(-.5,-.25,0,.25,.5,.75,1)) +
# ggtitle("") + #xlab("") + ylab("") +
# scale_size_continuous(name="Power",range=c(.5,3.5)) +
scale_color_discrete(guide = "none") +
scale_fill_discrete(guide = "none") +
theme_bw() +
# theme(legend.position=c(.9,.6), plot.margin = unit(c(-2,-1.5,2,2), "lines")) +
theme(legend.position = "none")
overviewplotly <- plotly::ggplotly(scatterplot, tooltip = "text") %>% plotly::config(displayModeBar = FALSE) %>%
layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE))
}) # , height = 800
# Forest Plot -------------------------------------------------------------
output$forestplot <- plotly::renderPlotly({
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
# use only studies with a replication effect size
red_temp <- red_temp[!is.na(red_temp$es_replication), ]
# use only studies with a reference for the original finding
red_temp <- red_temp[!is.na(red_temp$ref_original), ]
# make descriptions shorter
red_temp$description <- gsub("(.{70,}?)\\s", "\\1\n", red_temp$description) # line breaks
# make reference shorter
red_temp$ref_original <- gsub("(.{70,}?)\\s", "\\1\n", red_temp$ref_original) # line breaks
red_temp_selected <- red_temp
xlims <- seq(from = -1, 1, .25)
red_temp$description <- factor(red_temp$description, levels = unique(red_temp$description[order(red_temp$es_replication)]))
forest <- ggplot(data = red_temp, aes(x = es_replication, y = ref_original)) +
geom_vline(xintercept = 0, col = "dark grey", lwd = 1) +
# Replication effect sizes
geom_point() +
geom_errorbar(aes(xmin = ci.lower_replication, xmax = ci.upper_replication)) +
# Original effect sizes
geom_point(aes(x = es_original, y = ref_original), color = "dark grey", alpha = .5) +
geom_errorbar(aes(xmin = ci.lower_original, xmax = ci.upper_original), color = "dark grey") +
# highlighted studies
geom_point(data = red_temp_selected, aes(x = es_replication, y = ref_original), color = ifelse(nrow(red_temp) == nrow(red_temp_selected), "black", "red")) +
# Theme and formatting
theme_classic() + geom_vline(xintercept = xlims, col = rgb(0,0,0,.05), lwd = 0.5, lty = 1) +
theme(text = element_text(size = 14)) +
xlim(c(floor(min(red_temp$ci.lower_original)), ceiling(max(red_temp$ci.upper_original, na.rm = TRUE)))) +
xlab("r") +
ylab("") +
theme(legend.position="none") +
theme(text = element_text(size = 10)) +
scale_y_discrete(limits=rev) +
ggtitle(paste("Blobbogram\n"
, sum(!is.na(red_temp$es_original))
, "Effect sizes available.\n"
# , length(unique(red_temp$ref_original))
# , "Original studies were examined in replication studies."
))
p <- ggplotly(forest) %>%
plotly::config(displayModeBar = FALSE) %>%
layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE)) # %>% layout(height = 10000, width = 1200)
})
# Bar Plot -------------------------------------------------------------
output$barplot <- plotly::renderPlotly({
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
red_temp <- red_temp[red_temp$power >= input$minpower, ]
# source
if (input$source == "All studies") {
red_temp <- red_temp
} else {
red_temp <- red_temp[red_temp$source == input$source, ]
}
# validated
if (input$validated == TRUE) {
red_temp <- red_temp[!is.na(red_temp$validated), ]
}
# only show show coded entries?
if (input$codedentries == TRUE) {
red_temp <- red_temp[!is.na(red_temp$result), ]
}
red_temp[is.na(red_temp$result), "result"] <- "not coded"
# exclude NAs
# red_temp <- red_temp[!is.na(red_temp$result), ]
## Choose only entries that are also displayed in the table
s1 <- input$table_rows_current # rows on the current page
s2 <- input$table_rows_all # rows on all pages (after being filtered)
s3 <- input$table_rows_selected # selected rows
red_temp <- red_temp[s2, ]
bardata <- as.data.frame(base::table(red_temp$result, useNA = "always")/nrow(red_temp))
names(bardata) <- c("Result", "Proportion")
bardata$Proportion <- round(bardata$Proportion, 4)*100
bardata$description <- paste(bardata$Result, ": ", bardata$Proportion, "%", sep = "")
barchart <- ggplot(bardata, aes(x = "", fill = Result, y = Proportion, text = description)) + geom_bar(position = "fill", stat = "identity") +
theme_bw() + ylab("Percentage") + xlab("") + coord_flip() +
scale_fill_manual("Result", values = c(
"success" = "#30c25a"
, "informative failure to replicate" = "#f0473e"
, "practical failure to replicate" = "#f2bbb8"
, "inconclusive" = "#60bef7")) + # , NA = "grey"
ggtitle(paste(nrow(red_temp), "of", nrow(red), "studies selected."))
p <- ggplotly(barchart, tooltip = "text") %>%
plotly::config(displayModeBar = FALSE) %>%
layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE)) # %>% layout(height = 10000, width = 1200)
})
# Barplot Result2 ---------------------------------------------------------
output$barplot2 <- plotly::renderPlotly({
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
# # text inputs
# if (nchar(input$tags) > 0) {
# red_temp <- red_temp[grepl(tolower(as.character(input$tags)), tolower(red_temp$tags)), ]
# }
#
# if (nchar(input$titles) > 0) {
# red_temp <- red_temp[grepl(tolower(as.character(input$titles)), tolower(red_temp$description)), ]
# }
#
# if (nchar(input$contributors) > 0) {
# red_temp <- red_temp[grepl(tolower(as.character(input$contributors)), tolower(red_temp$contributors)), ]
# }
red_temp <- red_temp[red_temp$power >= input$minpower, ]
# source
if (input$source == "All studies") {
red_temp <- red_temp
} else {
red_temp <- red_temp[red_temp$source == input$source, ]
}
# validated
if (input$validated == TRUE) {
red_temp <- red_temp[!is.na(red_temp$validated), ]
}
## Exclude NAs
red_temp <- red_temp[!is.na(red_temp$result2), ]
## Choose only entries that are also displayed in the table
s1 <- input$table_rows_current # rows on the current page
s2 <- input$table_rows_all # rows on all pages (after being filtered)
s3 <- input$table_rows_selected # selected rows
red_temp <- red_temp[s2, ]
bardata <- as.data.frame(base::table(red_temp$result2, useNA = "always")/nrow(red_temp))
names(bardata) <- c("Result", "Proportion")
bardata$Proportion <- round(bardata$Proportion, 4)*100
bardata$description <- paste(bardata$Result, ": ", bardata$Proportion, "%", sep = "")
barchart <- ggplot(bardata, aes(x = Result, fill = Result, y = Proportion, text = description)) +
geom_bar(stat = "identity") +
theme_bw() + ylab("Percentage") + xlab("") + coord_flip() +
scale_fill_manual("Result", values = c(
"no signal - inconsistent" = "#9c0505"
, "signal - consistent" = "#05e361"
, "no signal - OS n.s." = "grey"
, "NA - OS n.s." = "grey"
, "signal - inconsistent, smaller" = "#a4d11b"
, "signal - inconsistent, larger" = "#77bd06"
, "signal - OS n.s." = "grey"
, "no signal - consistent" = "#b4d4a5"
# , "NA" = "grey"
)) + # , NA = "grey"
ggtitle(paste(nrow(red_temp), "of", nrow(red), "studies selected."))
p <- ggplotly(barchart, tooltip = "text") %>%
plotly::config(displayModeBar = FALSE) %>%
layout(xaxis = list(fixedrange = TRUE), yaxis = list(fixedrange = TRUE)) # %>% layout(height = 10000, width = 1200)
})
# Z-Curve -----------------------------------------------------------------
output$zcurve_plot <- shiny::renderPlot({
## apply filters
red_temp <- red
red_temp <- red_temp[rev(row.names(red_temp)), ]
red_temp <- red_temp[red_temp$power >= input$minpower, ]
# source
if (input$source == "All studies") {
red_temp <- red_temp
} else {
red_temp <- red_temp[red_temp$source == input$source, ]
}
# validated
if (input$validated == TRUE) {
red_temp <- red_temp[!is.na(red_temp$validated), ]
}
# exclude NAs
red_temp <- red_temp[!is.na(red_temp$result), ]
## Choose only entries that are also displayed in the table
s1 <- input$table_rows_current # rows on the current page
s2 <- input$table_rows_all # rows on all pages (after being filtered)
s3 <- input$table_rows_selected # selected rows
red_temp <- red_temp[s2, ]
# # make descriptions shorter
# red_temp$description <- gsub("(.{70,}?)\\s", "\\1\n", red_temp$description) # line breaks
# use only studies with complete data
red_temp <- red_temp[!is.na(red_temp$z), ]
# run z-curve analysis
zc <- zcurve::zcurve(z = red_temp$z, method = "EM", bootstrap = 0)
orr <- round(mean(red_temp$result == "success", na.rm = TRUE), 2)
err <- zc$coefficients[1]
# create plot
zcurve::plot.zcurve(zc, annotation = TRUE, CI = TRUE, main = paste("Observed Replication Rate: ", orr
# , "\nCorrected ERR: ", round(1.85*err-0.573, digits = 2)
, sep = ""))