-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_analysis.R
1141 lines (799 loc) · 39.1 KB
/
Data_analysis.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
# 2019. Martin R. Vasilev, Victoria Adedeji, Calvin Laursen, Tim Slattery
rm(list= ls())
#######################################################
# Data column explanation: #
#######################################################
# sub: Subject number
# item: Item (sentence) number from the corpus file
# cond: Condition number (1= small font short line; 2= big font short line; 3= small font long line;
# 4= big font long line)
# seq: Trial sequence, or the order in which trials were presented in the experiment
# trialStart: Start of trial time stamp in raw asc file
# SFIX: Start of fixation flag in the asc data (search for it in raw data to quickly locate it)
# EFIX: End of fixation flag in the asc data (search for it in raw data to quickly locate it)
# xPos: X position of the fixation on the screen
# yPos: Y position of the fixation on the screen
# fix_num: Fixation number in the current trial
# fix_dur: Fixation duration (in ms)
# sacc_dur: Incoming saccade duration (in ms)
# line: Line of text on which the fixation occured
# word: Word number in the trial on which the fixation occured
# char_trial: Character number in the trial on which the fixation occured (includes all text in the trial)
# char_line: Character number on the current line on which the fixation occured (each line starts at 0)
# prevChar: Character number (line) on which the previous fixation occured
# nextChar: Character number (line) on which the next fixation occured
# prevX: X position on which the previous fixation occured
# nextX: X position on which the next fixation occured
# regress: A logical indicating whether the current fixation is a regressive one (1= yes; 0= no)
# wordID: A string of the word on which the fixation occured
# land_pos: Landing position in characters on the current word (0= empty space before word)
# sacc_len: Incoming saccade length (in characters)
# outsideText: A logical indicating whether the current fixation occured outside the text area (1= yes; 0=no)
# max_char_line: Maximum number of characters on the current line
# Rtn_sweep: A logical indicating whether the current fixation is a return sweep one (1= yes; 0= no)
# Rtn_sweep_type: Type of return sweep saccade ("undersweep" or "accurate")
# LandStartLet: Landing position relative to the start of the line in letters (equivalent to char_line)
# LandStartVA: Landing position relative to the start of the line in degrees per visual angle
# undersweep_prob: A logical indicating whether the current fixation is an undersweep one (1= yes; 0=no)
# launchDistLet: Launch site distance in letters (equivalent to sacc_len)
# launchDistVA: Launch site distance in degrees per visual angle
# launchSite: Launch site distance relative to end of the line (letters)
# launchSiteVA: Launch site distance relative to end of the line (visual angle)
# Please note: counting in the present data (e.g., fixation/ character/ line numbers) always starts at 1.
# load/ install required packages:
packages= c("reshape", "lme4", "ggplot2", "MASS", "arm", "effects", "lattice",
"mgcv", "itsadug", 'ggpubr') # list of used packages:
for(i in 1:length(packages)){
if(packages[i] %in% rownames(installed.packages())==FALSE){
install.packages(packages[i])
library(packages[i], character.only=TRUE)
}else{
library(packages[i], character.only=TRUE)
}
}
# colorblind palletes: # https://venngage.com/blog/color-blind-friendly-palette/
pallete1= c("#CA3542", "#27647B", "#849FA0", "#AECBC9", "#57575F", "#FFC107") # "Classic & trustworthy"
source("Functions/CohensD_raw.R")
########################
# Prepare data frames: #
########################
# Load data:
load("data/Alldata.Rda")
load("data/Return_sweep.Rda")
load("data/Quest.Rda")
#classify data
RS$sub = as.factor(RS$sub)
RS$item = as.factor(RS$item)
RS$cond= as.factor(RS$cond)
RS$land_pos = as.numeric(RS$land_pos)
Alldata$sub = as.factor(Alldata$sub)
Alldata$item = as.factor(Alldata$item)
Alldata$cond= as.factor(Alldata$cond)
Alldata$land_pos = as.numeric(Alldata$land_pos)
Quest$sub<- as.factor(Quest$sub)
Quest$item<- as.factor(Quest$item)
#examine data
str(RS)
head(RS)
str(Alldata)
head(Alldata)
#merge conditions for main effect analysis
RS$line_len= factor(ifelse(RS$cond==1| RS$cond==2, 1,2),labels = c("short line", "long line"))
RS$font_size= factor(ifelse(RS$cond==1| RS$cond==3, 1,2), labels = c("small font", "big font"))
Alldata$line_len= factor(ifelse(Alldata$cond==1| Alldata$cond==2, 1,2),labels = c("short line", "long line"))
Alldata$font_size= factor(ifelse(Alldata$cond==1| Alldata$cond==3, 1,2), labels = c("small font", "big font"))
Quest$line_len= factor(ifelse(Quest$cond==1| Quest$cond==2, 1,2),labels = c("short line", "long line"))
Quest$font_size= factor(ifelse(Quest$cond==1| Quest$cond==3, 1,2), labels = c("small font", "big font"))
############################
# Comprehension accuracy #
############################
100*round(mean(Quest$accuracy),3) # mean accuracy (%)
100*round(sd(Quest$accuracy),3) # SD accuracy (%)
DesQuest<- melt(Quest, id=c('sub', 'item', 'cond', 'line_len', 'font_size'),
measure=c("accuracy"), na.rm=TRUE)
mQuest<- cast(DesQuest, line_len+font_size ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
mQuest
# GLMM model:
Quest$line_len<- as.factor(Quest$line_len)
Quest$font_size<- as.factor(Quest$font_size)
contrasts(Quest$line_len)<- c(-1, 1)
contrasts(Quest$font_size)<- c(-1, 1)
if(!file.exists("Models/CGM.Rda")){
# model does not converge with any other random slopes
CGM<- glmer(accuracy ~ font_size*line_len + (1|sub)+ (line_len|item), data = Quest, family= binomial)
save(CGM, file= "Models/CGM.Rda")
summary(CGM)
}else{
load("Models/CGM.Rda")
summary(CGM)
}
round(coef(summary(CGM)), 2)
############################
# Descriptives #
############################
#mean under_sweep per condition
USP<- melt(RS, id=c('sub', 'item', 'font_size', 'line_len'),
measure=c("undersweep_prob"), na.rm=TRUE)
mUSP<- cast(USP, font_size + line_len ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
#mean land_pos in letters per condition
LP<- melt(RS, id=c('sub', 'item', 'font_size', 'line_len'),
measure=c("LandStartLet"), na.rm=TRUE)
mLP<- cast(LP, font_size + line_len ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
#mean land_pos in visual angle per condition
LP1<- melt(RS, id=c('sub', 'item', 'font_size', 'line_len'),
measure=c("LandStartVA"), na.rm=TRUE)
mLP1<- cast(LP1, font_size + line_len ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
#mean incoming saccade length in visual angle per fixation type
Alldata2 <- Alldata[- which(Alldata$regress== 1 & Alldata$Rtn_sweep==0), ]
SLVA1<- melt(Alldata2, id=c('sub', 'item', 'line_len', 'font_size', 'Rtn_sweep'),
measure=c("launchDistVA"), na.rm=TRUE)
mSLVA1<- cast(SLVA1, line_len + font_size + Rtn_sweep ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
# get just intra-line saccades (forward vs regressive)
Alldata4<- Alldata[-which(Alldata$regress==0 & Alldata$Rtn_sweep==0), ]
RegVA<- melt(Alldata4, id=c('sub', 'item', 'line_len', 'font_size', 'Rtn_sweep'),
measure=c("launchDistVA"), na.rm=TRUE)
mReg<- cast(RegVA, line_len + font_size + Rtn_sweep ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
#mean incoming saccade length in visual angle per saccade type
Alldata3 <- Alldata[Alldata$Rtn_sweep < 1,]
SLVA2<- melt(Alldata3, id=c('sub', 'item', 'font_size', 'regress'),
measure=c("launchDistVA"), na.rm=TRUE)
mSLVA2<- cast(SLVA2, font_size + regress ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
# #mean incoming saccade length in letters per saccade type
# SLlet<- melt(Alldata3, id=c('sub', 'item', 'font_size', 'regress'),
# measure=c("launchDistLet"), na.rm=TRUE)
# mSLlet<- cast(SLlet, font_size + regress ~ variable
# ,function(x) c(M=signif(mean(x),3)
# , SD= sd(x) ))
#########################################
# (G)LMMS #
#########################################
#setting contrast
contrasts(RS$line_len) <- c(-1, 1)
contrasts(RS$font_size) <- c(-1, 1)
Alldata2$Rtn_sweep = as.factor(Alldata2$Rtn_sweep) # contains only forward intra-line saccades (+return-sweeps)
contrasts(Alldata2$Rtn_sweep) <- c(-1, 1)
contrasts(Alldata2$font_size) <- c(-1, 1)
Alldata4$Rtn_sweep = as.factor(Alldata4$Rtn_sweep) # contains only regressive intra-line saccades (+return-sweeps)
contrasts(Alldata4$Rtn_sweep) <- c(-1, 1)
contrasts(Alldata4$font_size) <- c(-1, 1)
#centering launch distance
RS$launchDistVA_C<- scale(RS$launchDistVA)
Alldata2$launchDistVA_C<- scale(Alldata2$launchDistVA)
Alldata4$launchDistVA_C<- scale(Alldata4$launchDistVA)
# centre launch site:
RS$launchSiteVA_C<- scale(RS$launchSiteVA)
#------------------------------#
# Undersweep probability #
#------------------------------#
if(!file.exists("Models/GLM1.Rda")){
GLM1<- glmer(undersweep_prob ~ font_size* line_len*launchSiteVA_C +(line_len|sub)+(line_len|item),
data= RS, family= binomial)
save(GLM1, file= "Models/GLM1.Rda")
}else{
load("Models/GLM1.Rda")
}
summary(GLM1)
round(coef(summary(GLM1)),3)
write.csv(round(coef(summary(GLM1)),3), 'Models/Undersweep_prob_GLM1.csv')
# Effect size:
CohensD_raw(data = RS, measure = 'undersweep_prob', group_var = 'line_len', baseline = 'short line')
CohensD_raw(data = RS, measure = 'undersweep_prob', group_var = 'font_size', baseline = 'small font')
#------------------------------#
# Landing Position #
#------------------------------#
if(!file.exists('Models/LM1.Rda')){
LM1<- lmer(LandStartVA ~ font_size*line_len*launchSiteVA_C + (line_len|sub) + (line_len|item),
data=RS, REML=T)
save(LM1, file= "Models/LM1.Rda")
}else{
load('Models/LM1.Rda')
}
summary(LM1)
LPM= round(coef(summary(LM1)), 2)
write.csv(LPM, file= "Models/LPM.csv")
CohensD_raw(data = RS, measure = 'LandStartVA', group_var = 'line_len', baseline = 'short line')
CohensD_raw(data = RS, measure = 'LandStartVA', group_var = 'font_size', baseline = 'small font')
plot(effect('font_size:launchSiteVA_C', LM1))
plot(effect('line_len:font_size:launchSiteVA_C', LM1))
#------------------------------#
# Saccade length #
#------------------------------#
# forward saccades:
if(!file.exists("Models/LM2.Rda")){
LM2<- lmer(launchDistVA ~ font_size*line_len*Rtn_sweep + (font_size|sub) + (1|item), Alldata2, REML=T)
save(LM2, file= "Models/LM2.Rda")
}else{
load("Models/LM2.Rda")
}
summary(LM2)
round(coef(summary(LM2)),3)
write.csv(round(coef(summary(LM2)),3), 'Models/SaccLen_LM2.csv')
contrasts(Alldata2$font_size)
contrasts(Alldata2$Rtn_sweep)
plot(effect('font_size', LM2))
plot(effect('font_size:Rtn_sweep', LM2))
effect('font_size:Rtn_sweep', LM2)
# Regressive saccades:
if(!file.exists("Models/LM3.Rda")){
LM3<- lmer(launchDistVA ~ font_size*line_len*Rtn_sweep + (font_size|sub) + (1|item), Alldata4, REML=T)
save(LM3, file= "Models/LM3.Rda")
}else{
load("Models/LM3.Rda")
}
summary(LM3)
round(coef(summary(LM3)),3)
write.csv(round(coef(summary(LM3)),3), 'Models/SaccLen_LM3.csv')
contrasts(Alldata4$font_size)
contrasts(Alldata4$Rtn_sweep)
plot(effect('font_size:Rtn_sweep', LM3))
effect('font_size:Rtn_sweep', LM3)
# ### font size in letters
# dat3<- subset(Alldata2, Rtn_sweep==0)
#
# summary(LM4<- lmer(sacc_len ~ font_size+ (1|sub) + (1|item), dat3, REML=T))
#########################################
# RESULTS PLOTS #
#########################################
#------------------------------#
# Descriptives plot #
#------------------------------#
# UNDERSWEEP PROBABILITY:
dfU<- subset(RS, !is.na(RS$launchDistVA_C))
dfU$fitted<- fitted(GLM1)
# average over subjects:
DesUSP_M<- melt(dfU, id=c('sub', 'item', 'font_size', 'line_len'),
measure=c("fitted", 'undersweep_prob'), na.rm=TRUE)
dfUSP<- cast(DesUSP_M, font_size + line_len+ sub ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
dfUSP$font_size= paste(' ', dfUSP$font_size, ' ', sep = '')
dfUSP$font_size<- as.factor(dfUSP$font_size)
dfUSP$font_size<- factor(dfUSP$font_size, levels = c(" small font ", " big font "))
USP_plot <- ggplot(dfUSP, aes(x=line_len, y=fitted_M, fill= font_size, shape= font_size, linetype= font_size)) +
theme_classic (22)+ geom_violin(alpha= 0.3, size=1)+ ylim(0, 1)+
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.6, position=position_dodge(0.9), alpha= 0.8)+
geom_boxplot(width=0.1, position=position_dodge(0.9), size=1 , notch = T, notchwidth = 0.4, varwidth =F,
fill= 'white', color= 'black', show.legend=FALSE, linetype='solid')+
labs(x= "Line length", y= "Under-sweep probability", color= "", shape= '', linetype= '', fill= '')+
theme(legend.position = 'none', legend.title=element_blank(),
legend.key.width = unit(1.25, 'cm'), legend.key.height = unit(1, 'cm'),
plot.title = element_text(hjust = 0.5))+
scale_fill_manual(values=c(pallete1[1], pallete1[4]))+
scale_color_manual(values=c(pallete1[1], pallete1[4]))+ ggtitle('b)')
USP_plot
ggsave(filename = 'Plots/USP.pdf', plot = USP_plot, width = 7, height = 7)
# LANDING POSITION:
dfL<- subset(RS, !is.na(RS$launchDistVA_C))
dfL$fitted<- fitted(LM1)
# average over subjects:
DesLP_M<- melt(dfL, id=c('sub', 'item', 'font_size', 'line_len'),
measure=c("fitted", 'LandStartVA'), na.rm=TRUE)
dfLP<- cast(DesLP_M, font_size + line_len+ sub ~ variable
,function(x) c(M=signif(mean(x),3)
, SD= sd(x) ))
dfLP$font_size= paste(' ', dfLP$font_size, ' ', sep = '')
dfLP$font_size<- as.factor(dfLP$font_size)
dfLP$font_size<- factor(dfLP$font_size, levels = c(" small font ", " big font "))
LP_plot <- ggplot(dfLP, aes(x=line_len, y=fitted_M, fill= font_size, shape= font_size, linetype= font_size)) +
theme_classic (22)+ geom_violin(alpha= 0.3, size=1)+ #ylim(0, 8)+
geom_dotplot(binaxis='y', stackdir='center', dotsize=0.6, position=position_dodge(0.9), alpha= 0.8)+
geom_boxplot(width=0.1, position=position_dodge(0.9), size=1 , notch = T, notchwidth = 0.4, varwidth =F,
fill= 'white', color= 'black', show.legend=FALSE, linetype= 'solid')+
labs(x= "Line length", y= "Landing position (deg)", color= "", shape= '', linetype= '', fill= '')+
theme(legend.position = c(0.2, 0.88), legend.title=element_blank(),
legend.key.width = unit(1.25, 'cm'), legend.key.height = unit(1, 'cm'),
plot.title = element_text(hjust = 0.5))+
scale_fill_manual(values=c(pallete1[1], pallete1[4]))+
scale_color_manual(values=c(pallete1[1], pallete1[4]))+ ggtitle('a)')
LP_plot
ggsave(filename = 'Plots/LP.pdf', plot = LP_plot, width = 7, height = 7)
#### merge two descriptives plots:
figure <- ggarrange(LP_plot, USP_plot, ncol = 2, nrow = 1, common.legend = TRUE, legend = "top")
ggsave(filename = 'Plots/Des_merged.pdf', plot = figure, width = 15, height = 7)
#---------------------------------#
# 3-way interaction plot (LP) #
#---------------------------------#
###ALL EFFECTS PLOT -THREE WAY INTERACTION
lp= allEffects(LM1)
summary(lp)
x= as.data.frame(lp)
x=as.data.frame(x)
colnames(x)= c("font_size", "line_len", "launchSiteVA_C", "fit", "se", "lower", "upper")
df<- x
df$line_len <- droplevels(df$line_len)
#levels(df$line_len)<- c("long", 'short')
df$line_len<- factor(df$line_len, levels= c("short line", "long line"))
levels(df$line_len)<- c(" short line", " long line")
levels(df$font_size)<- c('large font', 'small font', NA)
G1<- ggplot(df, aes(x= launchSiteVA_C, y=fit, ymax= upper, ymin= lower,
color=line_len, linetype= line_len, fill= line_len, shape= line_len)) + theme_bw (22)+
geom_line(size= 1)+ geom_point(size=4)+
labs(x= "Return-sweep launch position from end of first line (centred in deg)", y= "Return-sweep landing position (deg)",
color= "", shape= '', linetype= '', fill= '') +
facet_wrap(~font_size)+
geom_ribbon(alpha= 0.2, color= NA) + theme(legend.position = c(0.87, 0.88), legend.title=element_blank(),
legend.key.width = unit(1.5, 'cm'), legend.key.height = unit(0.75, 'cm'),
panel.grid.major = element_line(size = 0.5, linetype = 'solid', colour = "white"),
panel.grid.minor = element_line(size = 0.25, linetype = 'solid', colour = "white"),
strip.background = element_rect(colour="white", fill="white"),
strip.text = element_text(size=22, face="bold"), text=element_text(family="serif"))+
scale_fill_manual(values=c(pallete1[1], pallete1[2]))+
scale_color_manual(values=c(pallete1[1], pallete1[2])); G1
ggsave(filename = 'Plots/3-way.pdf', plot = G1, width = 10, height = 7)
###############################################################################
# Modulation by trial order: LANDING POSITIONS #
###############################################################################
#-------------------------------
# Prepare dataset for analsysis:
#-------------------------------
# fix seq issues for a few subjects where the gaze-box was not triggered properly:
a<- which(RS$sub==6)
RS$seq[a]<- 1:length(a)
a<- which(RS$sub==12)
RS$seq[a[1:25]]<- c(1:25)
RS$seq[a[26:38]]<- 26:38
RS$seq[a[39:99]]<- 40:100
a<- which(RS$sub==16) # seq 72 rpt
RS$seq[a[70:98]]<- 72:100
a<- which(RS$sub==22) # seq 11, 67 rpt
RS$seq[a[6:60]]<- RS$seq[a[6:60]]-1
a<- which(RS$sub==46) #seq 53
RS$seq[a[53:100]]<- RS$seq[a[53:100]]-1
a<- which(RS$sub==51)
RS$seq[a[5:95]]<- RS$seq[a[5:95]]-1
# check contrast coding:
contrasts(RS$font_size)
contrasts(RS$line_len)
RS$sub<- as.numeric(as.character(RS$sub))
# Add block order:
RS$block_order<- NA
RS$big_font_block<- NA
RS$small_font_block<- NA
for(i in 1:nrow(RS)){
if(RS$sub[i]%%2==1){ # odd subject, small font first
RS$big_font_block[i]<- 2
RS$small_font_block[i]<- 1
if(RS$font_size[i]== "small font"){ # small font, block seq= seq
RS$block_order[i]<- RS$seq[i]
}else{ # big font, block seq = seq-50 (50 is halfway point; 100 items)
RS$block_order[i]<- RS$seq[i]- 50
}
}else{ # even subject, big font first
RS$big_font_block[i]<- 1
RS$small_font_block[i]<- 2
if(RS$font_size[i]== "small font"){ # big font, block seq = seq-50 (50 is halfway point; 100 items)
RS$block_order[i]<- RS$seq[i]- 50
}else{ # small font, block seq= seq
RS$block_order[i]<- RS$seq[i]
}
}
}
# take a smaller, more managable dataset:
tDat<- RS[,c("sub", "item", "seq", "cond", "font_size", "line_len", "LandStartVA", "launchDistVA", "undersweep_prob" , "block_order",
"big_font_block", "small_font_block")]
#tDat$big_font_block<- as.factor(tDat$big_font_block)
#tDat$big_font_block<- factor(tDat$big_font_block, levels= c("small font", "big font"))
#contrasts(tDat$big_font_block)
is.numeric(tDat$block_order)
# gamm model:
tDat$big_font_block<- as.factor(tDat$big_font_block)
contrasts(tDat$big_font_block)<- c(-1, 1)
tDat$small_font_block<- as.factor(tDat$small_font_block)
contrasts(tDat$small_font_block)<- c(-1, 1)
contrasts(tDat$font_size)
tDat$block<- ifelse(tDat$small_font_block==1, "first", "second")
tDat$block<- as.factor(tDat$block)
contrasts(tDat$font_size)
block1<- subset(tDat, block== "first")
block2<- subset(tDat, block== "second")
##############################################################################
# small block first, large block second
gamLP1 <- bam(LandStartVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block1)
summary(gamLP1)
# large block first, small block second
gamLP2 <- bam(LandStartVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block2)
summary(gamLP2)
##############
# GAMM PLot: #
##############
pdf('Plots/GAMMs.pdf', width = 11, height = 11)
par(mfrow=c(2,2), mar= c(5,5,4,3))
# small block first, large block second
plot_smooth(gamLP1, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Landing position (deg)", main= "a) Font size means (small -> large block order)",
col = c(pallete1[1], pallete1[2]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(2,1), ylim= c(1, 2.7),
cex.main=1.7)
#legend:
legend(x = 28, y= 2.6, legend = c("Large font", "Small font"), col = c(pallete1[2], pallete1[1]), lwd = c(2, 2),
box.col = "white", lty= c(1,2), seg.len=2, cex = 1.5)
# large block first, small block second
plot_smooth(gamLP2, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Landing position (deg)", main= "b) Font size means (large -> small block order)",
col = c(pallete1[2], pallete1[1]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(1,2), ylim= c(1, 2.7),
cex.main=1.7)
# Font size effect: small - large
plot_diff(gamLP1, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "c) Font size effect (small -> large block order)",
ylab= "Mean diff. in landing position (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-1, 0.5),
mark.diff = T, col.diff = NA)
abline(v = c(14.858586, 50), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 14.858586, x1 = 50, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
# Font size effect: large - small
plot_diff(gamLP2, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "d) Font size effect (large -> small block order)",
ylab= "Mean diff. in landing position (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-1, 0.5),
mark.diff = T, col.diff = NA)
abline(v = c(5.949495, 50), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 5.949495, x1 = 50, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
dev.off()
##############################################################################
####################################################################
# Modulation of SACCADE LENGTH by trial order: #
####################################################################
#-------------------------------
# Prepare dataset for analsysis:
#-------------------------------
# fix seq issues for a few subjects where the gaze-box was not triggered properly:
for(i in 1:nrow(Alldata2)){
# subject 6
if(Alldata2$sub[i]==6){
# 40 & 55
if(is.element(Alldata2$seq[i], c(51:54))){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
if(is.element(Alldata2$seq[i], c(56:102))){
Alldata2$seq[i]<- Alldata2$seq[i]-2
}
} # end of subject 6
# subject 12
if(Alldata2$sub[i]== 12){
# 25, 46
if(is.element(Alldata2$seq[i], c(26:46))){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
if(Alldata2$seq[i]>46){
Alldata2$seq[i]<- Alldata2$seq[i]-2
}
} # end of subject 12
# subject 16
if(Alldata2$sub[i]== 16){
# 72
if(Alldata2$seq[i]>71){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
} # end of subject 16
# subject 22
if(Alldata2$sub[i]== 22){
# 11, 67
if(is.element(Alldata2$seq[i], c(12:66))){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
if(Alldata2$seq[i]>66){
Alldata2$seq[i]<- Alldata2$seq[i]-2
}
} # end of subject 22
# subject 46
if(Alldata2$sub[i]== 46){
# 53
if(Alldata2$seq[i]>53){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
} # end of subject 46
# subject 51
if(Alldata2$sub[i]== 51){
# 5
if(Alldata2$seq[i]>5){
Alldata2$seq[i]<- Alldata2$seq[i]-1
}
}# subject 51
}
# check contrast coding:
contrasts(Alldata2$font_size)
contrasts(Alldata2$line_len)
Alldata2$sub<- as.numeric(as.character(Alldata2$sub))
Alldata2<- subset(Alldata2, Rtn_sweep==0) # remove return sweep saccades
table(Alldata2$Rtn_sweep)
# Add block order:
Alldata2$block_order<- NA
Alldata2$big_font_block<- NA
Alldata2$small_font_block<- NA
for(i in 1:nrow(Alldata2)){
if(Alldata2$sub[i]%%2==1){ # odd subject, small font first
Alldata2$big_font_block[i]<- 2
Alldata2$small_font_block[i]<- 1
if(Alldata2$font_size[i]== "small font"){ # small font, block seq= seq
Alldata2$block_order[i]<- Alldata2$seq[i]
}else{ # big font, block seq = seq-50 (50 is halfway point; 100 items)
Alldata2$block_order[i]<- Alldata2$seq[i]- 50
}
}else{ # even subject, big font first
Alldata2$big_font_block[i]<- 1
Alldata2$small_font_block[i]<- 2
if(Alldata2$font_size[i]== "small font"){ # big font, block seq = seq-50 (50 is halfway point; 100 items)
Alldata2$block_order[i]<- Alldata2$seq[i]- 50
}else{ # small font, block seq= seq
Alldata2$block_order[i]<- Alldata2$seq[i]
}
}
}
# take a smaller, more managable dataset:
tDat2<- Alldata2[,c("sub", "item", "seq", "cond", "font_size", "line_len", "launchDistVA", "undersweep_prob" , "block_order",
"big_font_block", "small_font_block")]
tDat2<- subset(tDat2, block_order>0)
is.numeric(tDat2$block_order)
contrasts(tDat2$font_size)
tDat2$block<- ifelse(tDat2$small_font_block==1, "first", "second")
tDat2$block<- as.factor(tDat2$block)
contrasts(tDat2$font_size)
block1S<- subset(tDat2, block== "first")
block2S<- subset(tDat2, block== "second")
##############################################################################################
# small block first, large block second
gamSL1 <- bam(launchDistVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block1S)
summary(gamSL1)
# large block first, small block second
gamSL2 <- bam(launchDistVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block2S)
summary(gamSL2)
##############
# GAMM PLot: #
##############
pdf('Plots/GAMMs_intra_line.pdf', width = 11, height = 11)
par(mfrow=c(2,2), mar= c(5,5,4,3))
# small block first, large block second
plot_smooth(gamSL1, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Intra-line saccade length (deg)", main= "a) Font size means (small -> large block order)",
col = c(pallete1[1], pallete1[2]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(2,1), ylim= c(2.1, 3.5),
cex.main=1.7)
# large block first, small block second
plot_smooth(gamSL2, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Intra-line saccade length (deg)", main= "b) Font size means (large -> small block order)",
col = c(pallete1[2], pallete1[1]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(1,2), ylim= c(2.1, 3.5),
cex.main=1.7)
#legend:
legend(x = 28, y= 2.4, legend = c("Large font", "Small font"), col = c(pallete1[2], pallete1[1]), lwd = c(2, 2),
box.col = "white", lty= c(1,2), seg.len=2, cex = 1.5)
# Font size effect: small - large
plot_diff(gamSL1, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "c) Font size effect (small -> large block order)",
ylab= "Mean diff. in saccade length (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-1, 0.5),
mark.diff = T, col.diff = NA)
abline(v = c(1, 50), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 1, x1 = 50, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
# Font size effect: large - small
plot_diff(gamSL2, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "d) Font size effect (large -> small block order)",
ylab= "Mean diff. in saccade length (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-1, 0.5),
mark.diff = T, col.diff = NA)
abline(v = c(1, 50), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 1, x1 = 50, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
dev.off()
##############################################################################################
#########################################################################################################################
# MODULATION BY TRIAL NUMBER - RETURN SWEEPS #
#########################################################################################################################
###############################################################################################
# small block first, large block second
gamRS1 <- bam(launchDistVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block1)
summary(gamRS1)
# large block first, small block second
gamRS2 <- bam(launchDistVA ~ font_size+
s(sub, bs="re", k=10) +
s(sub, font_size, bs="re", k=10) +
s(item, bs= "re", k=10)+
s(item, font_size, bs="re") +
s(block_order, bs= "cr", k=10)+
s(block_order, by= font_size, k=10, bs= "cr")+
# s(font_size, by= font_size, k=10, bs= "cr")+
s(block_order, sub, bs= "fs", m=1, k=4),
data= block2)
summary(gamRS2)
pdf('Plots/GAMMs_RS_length.pdf', width = 11, height = 11)
par(mfrow=c(2,2), mar= c(5,5,4,3))
# small block first, large block second
plot_smooth(gamRS1, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Return-sweep saccade length (deg)", main= "a) Font size means (small -> large block order)",
col = c(pallete1[1], pallete1[2]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(2,1), ylim= c(15.5, 18.5),
cex.main=1.7)
#legend:
legend(x = 2, y= 16.2, legend = c("Large font", "Small font"), col = c(pallete1[2], pallete1[1]), lwd = c(2, 2),
box.col = "white", lty= c(1,2), seg.len=2, cex = 1.5)
# large block first, small block second
plot_smooth(gamRS2, view="block_order", plot_all="font_size", rug=F, xlab= "Trial number within block",
ylab= "Return-sweep saccade length (deg)", main= "b) Font size means (large -> small block order)",
col = c(pallete1[2], pallete1[1]), legend_plot_all = list(x=0, y=0), family= "serif",
cex.axis= 1.6, cex.lab= 1.7, hide.label = T, lwd= 2, lty= c(1,2), ylim= c(15.5, 18.5),
cex.main=1.7)
# Font size effect: small - large
plot_diff(gamRS1, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "c) Font size effect (small -> large block order)",
ylab= "Mean diff. in RS saccade length (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-0.8, 2.2),
mark.diff = T, col.diff = NA)
abline(v = c(13.373737, 50), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 13.373737, x1 = 50, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
# Font size effect: large - small
plot_diff(gamRS2, view = "block_order", rm.ranef = F, comp = list(font_size = c("small font", "big font")),
col = pallete1[3], main= "d) Font size effect (large -> small block order)",
ylab= "Mean diff. in RS saccade length (deg)", xlab= "Trial number within block", print.summary = T,
family= "serif", cex.axis= 1.6, cex.lab= 1.7, cex.main= 1.7, lwd= 2, lty=1 , hide.label = T, ylim= c(-0.8, 2.2),
mark.diff = T, col.diff = NA)
abline(v = c(9.414141, 49.010101), col= "red", lwd= 2.5, lty= 3 )
segments(x0 = 9.414141, x1 = 49.010101, y0 = -1.06, y1 = -1.06, col= "red", lwd= 3)
dev.off()
################################################################################################
#########################################################################################################################
# Post-hoc analyses suggested by Reviewers #
#########################################################################################################################
####### Do variences of under-sweep probability differs between the two font size conditions:
# Since the data is binomial, we average over items to get a single mean for each condition:
small_font<- subset(RS, font_size== "small font")
small_font<- small_font$LandStartVA
big_font<- subset(RS, font_size== "big font")
big_font<- big_font$LandStartVA
#db<- data.frame(small= small_font, big= big_font)
#db2<- data.frame(Mean= c(db$small, db$big))
#db2$Font<- c(rep("small", 128), rep("big", 128))
library(tidyverse)
library(ggpubr)
library(ggplot2)
# let's check normality distribution:
ggqqplot(small_font)
ggqqplot(small_font)
shapiro.test(small_font)
shapiro.test(big_font)