forked from marton-balazs-kovacs/Weissman-replication-script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeissman-replication-analysis.Rmd
More file actions
2080 lines (1691 loc) · 69 KB
/
Copy pathWeissman-replication-analysis.Rmd
File metadata and controls
2080 lines (1691 loc) · 69 KB
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: "Weissman-replication-analysis"
author: "Marton Kovacs"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: html_document
---
# Load packages
```{r load packages, warning = FALSE, message = FALSE}
if (!require("pacman")) install.packages("pacman")
pacman::p_load(tidyverse, osfr, lme4, BayesFactor, DescTools, sjstats, car, broom, papaja, cowplot)
```
# Load helper functions
```{r load helper functions}
source("utils.R")
```
# Download data from OSF
## OSF auth (until project is public)
Read/write token should be created on OSF and it should be named as "osf_token_write"
```{r osf authentication}
osf_auth(token = read_lines(list.files(pattern ="osf_token_write_.*.txt")))
```
## Connect to data OSF folder
```{r osf connect to OSF folder, message = FALSE}
data_guid <- "9knds"
weissman_project <- osf_retrieve_node(data_guid)
```
## Download data locally
```{r osf download data, message = FALSE, echo = T, results = "hide"}
local_data_pth <- file.path("data","Processed")
create_local_structure(local_data_pth)
data_files <-
weissman_project %>%
osf_ls_files() %>%
filter(name == "Processed") %>%
osf_ls_files()
data_files %>%
group_by(name) %>% # for each experiment type
do(download_files(.,local_data_pth))
# uncomment following line to remove the data
# remove_local_data(local_data_pth)
```
# Import data
```{r, message = FALSE, warning = FALSE}
# Saving subfolder names
subfolder <- list("primeprobe", "flanker", "stroop", "simon")
# Reading data
processed <-
tibble(task = subfolder,
rt_data = map(subfolder,
~ read_plus(subfolder_name = .x,
pattern = ".tsv$",
path = "data/Processed/",
sep = "\t",
include = "_Rt_")),
acc_data = map(subfolder,
~ read_plus(subfolder_name = .x,
pattern = ".tsv$",
path = "data/Processed/",
sep = "\t",
include = "_Acc_")),
acc_exp_data = map(subfolder,
~ read_plus(subfolder_name = .x,
pattern = ".tsv$",
path = "data/Processed/",
sep = "\t",
include = "Acc_Exploratory_")))
# Reading original study effect sizes
original <- read_tsv("original_study_data.tsv")
```
# Set task names
```{r}
processed$rt_data <- set_names(processed$rt_data, processed$task)
processed$acc_data <- set_names(processed$acc_data, processed$task)
processed$acc_exp_data <- set_names(processed$acc_exp_data, processed$task)
```
# Descriptive statistics of the sample size
## Number of participants left after exclusion
The number of participants is the same for the reaction time, the accuracy, and the exploratory analyses as well
```{r}
map(processed$rt_data,
. %>%
distinct(participant_id) %>%
count())
```
## Number of responses after exclusion
### For the reaction time analysis
```{r}
map(processed$rt_data,
. %>%
count())
```
### For the accuracy analysis
```{r}
map(processed$acc_data,
. %>%
count())
```
### For the accuracy exploratory analysis
```{r}
map(processed$acc_exp_data,
. %>%
count())
```
## Age
We calculated the following statistics based on the reaction time data file, but because it contains the same participants as the accuracy data, and the exploratory data files there should be no difference between the results.
```{r}
map_df(processed$rt_data,
. %>%
distinct(participant_id, .keep_all = T) %>%
group_by(task) %>%
summarize(median_age = median(age, na.rm = T),
min_age = min(age, na.rm = T),
max_age = max(age, na.rm = T),
quart1_age = quantile(age, probs = 0.25, na.rm = T),
quart3_age = quantile(age, probs = 0.75, na.rm = T))) %>%
knitr::kable(caption = "Age demographics")
```
## Gender
```{r}
map_df(processed$rt_data,
. %>%
distinct(participant_id, .keep_all = T) %>%
group_by(task,gender) %>%
count() %>%
ungroup() %>%
filter(gender %in% c("female", "male")) %>%
mutate(prop = n / sum(n) * 100)) %>%
knitr::kable(caption = "Gender demographics")
```
## Language
```{r}
map_df(processed$rt_data,
. %>%
distinct(participant_id, .keep_all = T) %>%
mutate(loc = case_when(loc == "HUN" ~ "Hungarian",
loc == "CZ" ~ "Czech")) %>%
group_by(task,loc) %>%
count() %>%
ungroup() %>%
mutate(prop = n / sum(n) * 100)) %>%
knitr::kable(caption = "Language demographics")
```
## Education demographics
```{r}
map_df(processed$rt_data,
. %>%
distinct(participant_id, .keep_all = T) %>%
group_by(task,education) %>%
count() %>%
ungroup() %>%
filter(education %ni% c("blank", "refused")) %>%
mutate(prop = n / sum(n) * 100)) %>%
knitr::kable(caption = "Education demographics")
```
# Figures of CSE
## For the reaction time data
```{r}
processed <-
processed %>%
mutate(cse_plot_rt_data = map(rt_data,
. %>%
mutate(isPrevCongruent = case_when(isPrevCongruent == 0L ~ "Incongruent",
isPrevCongruent == 1L ~ "Congruent"),
isCongruent = case_when(isCongruent == 0L ~ "Incongruent",
isCongruent == 1L ~ "Congruent")) %>%
group_by(participant_id, isPrevCongruent, isCongruent) %>%
summarise(participant_mean_rt = mean(rt, na.rm = T)) %>%
group_by(isPrevCongruent, isCongruent) %>%
summarise(N = n(),
mean_rt = mean(participant_mean_rt, na.rm = T),
sd_rt = sd(participant_mean_rt, na.rm = T),
se_rt = sd_rt / sqrt(N))),
cse_plot_rt = map2(cse_plot_rt_data, task,
~ ggplot(.x, aes(x = isPrevCongruent, y = mean_rt, shape = isCongruent, group = isCongruent)) +
geom_path() +
geom_point(size = 2) +
geom_errorbar(aes(ymin = mean_rt - se_rt, ymax = mean_rt + se_rt), width=.1) +
scale_shape_manual(values=c(4, 16)) +
scale_y_continuous(limits = c(550, 1000)) +
scale_x_discrete(expand=c(1, 0)) +
ggtitle(stringr::str_to_title(.y)) +
xlab("Congruency of the previous trial")+
ylab("Reaction time") +
guides(shape = guide_legend(title="Congruency of \n the current trial")) +
papaja::theme_apa() +
theme(legend.position = c(0.85, 0.5),
axis.line = element_line(color = "black"))))
```
## Creating figure for the paper
```{r}
cowplot::plot_grid(plotlist = processed$cse_plot_rt)
```
## Saving the figure
```{r}
ggsave("figures/weissman_replication_rt_cse.png", width = 14.4, height = 8, plot = last_plot())
```
## For the accuracy data
```{r}
processed <-
processed %>%
mutate(cse_plot_acc_data = map(acc_data,
. %>%
mutate(isPrevCongruent = case_when(isPrevCongruent == 0L ~ "Incongruent",
isPrevCongruent == 1L ~ "Congruent"),
isCongruent = case_when(isCongruent == 0L ~ "Incongruent",
isCongruent == 1L ~ "Congruent")) %>%
group_by(participant_id, isPrevCongruent, isCongruent) %>%
summarise(participant_mean_acc = mean(isCorrect, na.rm = T)) %>%
group_by(isPrevCongruent, isCongruent) %>%
summarise(N = n(),
mean_acc = mean(participant_mean_acc, na.rm = T),
sd_acc = sd(participant_mean_acc, na.rm = T),
se_acc = sd_acc / sqrt(N))),
cse_plot_acc = map2(cse_plot_acc_data, task,
~ ggplot(.x, aes(x = isPrevCongruent, y = mean_acc, shape = isCongruent, group = isCongruent)) +
geom_path() +
geom_point(size = 2) +
geom_errorbar(aes(ymin = mean_acc - se_acc, ymax = mean_acc + se_acc), width=.1) +
scale_shape_manual(values=c(4, 16)) +
scale_y_continuous(limits = c(0.93, 1)) +
scale_x_discrete(expand=c(1, 0)) +
ggtitle(stringr::str_to_title(.y)) +
xlab("Congruency of the previous trial")+
ylab("Accuracy") +
guides(shape = guide_legend(title="Congruency of \n the current trial")) +
papaja::theme_apa() +
theme(legend.position = c(0.85, 0.5),
axis.line = element_line(color = "black"))))
```
## Creating figure for the paper
```{r}
cowplot::plot_grid(plotlist = processed$cse_plot_acc)
```
## Saving the figure
```{r}
ggsave("figures/weissman_replication_acc_cse.png", width = 14.4, height = 8, plot = last_plot())
```
## For the exploratory accuracy data
```{r}
processed <-
processed %>%
mutate(cse_plot_acc_exp_data = map(acc_exp_data,
. %>%
mutate(isPrevCongruent = case_when(isPrevCongruent == 0L ~ "Incongruent",
isPrevCongruent == 1L ~ "Congruent"),
isCongruent = case_when(isCongruent == 0L ~ "Incongruent",
isCongruent == 1L ~ "Congruent")) %>%
group_by(participant_id, isPrevCongruent, isCongruent) %>%
summarise(participant_mean_acc = mean(isCorrect, na.rm = T)) %>%
group_by(isPrevCongruent, isCongruent) %>%
summarise(N = n(),
mean_acc = mean(participant_mean_acc, na.rm = T),
sd_acc = sd(participant_mean_acc, na.rm = T),
se_acc = sd_acc / sqrt(N))),
cse_plot_acc_exp = map2(cse_plot_acc_exp_data, task,
~ ggplot(.x, aes(x = isPrevCongruent, y = mean_acc, shape = isCongruent, group = isCongruent)) +
geom_path() +
geom_point(size = 2) +
geom_errorbar(aes(ymin = mean_acc - se_acc, ymax = mean_acc + se_acc), width=.1) +
scale_shape_manual(values=c(4, 16)) +
scale_y_continuous(limits = c(0.93, 1)) +
scale_x_discrete(expand=c(1, 0)) +
ggtitle(stringr::str_to_title(.y)) +
xlab("Congruency of the previous trial")+
ylab("Accuracy") +
guides(shape = guide_legend(title="Congruency of \n the current trial")) +
papaja::theme_apa() +
theme(legend.position = c(0.85, 0.5),
axis.line = element_line(color = "black"))))
```
## Creating figure for the paper
```{r}
cowplot::plot_grid(plotlist = processed$cse_plot_acc_exp)
```
## Saving the figure
```{r}
ggsave("figures/weissman_replication_acc_exp_cse.png", width = 14.4, height = 8, plot = last_plot())
```
# Reaction time analyis
## I. analysis: Testing whether the CSE was present in the different tasks
### Preprocessing data
We are calculating mean reaction time for the analysis for each participant in each condition for each task.
```{r calculating mean dev rt}
processed <-
processed %>%
mutate(rt_data = map(rt_data,
. %>%
group_by(participant_id, isCongruent, isPrevCongruent) %>%
summarise(rtConditionalMean = mean(rt, na.rm = T)) %>%
ungroup() %>%
mutate(isCongruent = as.factor(isCongruent),
isPrevCongruent = as.factor(isPrevCongruent),
participant_id = as.factor(participant_id))))
```
We are calculating the main congruency effect of the current (n) trial, the main congruency effect of the previous trial (n-1) and the interaction effect (CSE) between them for each participant.
```{r}
processed <-
processed %>%
mutate(rt_effect_data = map(rt_data,
. %>%
ungroup() %>%
mutate(condition = case_when(isPrevCongruent == 0L & isCongruent == 0L ~ "ii",
isPrevCongruent == 0L & isCongruent == 1L ~ "ic",
isPrevCongruent == 1L & isCongruent == 0L ~ "ci",
isPrevCongruent == 1L & isCongruent == 1L ~ "cc",
TRUE ~ NA_character_)) %>%
select(-isPrevCongruent, -isCongruent) %>%
spread(key = condition, value = rtConditionalMean) %>%
mutate(congruencyEffect = ((ci + ii) / 2) - ((cc + ic) / 2),
prevCongruencyEffect = ((ci + cc) / 2) - ((ii + ic) / 2),
cseEffect = (ci - cc) - (ii - ic))))
```
### Running the analysis
We are running a 2 × 2 repeated-measures ANOVA per task with mean RT as dependent variable. The two factors of the ANOVA are Previous Trial Congruency (congruent, incongruent) and Current Trial Congruency (congruent, incongruent).
```{r}
processed <-
processed %>%
mutate(anova_rt = map(rt_data,
~ aov(rtConditionalMean ~ isCongruent * isPrevCongruent + Error(participant_id / (isCongruent * isPrevCongruent)), data = .x)))
# Print results with names
processed$anova_rt %>%
set_names(., processed$task) %>%
map(., summary)
```
The interaction was only significant for the first task, the primeprobe task.
We are calculating the partial eta square as an effect size estimate for the ANOVA.
```{r}
processed <-
processed %>%
mutate(anova_rt_eta = map(anova_rt,
~ eta_sq(.x, partial = TRUE)))
# Print results with names
processed$anova_rt_eta %>%
set_names(., processed$task) %>%
map(., summary)
```
### Calculating Bayes factors
#### Preprocessing data for the Bayes factor analysis
We are substracting the F values for each effect (main congruency effect of current trial, main congruency effect of previous trial and interaction effect) from the ANOVA.
```{r}
processed <-
processed %>%
mutate(anova_rt_f = map(anova_rt,
. %>%
broom::tidy() %>%
select(term, statistic) %>%
transmute(term = case_when(term == "isCongruent" ~ "mainEffectIsCongruent",
term == "isPrevCongruent" ~ "mainEffectIsPrevCongruent",
term == "isCongruent:isPrevCongruent" ~ "interactionEffect",
term == "Residuals" ~ term),
fValue = statistic) %>%
filter(!is.na(fValue))))
```
We are calculating the mean effects (main congruency effect of current trial, main congruency effect of previous trial and interaction effect) for each task.
```{r}
processed <-
processed %>%
mutate(anova_rt_raw_effect = map(rt_effect_data,
. %>%
summarise(mainEffectIsCongruent = mean(congruencyEffect, na.rm = T),
mainEffectIsPrevCongruent = mean(prevCongruencyEffect, na.rm = T),
interactionEffect = mean(cseEffect, na.rm = T),
nParticipant = n()) %>%
gather(key = "term", value = "rawEffect", -nParticipant)))
```
We are adding the calucalted F-values for each effect to the calculated mean effects.
```{r}
processed <-
processed %>%
mutate(anova_rt_raw_effect = map2(anova_rt_raw_effect, anova_rt_f,
~ inner_join(.x, .y, by = "term")))
```
Calculating the SEs.
```{r}
processed <-
processed %>%
mutate(anova_rt_raw_effect = map(anova_rt_raw_effect,
. %>%
mutate(se = rawEffect / sqrt(fValue))))
```
Preprocessing effect sizes that Weissman et al. (2014) found for the H1 model of the Bayes factor analysis.
```{r}
original_rt_effect <-
original %>%
filter(measure == "rt") %>%
select(task, congruency, cse) %>%
gather(key = "term", value = "originalRawEffect", -task) %>%
mutate(term = case_when(term == "congruency" ~ "mainEffectIsCongruent",
term == "cse" ~ "interactionEffect")) %>%
group_by(task) %>%
nest() %>%
rename(original_effect_reaction_time = data)
```
Joining the effect sizes of the replicated study with the effect sizes of the current study.
```{r}
processed <-
processed %>%
mutate(task = as.character(task)) %>% # vector needs to be character class (instead of a list) for joining
left_join(., original_rt_effect, by = "task") %>%
mutate(anova_rt_bf_effect = map2(anova_rt_raw_effect, original_effect_reaction_time,
~ left_join(.x, .y, by = "term")))
```
#### Calculating the Bayes factor
##### For the interaction effect
A half-normal distribution is used with a mode of 0 and a SD equal to the half of the congruency effect (in ms) for the particular task in the original data set by Weissman et al. (2014) to model the prediction of the interaction effect.
```{r}
processed <-
processed %>%
mutate(bf_interaction_rt = map(anova_rt_bf_effect,
~ Bf(sd = .x$se[3],
obtained = .x$rawEffect[3],
dfdata = .x$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = .x$originalRawEffect[1] / 2,
dftheory = 10^10,
tail = 1)))
# Print results with names
processed$bf_interaction_rt %>%
set_names(., processed$task)
```
###### Finding the robustness region for the interaction effect
```{r}
# Finding the lower boundary of the robustness region
## Primeprobe
primeprobe_rt <- processed$anova_rt_bf_effect[[1]]
Bf(sd = primeprobe_rt$se[3],
obtained = primeprobe_rt$rawEffect[3],
dfdata = primeprobe_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 0.60,
dftheory = 10^10,
tail = 1)
## Flanker
flanker_rt <- processed$anova_rt_bf_effect[[2]]
Bf(sd = flanker_rt$se[3],
obtained = flanker_rt$rawEffect[3],
dfdata = flanker_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 14.6,
dftheory = 10^10,
tail = 1)
## Stroop
stroop_rt <- processed$anova_rt_bf_effect[[3]]
### The lower limit is 0, because the Bf is inconslusive
## Simon
simon_rt <- processed$anova_rt_bf_effect[[4]]
## The lower limit is 0, because the Bf is inconslusive
# Finding the upper boundary of the robustness region
## Primeprobe
Bf(sd = primeprobe_rt$se[3],
obtained = primeprobe_rt$rawEffect[3],
dfdata = primeprobe_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 6423,
dftheory = 10^10,
tail = 1)
## Flanker
### The upper boundary is infinite, because the Bf supports the null model
## Stroop
Bf(sd = stroop_rt$se[3],
obtained = stroop_rt$rawEffect[3],
dfdata = stroop_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 222,
dftheory = 10^10,
tail = 1)
## Simon
Bf(sd = simon_rt$se[3],
obtained = simon_rt$rawEffect[3],
dfdata = simon_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 120,
dftheory = 10^10,
tail = 1)
```
##### For the main congruency effect of the current trial
To test the congruency main effect, the SD of the H1 model is set to the congruency effect reported by Weissman et al. (2014) for the given task. The other settings stay the same.
```{r}
processed <-
processed %>%
mutate(bf_congruency_rt = map(anova_rt_bf_effect,
~ Bf(sd = .x$se[1],
obtained = .x$rawEffect[1],
dfdata = .x$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = .x$originalRawEffect[1],
dftheory = 10^10,
tail = 1)))
# Print results with names
processed$bf_congruency_rt %>%
set_names(., processed$task)
```
###### Finding the robustness region for the interaction effect
```{r}
# Finding the lower boundary of the robustness region
## Primeprobe
Bf(sd = primeprobe_rt$se[1],
obtained = primeprobe_rt$rawEffect[1],
dfdata = primeprobe_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 0.74,
dftheory = 10^10,
tail = 1)
## Flanker
Bf(sd = flanker_rt$se[1],
obtained = flanker_rt$rawEffect[1],
dfdata = flanker_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 1,
dftheory = 10^10,
tail = 1)
## Stroop
Bf(sd = stroop_rt$se[1],
obtained = stroop_rt$rawEffect[1],
dfdata = stroop_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 1.75,
dftheory = 10^10,
tail = 1)
## Simon
Bf(sd = simon_rt$se[1],
obtained = simon_rt$rawEffect[1],
dfdata = simon_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 0.74,
dftheory = 10^10,
tail = 1)
# Finding the upper boundary of the robustness region
## Primeprobe
Bf(sd = primeprobe_rt$se[1],
obtained = primeprobe_rt$rawEffect[1],
dfdata = primeprobe_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 26512,
dftheory = 10^10,
tail = 1)
## Flanker
Bf(sd = flanker_rt$se[1],
obtained = flanker_rt$rawEffect[1],
dfdata = flanker_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 17181,
dftheory = 10^10,
tail = 1)
## Stroop
Bf(sd = stroop_rt$se[1],
obtained = stroop_rt$rawEffect[1],
dfdata = stroop_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 47403,
dftheory = 10^10,
tail = 1)
## Simon
Bf(sd = simon_rt$se[1],
obtained = simon_rt$rawEffect[1],
dfdata = simon_rt$nParticipant[1] - 1,
meanoftheory = 0,
sdtheory = 15000,
dftheory = 10^10,
tail = 1)
```
### Follow up simple effects analysis
#### Preprocessing data
Saving the data of the task (primeprobe) with significant interaction between current trial congruency and previous trial congruency.
```{r}
primeprobe <- processed$rt_effect_data[[1]]
```
#### Checking the number of responses
```{r}
primeprobe %>%
count()
```
#### Running the analysis
If the Bayes factor is greater than the preset threshold of B = 3 for the interaction effect in a given task we run a simple effects analyses, contrasting current-congruent congruent (cC) and current-incongruent congruent (iC) trials.
```{r current congruent follow up comparison for rt}
current_congruent <-
t.test(primeprobe$ic, primeprobe$cc, paired = TRUE) %>%
broom::tidy()
current_congruent %>% knitr::kable()
```
current-congruent incongruent (cI) and current-incongruent incongruent (iI) trials in another.
```{r current incongruent follow up comparison for rt}
current_incongruent <-
t.test(primeprobe$ci, primeprobe$ii, paired = TRUE) %>%
broom::tidy()
current_incongruent %>% knitr::kable()
```
#### Calculating the Bayes factor for the follow up analysis
The prior H1 model is a half-normal distribution with a mode of 0 and an SD equal to half of the CSE estimate for that given task, i.e., the originally reported congruency effect divided by four.
##### Current congruent follow up analysis
```{r}
Bf(sd = current_congruent$estimate / current_congruent$statistic,
obtained = current_congruent$estimate,
dfdata = current_congruent$parameter,
meanoftheory = 0,
sdtheory = processed$anova_rt_bf_effect[[1]]$originalRawEffect[1] / 4,
dftheory = 10^10,
tail = 1)
```
###### Finding the robustness region for the current congruent follow up analysis
```{r}
# Finding the lower boundary of the robustness region
Bf(sd = current_congruent$estimate / current_congruent$statistic,
obtained = current_congruent$estimate,
dfdata = current_congruent$parameter,
meanoftheory = 0,
sdtheory = 0.525,
dftheory = 10^10,
tail = 1)
```
```{r}
# Finding the upper boundary of the robustness region
Bf(sd = current_congruent$estimate / current_congruent$statistic,
obtained = current_congruent$estimate,
dfdata = current_congruent$parameter,
meanoftheory = 0,
sdtheory = 2713,
dftheory = 10^10,
tail = 1)
```
##### Current incongruent follow up analysis
```{r}
Bf(sd = current_incongruent$estimate / current_incongruent$statistic,
obtained = current_incongruent$estimate,
dfdata = current_incongruent$parameter,
meanoftheory = 0,
sdtheory = processed$anova_rt_bf_effect[[1]]$originalRawEffect[1] / 4,
dftheory = 10^10,
tail = 1)
```
###### Finding the robustness region for the current incongruent follow up analysis
```{r}
# Finding the lower boundary of the robustness region
Bf(sd = current_incongruent$estimate / current_incongruent$statistic,
obtained = current_incongruent$estimate,
dfdata = current_incongruent$parameter,
meanoftheory = 0,
sdtheory = 0.53,
dftheory = 10^10,
tail = 1)
```
```{r}
# Finding the upper boundary of the robustness region
Bf(sd = current_incongruent$estimate / current_incongruent$statistic,
obtained = current_incongruent$estimate,
dfdata = current_incongruent$parameter,
meanoftheory = 0,
sdtheory = 2973,
dftheory = 10^10,
tail = 1)
```
## II. analysis: Testing whether the size of the CSE varies across tasks
### Creating the datatable
We are combining the effects (main congruency effect of current trial, main congruency effect of previous trial and interaction effect) for each task (primeprobe, Flanker, Stroop, Simon) in one datatable.
```{r, warning = FALSE}
interaction_rt_data <-
processed %>%
select(task, rt_effect_data) %>%
unnest(rt_effect_data) %>%
mutate(task = as.factor(task))
```
### Testing the assumptions
We are testing the homogenity of variances.
```{r}
car::leveneTest(cseEffect ~ task, data = interaction_rt_data)
```
The assumption of homogenity of variances is violated. Therefore, we are running a Kruskal Wallis H test instead of an ANOVA.
### Running the analysis
We are running a Kruskal-Wallis H test with task (levels: Prime-Probe, Flanker, Stroop, Simon) as the single factor, and the CSE index as the dependent variable to examine if the size of the effect differs across tasks.
```{r}
kruskal.test(cseEffect ~ task, data = interaction_rt_data)
```
### Calculating pairwise comparisons
A Dunn’s test is used for pairwise comparisons.
```{r}
dunn_test <- DescTools::DunnTest(cseEffect ~ task, data = interaction_rt_data)
dunn_test
```
Creating a tidy datatable from the Dunn test output.
```{r}
dunn_test <-
dunn_test[[1]] %>%
as_tibble(rownames = "comparison") %>%
janitor::clean_names()
```
#### Bf analysis of pairwise comparisons
##### Preprocessing data for the Bf analyses
```{r}
# Stroop and Primeprobe comparison
stroop_primeprobe_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("stroop", "primeprobe"))) %>%
broom::tidy()
# Stroop and Simon comparison
stroop_simon_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("stroop", "simon"))) %>%
broom::tidy()
# Stroop and Flanker comparison
stroop_flanker_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("stroop", "flanker"))) %>%
broom::tidy()
# Primeprobe and Flanker comparison
primeprobe_flanker_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("primeprobe", "flanker"))) %>%
broom::tidy()
# Primeprobe and Simon comparison
primeprobe_simon_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("primeprobe", "simon"))) %>%
broom::tidy()
# Flanker and Simon comparison
flanker_simon_comparison <-
t.test(cseEffect ~ task,
data = filter(interaction_rt_data,
task %in% c("flanker", "simon"))) %>%
broom::tidy()
```
##### Running the analysis
A half-normal distribution is used with a mode of 0 and SD equal to half of the greater congruency effect of the two in any given pair as reported by Weissman et al. (2014).
Tasks in a descending order based on their congruency effect according to the original study:
Stroop > Primeprobe > Flanker > Simon
We are using a two-tailed test for the analysis.
###### Stroop and Primeprobe comparison
```{r}
# Bf Analysis
Bf(obtained = stroop_primeprobe_comparison$estimate,
sd = stroop_primeprobe_comparison$estimate / stroop_primeprobe_comparison$statistic,
dfdata = stroop_primeprobe_comparison$parameter,
meanoftheory = 0,
sdtheory = original$congruency[1] / 2,
dftheory = 10^10,
tail = 2)
# Finding the robustness region for the current incongruent follow up analysis
## Finding the lower boundary of the robustness region
Bf(obtained = stroop_primeprobe_comparison$estimate,
sd = stroop_primeprobe_comparison$estimate / stroop_primeprobe_comparison$statistic,
dfdata = stroop_primeprobe_comparison$parameter,
meanoftheory = 0,
sdtheory = 28.8,
dftheory = 10^10,
tail = 2)
## Finding the upper boundary of the robustness region
### The upper boundary is infinite, because the Bf supports the null model
```
###### Stroop and Simon comparison
```{r}
# Bf Analysis
Bf(obtained = stroop_simon_comparison$estimate,
sd = stroop_simon_comparison$estimate / stroop_simon_comparison$statistic,
dfdata = stroop_simon_comparison$parameter,
meanoftheory = 0,
sdtheory = original$congruency[1] / 2,
dftheory = 10^10,
tail = 2)
# Finding the robustness region for the current incongruent follow up analysis
## Finding the lower boundary of the robustness region
Bf(obtained = stroop_simon_comparison$estimate,
sd = stroop_simon_comparison$estimate / stroop_simon_comparison$statistic,
dfdata = stroop_simon_comparison$parameter,
meanoftheory = 0,
sdtheory = 37.7,
dftheory = 10^10,
tail = 2)
## Finding the upper boundary of the robustness region
## The upper boundary is infinite, because the Bf supports the null model
```
###### Stroop and Flanker comparison
```{r}
# Bf Analysis
Bf(obtained = stroop_flanker_comparison$estimate,
sd = stroop_flanker_comparison$estimate / stroop_flanker_comparison$statistic,
dfdata = stroop_flanker_comparison$parameter,
meanoftheory = 0,
sdtheory = original$congruency[1] / 2,
dftheory = 10^10,
tail = 2)
# Finding the robustness region for the current incongruent follow up analysis
## Finding the lower boundary of the robustness region
### The lower limit is 0, because the Bf is inconslusive
## Finding the upper boundary of the robustness region
Bf(obtained = stroop_flanker_comparison$estimate,
sd = stroop_flanker_comparison$estimate / stroop_flanker_comparison$statistic,
dfdata = stroop_flanker_comparison$parameter,
meanoftheory = 0,
sdtheory = 140,
dftheory = 10^10,
tail = 2)
```
###### Primeprobe and Flanker comparison
```{r}
# Bf Analysis
Bf(obtained = primeprobe_flanker_comparison$estimate,
sd = primeprobe_flanker_comparison$estimate / primeprobe_flanker_comparison$statistic,
dfdata = primeprobe_flanker_comparison$parameter,
meanoftheory = 0,
sdtheory = original$congruency[4] / 2,
dftheory = 10^10,
tail = 2)
# Finding the robustness region for the current incongruent follow up analysis
## Finding the lower boundary of the robustness region
Bf(obtained = primeprobe_flanker_comparison$estimate,
sd = primeprobe_flanker_comparison$estimate / primeprobe_flanker_comparison$statistic,
dfdata = primeprobe_flanker_comparison$parameter,
meanoftheory = 0,
sdtheory = 6.3,
dftheory = 10^10,
tail = 2)
## Finding the upper boundary of the robustness region