-
Notifications
You must be signed in to change notification settings - Fork 0
/
AVSRT_Autism_main_analysis.m
4298 lines (3722 loc) · 132 KB
/
AVSRT_Autism_main_analysis.m
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
% Script for running the main analysis of the AVSRT-Autism Study.
% Dependencies:
% RaceModel: https://github.com/mickcrosse/RaceModel
% PERMUTOOLS: https://github.com/mickcrosse/PERMUTOOLS
% RSE-box: https://github.com/tomotto/RSE-box
% M3 Toolbox: https://github.com/canlab/MediationToolbox
% MES: https://github.com/hhentschke/measures-of-effect-size-toolbox
% References:
% [1] Crosse MJ, Foxe JJ, Molholm S (2019) Developmental Recovery of
% Impaired Multisensory Processing in Autism and the Cost of
% Switching Sensory Modality. bioRxiv 565333.
% [2] Crosse MJ, Foxe JJ, Tarrit K, Freedman EG, Molholm S (submitted)
% Resolution of Impaired Multisensory Processing in Autism and the
% Cost of Switching Sensory Modality.
% Copyright (c) 2021, Mick Crosse <mickcrosse@gmail.com>
clear;
clc;
% Directory
subj_info = xlsread('.\AVSRT_Autism_subject_info.xlsx');
% Get subject IDs
id = subj_info(:,1);
nSubjs = length(id);
% Set parameters
minAge = 6;
maxAge = 40;
minIQ = 80;
minRT = 100;
maxRT = 2e3;
minISI = 950;
maxISI = 3150;
minPer = 2.5;
maxPer = 97.5;
minTrials = 20;
startTrials = 3;
factor = 3;
outliers = 'cond';
% Preallocate memory
faRate = zeros(nSubjs,1);
hitRate = zeros(nSubjs,1);
Fscore = zeros(nSubjs,1);
AHR = zeros(nSubjs,1);
VHR = zeros(nSubjs,1);
perLim = zeros(nSubjs,2);
numRTs = zeros(nSubjs,3);
lwrISI = zeros(nSubjs,1);
grp_vec = zeros(nSubjs,1);
sex_vec = zeros(nSubjs,1);
age_vec = zeros(nSubjs,1);
dev_vec = zeros(nSubjs,1);
piq_vec = zeros(nSubjs,1);
viq_vec = zeros(nSubjs,1);
fsiq_vec = zeros(nSubjs,1);
ados_vec = zeros(nSubjs,1);
RT_cell = cell(nSubjs,1);
RTprev_cell = cell(nSubjs,1);
cond_cell = cell(nSubjs,1);
task_cell = cell(nSubjs,1);
type_cell = cell(nSubjs,1);
ISI_cell = cell(nSubjs,1);
subj_cell = cell(nSubjs,1);
grp_cell = cell(nSubjs,1);
sex_cell = cell(nSubjs,1);
age_cell = cell(nSubjs,1);
dev_cell = cell(nSubjs,1);
piq_cell = cell(nSubjs,1);
viq_cell = cell(nSubjs,1);
fsiq_cell = cell(nSubjs,1);
ados_cell = cell(nSubjs,1);
% Initialize variables
ctr = 1;
allRTs = [];
fastRTs = [];
slowRTs = [];
% Process data
fprintf('Processing data...')
% Loop through subjects
for i = 1:size(id,1)
% Load data
load(['.\data\sub_',num2str(id(i)),'.mat']);
% Compute some parameters
nR2s = nansum(R2s);
nBlocks = length(nStims);
nTrials = sum(nStims);
% Compute percentage of fast and slow RTs
allRTs = [allRTs;RTs(~isnan(RTs) & RTs<4e3)];
fastRTs = [fastRTs;sum(RTs<minRT)/length(~isnan(RTs))*100];
slowRTs = [slowRTs;sum(RTs>maxRT)/length(~isnan(RTs))*100];
% Define previous RTs
RTprev = [NaN;RTs(1:end-1)];
RTprev(nStims(1:end-1)+1) = NaN;
% Re-number conditions (AV=1, A=2, V=3)
conds = conds-2;
% Find number of hits
noRT = isnan(RTs) | RTs>maxRT;
misses = sum(noRT);
hits = nTrials-misses;
aHits = sum(conds==2 & noRT==0);
vHits = sum(conds==3 & noRT==0);
% Compute precision and recall
falarms = sum(nResps)-hits+sum(RTs<minRT);
precis = hits./(hits+falarms);
recall = hits./(hits+misses);
% Compute false alarm rate and hit rate
faRate(ctr) = falarms/nTrials*100;
hitRate(ctr) = hits/nTrials*100;
Fscore(ctr) = 2*(precis.*recall)./(precis+recall);
% Compute A and V hit rates as percentage of each other
AHR(ctr) = aHits/vHits*100;
VHR(ctr) = vHits/aHits*100;
% Index first 3 trials of each block (training trials)
startTrials = [];
endTrials = [0;cumsum(nStims(1:end-1))];
for k = 1:nBlocks
startTrials = [startTrials;endTrials(k)+(1:startTrials)'];
end
% Index bad trials (misses, double-presses, fast/slow RTs, training)
badRTs = unique([find(isnan(RTs));find(RTs<minRT|RTs>maxRT);...
find(R2s==true);find(ISIs<minISI|ISIs>maxISI);startTrials]);
% Find bad previous trials
badprevRTs = badRTs(badRTs<length(RTs))+1;
RTprev(badprevRTs) = NaN;
% Get rid of bad trials
RTs(badRTs) = []; %#ok<*SAGROW>
RTprev(badRTs) = [];
ISIs(badRTs) = [];
tasks(badRTs) = [];
conds(badRTs) = [];
clear badRTs badprevRTs
% Use middle 95th percentile of RTs
switch outliers
case 'cond'
perCond = zeros(3,2);
idxConds = cell(1,3);
for k = 1:3
idxConds{k} = find(conds==k);
perCond(k,:) = prctile(RTs(conds==k),[minPer,maxPer]);
badRTs{k} = idxConds{k}(RTs(conds==k)<perCond(k,1) | RTs(conds==k)>perCond(k,2));
end
perLim(ctr,:) = [min(perCond(:,1)),max(perCond(:,2))];
badRTs = cell2mat(badRTs(:));
case 'all'
perLim(ctr,:) = prctile(RTs,[minPer,maxPer]);
badRTs = find(RTs<perLim(ctr,1) | RTs>perLim(ctr,2));
end
% Find bad previous trials
badprevRTs = badRTs(badRTs<length(RTs))+1;
RTprev(badprevRTs) = NaN;
% Get rid of bad trials
RTs(badRTs) = [];
RTprev(badRTs) = [];
ISIs(badRTs) = [];
tasks(badRTs) = [];
conds(badRTs) = [];
% Compute # of RTs per condition
for k = 1:3
numRTs(ctr,k) = sum(conds==k);
end
% Compute average ISI
lwrISI(ctr) = nanmin(ISIs);
% Get subject group(NT=1, ASD=2), sex(M=1, F=2) and age
grp = subj_info((subj_info(:,1)==id(i)),2);
sex = subj_info((subj_info(:,1)==id(i)),3);
age = subj_info((subj_info(:,1)==id(i)),4);
piq = subj_info((subj_info(:,1)==id(i)),5);
viq = subj_info((subj_info(:,1)==id(i)),6);
fsiq = subj_info((subj_info(:,1)==id(i)),7);
ados = subj_info((subj_info(:,1)==id(i)),8);
% Define developmental group (6-9=1, 10-12=2, 13-17=3, 18-40=4)
if age>=minAge && age<10
dev = 1;
elseif age>=10 && age<13
dev = 2;
elseif age>=13 && age<18
dev = 3;
elseif age>=18 && age<maxAge
dev = 4;
else
dev = NaN;
end
% Define task type (swtich=1, repeat=2, neither=NaN)
type = tasks;
type(tasks==2|tasks==3|tasks==6|tasks==8) = 1;
type(tasks==1|tasks==5|tasks==9) = 2;
type(tasks==4|tasks==7) = NaN;
% Store data in vectors
sex_vec(ctr) = sex;
grp_vec(ctr) = grp;
dev_vec(ctr) = dev;
age_vec(ctr) = age;
piq_vec(ctr) = piq;
viq_vec(ctr) = viq;
fsiq_vec(ctr) = fsiq;
ados_vec(ctr) = ados;
% Store data in cell arrays
RT_cell{ctr} = RTs;
RTprev_cell{ctr} = RTprev;
ISI_cell{ctr} = ISIs;
cond_cell{ctr} = conds;
task_cell{ctr} = tasks;
type_cell{ctr} = type;
subj_cell{ctr} = ctr*ones(size(RTs));
grp_cell{ctr} = grp*ones(size(RTs));
sex_cell{ctr} = sex*ones(size(RTs));
age_cell{ctr} = age*ones(size(RTs));
dev_cell{ctr} = dev*ones(size(RTs));
piq_cell{ctr} = piq*ones(size(RTs));
viq_cell{ctr} = viq*ones(size(RTs));
fsiq_cell{ctr} = fsiq*ones(size(RTs));
ados_cell{ctr} = ados*ones(size(RTs));
% Increment counter
ctr = ctr+1;
clear RTs RTprev ISIs R2s badRTs
clear conds tasks type trials
clear nStims nResps nResps2
clear sex age dev piq viq fsiq ados
end
% Update number of subjects
nSubjs = ctr-1;
% Store variables for plotting
tmp1 = faRate;
tmp2 = Fscore;
midRTs = cell2mat(RT_cell);
% Index bad subjects
fprintf('\n\nBad subjects:\n')
% Identify subjects too young/old
badIDs = isnan(age_vec) | age_vec<minAge | age_vec>maxAge;
for i = find(badIDs)'
fprintf('%d - Age: %.1f yrs\n',id(i),age_vec(i))
end
idx = badIDs;
% Identify subjects with low PIQ
tmp = piq_vec; tmp(idx) = NaN;
badIDs = tmp<minIQ | (isnan(piq_vec) & grp_vec==2 & dev_vec~=4);
for i = find(badIDs)'
fprintf('%d - PIQ: %d\n',id(i),piq_vec(i))
end
idx = idx | badIDs; clear tmp
% Identify subjects with high false alarm rate (excessive button presses)
tmp = faRate; tmp(idx) = NaN;
thr = nanmean(tmp)+factor*nanstd(tmp);
badIDs = tmp>thr;
for i = find(badIDs)'
fprintf('%d - FA: %.0f%%\n',id(i),faRate(i))
end
idx = idx | badIDs; clear tmp thr
% Identify subjects with low hit rate (not attending)
tmp = Fscore; tmp(idx) = NaN;
thr = nanmean(tmp)-factor*nanstd(tmp);
badIDs = tmp<thr;
for i = find(badIDs)'
fprintf('%d - F1: %.2f\n',id(i),Fscore(i))
end
idx = idx | badIDs; clear tmp thr
% Identify subjects with low V hit rate (eyes closed)
tmp = VHR; tmp(idx) = NaN;
tmp(tmp>1000) = NaN;
thr = nanmean(tmp)-factor*nanstd(tmp);
badIDs = tmp<thr;
for i = find(badIDs)'
fprintf('%d - V-HR: %.0f%%\n',id(i),VHR(i))
end
idx = idx | badIDs; clear tmp thr
% Identify subjects with low A hit rate (not listening)
tmp = AHR; tmp(idx) = NaN;
tmp(tmp>1000) = NaN;
thr = nanmean(tmp)-factor*nanstd(tmp);
badIDs = tmp<thr;
for i = find(badIDs)'
fprintf('%d - A-HR: %.0f%%\n',id(i),AHR(i))
end
idx = idx | badIDs; clear tmp thr
% Identify subjects with < 20 RTs (min required number)
tmp = numRTs; tmp(idx,:) = NaN;
badIDs = min(tmp,[],2)<minTrials;
for i = find(badIDs)'
fprintf('%d - #RTs: %d, %d, %d\n',id(i),numRTs(i,:)<minTrials)
end
idx = idx | badIDs; clear tmp thr
% Identify subjects with min ISIs > 2000 ms (should be 1000-3000 ms)
tmp = lwrISI; tmp(idx,:) = NaN;
badIDs = tmp>2e3;
for i = find(badIDs)'
fprintf('%d - Min ISI: %.0f ms\n',id(i),lwrISI(i))
end
idx = idx | badIDs; clear tmp thr badIDs
% Compute total bad subjects
nBad = sum(idx)-length(ctr:nSubjs);
fprintf('Subjects rejected: %d/%d (%.1f%%)\n',nBad,nSubjs,nBad/nSubjs*100)
% Get rid of bad subjects
id(idx) = [];
grp_vec(idx) = [];
sex_vec(idx) = [];
age_vec(idx) = [];
dev_vec(idx) = [];
piq_vec(idx) = [];
viq_vec(idx) = [];
fsiq_vec(idx) = [];
ados_vec(idx) = [];
faRate(idx) = [];
hitRate(idx) = [];
Fscore(idx) = [];
AHR(idx) = [];
VHR(idx) = [];
numRTs(idx,:) = [];
fastRTs(idx) = [];
slowRTs(idx) = [];
perLim(idx,:) = [];
lwrISI(idx) = [];
subj_cell(idx) = [];
grp_cell(idx) = [];
sex_cell(idx) = [];
age_cell(idx) = [];
dev_cell(idx) = [];
piq_cell(idx) = [];
viq_cell(idx) = [];
fsiq_cell(idx) = [];
ados_cell(idx) = [];
RT_cell(idx) = [];
RTprev_cell(idx) = [];
ISI_cell(idx) = [];
task_cell(idx) = [];
type_cell(idx) = [];
cond_cell(idx) = [];
% Update number of subjects
nSubjs = length(id);
exSub = find(id==186);
%% Plot results of outlier correction procedure
close all;
clc;
% Print percentage of fast/slow outliers
fprintf('Percentage of fast outliers: %1.1f ± %1.1f\n',mean(fastRTs),std(fastRTs));
fprintf('Percentage of slow outliers: %1.1f ± %1.1f\n',mean(slowRTs),std(slowRTs));
% Plot all and middle 95th percentile RTs
figure
subplot(2,1,1), histogram(allRTs,150), title('Before'), xlim([0,maxRT])
subplot(2,1,2), histogram(midRTs,100), title('After'), xlim([0,maxRT])
% Plot response rate of subjects within 95th percentile
figure
grp = [zeros(size(tmp1')),ones(size(faRate'))];
subplot(2,3,[1,4]), boxplot([tmp1;faRate]',grp)
title('False Alarm Rate'), ylabel('%'), set(gca,'xticklabel',{'Before','After'})
subplot(2,3,2:3), histogram(tmp1,60), title('Before'), xlim([0,250])
subplot(2,3,5:6), histogram(faRate,20), title('After'), xlim([0,250])
% Plot hit rate of subjects within 95th percentile
figure
grp = [zeros(size(tmp2')),ones(size(Fscore'))];
subplot(2,3,[1,4]), boxplot([tmp2;Fscore]',grp)
title('F_1 score'), ylabel('%'), set(gca,'xticklabel',{'Before','After'})
subplot(2,3,2:3), histogram(tmp2,40), title('Before'), xlim([0,1])
subplot(2,3,5:6), histogram(Fscore,20), title('After'), xlim([0,1])
%% Compute participant demographics
clc;
% Total number of subjects
fprintf('Number of subjects: %d (%d F)\n',length(id),sum(sex_vec==2));
fprintf('Number of NTs: %d (%d F)\n',sum(grp_vec==1),sum(grp_vec==1 & sex_vec==2));
fprintf('Number of ASDs: %d (%d F)\n',sum(grp_vec==2),sum(grp_vec==2 & sex_vec==2));
% Age ranges
fprintf('\nNT age range: %1.1f-%1.1f yrs\n',min(age_vec(grp_vec==1)),max(age_vec(grp_vec==1)));
fprintf('ASD age range: %1.1f-%1.1f yrs\n',min(age_vec(grp_vec==2)),max(age_vec(grp_vec==2)));
% Number of subjects
fprintf('\nNumber of subjects:\n')
for i = 1:2
for j = 1:4
n = sum(grp_vec==i & dev_vec==j);
fprintf('%d\t',n);
end
fprintf('\n');
end
% Number of females
fprintf('\nNumber of females:\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%d\t',length(find(sex_vec(idx)==2)));
end
fprintf('\n');
end
% Number of IQs
fprintf('\nNumber of IQs:\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%d\t',sum(~isnan(piq_vec(idx))));
end
fprintf('\n');
end
% Number of IQs
fprintf('\nPercentage of IQs:\n')
for i = 1:2
idx = grp_vec==i;
fprintf('%.1f\t',sum(~isnan(piq_vec(idx)))/sum(idx)*100);
fprintf('\n');
end
% Mean age
fprintf('\nMean age (SD):\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%1.1f (%1.1f)\t',nanmean(age_vec(idx)),nanstd(age_vec(idx)));
end
fprintf('\n');
end
% Mean F1 score
fprintf('\nMean F1 score (SD):\n')
for i = 1:2
for j = 1:4
idx = find(grp_vec==i & dev_vec==j);
fprintf('%1.2f (%1.2f)\t',nanmean(Fscore(idx)),nanstd(Fscore(idx)));
end
fprintf('\n');
end
% Mean False alarm rate
fprintf('\nMean False alarm rate (SD):\n')
for i = 1:2
for j = 1:4
idx = find(grp_vec==i & dev_vec==j);
fprintf('%1.2f (%1.2f)\t',nanmean(faRate(idx)/100),nanstd(faRate(idx)/100));
end
fprintf('\n');
end
% Mean misses
fprintf('\nMean misses (SD):\n')
for i = 1:2
for j = 1:4
idx = find(grp_vec==i & dev_vec==j);
fprintf('%1.2f (%1.2f)\t',nanmean(1-hitRate(idx)/100),nanstd(1-hitRate(idx)/100));
end
fprintf('\n');
end
% Mean PIQ
fprintf('\nMean PIQ (SD):\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%1.1f (%1.1f)\t',nanmean(piq_vec(idx)),nanstd(piq_vec(idx)));
end
fprintf('\n');
end
% Mean VIQ
fprintf('\nMean VIQ (SD):\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%1.1f (%1.1f)\t',nanmean(viq_vec(idx)),nanstd(viq_vec(idx)));
end
fprintf('\n');
end
% Mean FSIQ
fprintf('\nMean FSIQ (SD):\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%1.1f (%1.1f)\t',nanmean(fsiq_vec(idx)),nanstd(fsiq_vec(idx)));
end
fprintf('\n');
end
% Mean ADOS score
fprintf('\nMean ADOS score (SD):\n')
for i = 1:2
for j = 1:4
idx = grp_vec==i & dev_vec==j;
fprintf('%1.1f (%1.1f), n = %d\t',nanmean(ados_vec(idx)),nanstd(ados_vec(idx)),sum(~isnan(ados_vec(idx))));
end
fprintf('\n');
end
%% Test for group differences in age, performance and IQ
close all;
clc;
% Set params
nperm = 1e4;
age_match = false;
% Test for age difference
fprintf('Age:\n')
for i = 1:4
idx1 = grp_vec==1 & dev_vec==i & ~isnan(age_vec);
idx2 = grp_vec==2 & dev_vec==i & ~isnan(age_vec);
[tstat,~,orig,stats] = permtest_t2(age_vec(idx1),age_vec(idx2),'nperm',nperm);
d = mes(age_vec(idx1),age_vec(idx2),'hedgesg','isDep',0,'nBoot',nperm);
fprintf('t(%d) = %0.2f, ',stats.df,tstat)
fprintf('p = %0.3f, ',orig.p)
fprintf('g = %0.2f, ',d.hedgesg)
fprintf('95CI [%0.2f, %0.2f]\n',d.hedgesgCi)
end
% Test for F1 score difference
fprintf('\nF1 score:\n')
for i = 1:4
switch age_match
case true
if i==4
[idx1,idx2] = agematch(i,grp_vec,dev_vec,sex_vec,age_vec,[],false);
else
[idx1,idx2] = agematch(i,grp_vec,dev_vec,sex_vec,age_vec,piq_vec,false);
end
case false
idx1 = find(grp_vec==1 & dev_vec==i & ~isnan(Fscore));
idx2 = find(grp_vec==2 & dev_vec==i & ~isnan(Fscore));
end
[tstat,~,orig,stats] = permtest_t2(Fscore(idx1),Fscore(idx2),'nperm',nperm);
d = mes(Fscore(idx1),Fscore(idx2),'hedgesg','isDep',0,'nBoot',nperm);
fprintf('t(%d) = %0.2f, ',stats.df,tstat)
fprintf('p = %0.3f, ',orig.p)
fprintf('g = %0.2f, ',d.hedgesg)
fprintf('95CI [%0.2f, %0.2f]\n',d.hedgesgCi)
end
% Test for PIQ difference
fprintf('\nPIQ:\n')
for i = 1:4
switch age_match
case true
[idx1,idx2] = agematch(i,grp_vec,dev_vec,sex_vec,age_vec,piq_vec,false);
case false
idx1 = find(grp_vec==1 & dev_vec==i & ~isnan(piq_vec));
idx2 = find(grp_vec==2 & dev_vec==i & ~isnan(piq_vec));
end
[tstat,~,orig,stats] = permtest_t2(piq_vec(idx1),piq_vec(idx2),'nperm',nperm);
d = mes(piq_vec(idx1),piq_vec(idx2),'hedgesg','isDep',0,'nBoot',nperm);
fprintf('t(%d) = %0.2f, ',stats.df,tstat)
fprintf('p = %0.3f, ',orig.p)
fprintf('g = %0.2f, ',d.hedgesg)
fprintf('95CI [%0.2f, %0.2f]\n',d.hedgesgCi)
end
% Test for VIQ difference
fprintf('\nVIQ:\n')
for i = 1:4
switch age_match
case true
[idx1,idx2] = agematch(i,grp_vec,dev_vec,sex_vec,age_vec,piq_vec,false);
case false
idx1 = find(grp_vec==1 & dev_vec==i & ~isnan(viq_vec));
idx2 = find(grp_vec==2 & dev_vec==i & ~isnan(viq_vec));
end
[tstat,~,orig,stats] = permtest_t2(viq_vec(idx1),viq_vec(idx2),'nperm',nperm);
d = mes(viq_vec(idx1),viq_vec(idx2),'hedgesg','isDep',0,'nBoot',nperm);
fprintf('t(%d) = %0.2f, ',stats.df,tstat)
fprintf('p = %0.3f, ',orig.p)
fprintf('g = %0.2f, ',d.hedgesg)
fprintf('95CI [%0.2f, %0.2f]\n',d.hedgesgCi)
end
% Test for FSIQ difference
fprintf('\nFSIQ:\n')
for i = 1:4
switch age_match
case true
[idx1,idx2] = agematch(i,grp_vec,dev_vec,sex_vec,age_vec,piq_vec,true);
case false
idx1 = find(grp_vec==1 & dev_vec==i & ~isnan(fsiq_vec));
idx2 = find(grp_vec==2 & dev_vec==i & ~isnan(fsiq_vec));
end
[tstat,~,orig,stats] = permtest_t2(fsiq_vec(idx1),fsiq_vec(idx2),'nperm',nperm);
d = mes(fsiq_vec(idx1),fsiq_vec(idx2),'hedgesg','isDep',0,'nBoot',nperm);
fprintf('t(%d) = %0.2f, ',stats.df,tstat)
fprintf('p = %0.3f, ',orig.p)
fprintf('g = %0.2f, ',d.hedgesg)
fprintf('95CI [%0.2f, %0.2f]\n',d.hedgesgCi)
end
%% Compute CDFs and RMV
nConds = 3;
nConds2 = 11;
nTasks = 8;
test = 'ver';
dep = 0;
nSamps = 1e4;
% Define CDF percentiles
prob = 0:0.05:1;
% Pre-allocate memory
RTper = zeros(nSubjs,numel(prob));
RTs = cell(nSubjs,nConds,nTasks);
% Separate RTs by condition and trial type
for i = 1:nSubjs
RTper(i,:) = linspace(perLim(i,1),perLim(i,2),numel(prob));
for j = 1:nConds
RTs{i,j,1} = RT_cell{i}(cond_cell{i}==j); % 1. mix
RTs{i,j,2} = RT_cell{i}((task_cell{i}==1 | task_cell{i}==5 | task_cell{i}==9) & cond_cell{i}==j); % 2. repeat
RTs{i,j,3} = RT_cell{i}((task_cell{i}==2 | task_cell{i}==3 | task_cell{i}==6 | task_cell{i}==8) & cond_cell{i}==j); % 3. switch
RTs{i,j,4} = RT_cell{i}((task_cell{i}==2 | task_cell{i}==6 | task_cell{i}==8) & cond_cell{i}==j); % 4. switch A->AV
RTs{i,j,5} = RT_cell{i}((task_cell{i}==3 | task_cell{i}==6 | task_cell{i}==8) & cond_cell{i}==j); % 5. switch V->AV
RTs{i,j,6} = RT_cell{i}((task_cell{i}==1 | task_cell{i}==4 | task_cell{i}==7) & cond_cell{i}==j); % 6. AV prior
RTs{i,j,7} = RT_cell{i}((task_cell{i}==2 | task_cell{i}==5 | task_cell{i}==8) & cond_cell{i}==j); % 7. A prior
RTs{i,j,8} = RT_cell{i}((task_cell{i}==3 | task_cell{i}==6 | task_cell{i}==9) & cond_cell{i}==j); % 8. V prior
RTs{i,j,9} = RT_cell{i}((task_cell{i}==1 | task_cell{i}==5 | task_cell{i}==9) & cond_cell{i}==j & ISI_cell{i}<1500); % 9. repeat fast ISI
RTs{i,j,10} = RT_cell{i}((task_cell{i}==2 | task_cell{i}==3 | task_cell{i}==6 | task_cell{i}==8) & cond_cell{i}==j & ISI_cell{i}<1500); % 10. switch fast ISI
RTs{i,j,11} = RT_cell{i}((task_cell{i}==1 | task_cell{i}==5 | task_cell{i}==9) & cond_cell{i}==j & ISI_cell{i}>2500); % 11. repeat slow ISI
RTs{i,j,12} = RT_cell{i}((task_cell{i}==2 | task_cell{i}==3 | task_cell{i}==6 | task_cell{i}==8) & cond_cell{i}==j & ISI_cell{i}>2500); % 12. switch slow ISI
RTs{i,j,13} = RT_cell{i}(cond_cell{i}==j & ISI_cell{i}>2500); % 13. mix slow ISI
end
end
% Compute CDFs for each subject, condition, trial type
CDFs = zeros(nSubjs,nConds2,nTasks,numel(prob));
for i = 1:nSubjs
for j = 1:nTasks
[CDFs(i,6,j,:),CDFs(i,2,j,:),CDFs(i,3,j,:),CDFs(i,1,j,:)] = ...
racemodel(RTs{i,2,j},RTs{i,3,j},RTs{i,1,j},...
prob,'lim',perLim(i,:),'dep',dep,'test',test);
end
end
% Compute number of RTs for each subject, condition, trial type
nRTs = zeros(nSubjs,nConds,nTasks,numel(prob));
for i = 1:nSubjs
for j = 1:nConds
for k = 1:nTasks
for n = 2:numel(prob)
nRTs(i,j,k,n) = sum(RTs{i,j,k}<=RTper(i,n));
end
end
end
end
% Compute RMV based on simulation
CDFs(:,5,:,:) = CDFs(:,1,:,:) - CDFs(:,4,:,:);
switch test
case 'ver'
% Compute RMV based on Raab's model
CDFs(:,7,:,:) = CDFs(:,1,:,:) - CDFs(:,6,:,:);
% Compute Miller's bound
CDFs(:,8,:,:) = CDFs(:,2,:,:) + CDFs(:,3,:,:); CDFs(CDFs>1) = 1;
% Compute RMV based on Miller's bound
CDFs(:,9,:,:) = CDFs(:,1,:,:) - CDFs(:,8,:,:);
% Compute empirical benefit based on Grice's bound
CDFs(:,10,:,:) = CDFs(:,1,:,:) - max(CDFs(:,2:3,:,:),[],2);
% Compute predicted benefit (Raab's model vs. Grice's bound)
CDFs(:,11,:,:) = CDFs(:,6,:,:) - max(CDFs(:,2:3,:,:),[],2);
case 'hor'
% Compute RMV based on Raab's model
CDFs(:,7,:,:) = CDFs(:,6,:,:) - CDFs(:,1,:,:);
% Compute Miller's bound
CDFs(:,8,:,:) = CDFs(:,2,:,:) + CDFs(:,3,:,:);
% Compute RMV based on Miller's bound
CDFs(:,9,:,:) = CDFs(:,1,:,:) - CDFs(:,8,:,:);
% Compute empirical benefit based on Grice's bound
CDFs(:,10,:,:) = CDFs(:,1,:,:) - max(CDFs(:,2:3,:,:),[],2);
% Compute predicted benefit (Raab's model vs. Grice's bound)
CDFs(:,11,:,:) = CDFs(:,6,:,:) - max(CDFs(:,2:3,:,:),[],2);
end
%% Compute multisnesory benefits and gain
meth = 'all'; % 'all' 'pos' 'quant'
quant = 3;
% Define race model
race = mean(CDFs(:,6,6:8,:),3);
grice = CDFs(:,2:3,1,:);
% Compute multisensory benefits
switch test
case 'ver'
benPred = race - max(grice,[],2);
benPred = squeeze(trapz(prob,benPred,4));
benEmp = CDFs(:,1,1,:) - max(grice,[],2);
benEmp = squeeze(trapz(prob,benEmp,4));
case 'hor'
benPred = min(grice,[],2) - race;
benPred = squeeze(trapz(prob,benPred,4));
benEmp = min(grice,[],2) - CDFs(:,1,1,:);
benEmp = squeeze(trapz(prob,benEmp,4));
end
% Compute violation of channel-dependent race model
switch test
case 'ver'
rmv = squeeze(CDFs(:,1,1,:) - race);
case 'hor'
rmv = squeeze(race - CDFs(:,1,1,:));
end
% Compute modality switch costs
switch test
case 'ver'
msc = squeeze(CDFs(:,1:3,2,:) - CDFs(:,1:3,3,:));
case 'hor'
msc = squeeze(CDFs(:,1:3,3,:) - CDFs(:,1:3,2,:));
end
% Compute multisensory gain
switch meth
case 'quant'
gain = rmv(:,quant);
cost = msc(:,quant);
case 'all'
gain = trapz(prob,rmv,2);
cost = trapz(prob,msc,3);
end
%% Define plotting parameters
shades = [0,0.25,0.5,0.75];
colors = [0.0000 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840];
cols1 = colors;
cols2 = linspecer(3);
cols3 = [0,0,0;0.3,0.3,0.3;0.6,0.6,0.6];
age_groups = {'69','1012','1317','1840'};
diag_groups = {'NT','ASD'};
sex_groups = {'Female','Male'};
conditions = {'AV','A','V'};
switch_conds = {'V/A\rightarrowAV','V\rightarrowA','A\rightarrowV'};
labels = {'a','b'};
alpha = 0.05;
fnt = 'Helvetica';
fntSz = 10;
mkrSz = 10;
set(0,'DefaultAxesTitleFontWeight','normal')
%% Compare Race Model Approaches
clc;
% Set params
test = 1;
nperm = 1e4;
quant = 2:numel(prob)-1;
if test == 1
% Channel-independent race model vs. channel-dependent race model
[tstat,stats,orig] = permtest_t(squeeze(mean(CDFs(:,6,6:8,quant),3)),squeeze(mean(CDFs(:,6,1,quant),3)));
d = mes(squeeze(mean(CDFs(:,6,6:8,quant),3)),squeeze(mean(CDFs(:,6,1,quant),3)),'hedgesg','isDep',1,'nBoot',nperm);
d.hedgesg
elseif test == 2
% Simulated race distribution vs. Raab's model
[tstat,corx] = permtest_t(squeeze(mean(CDFs(:,6,6:8,quant),3)),squeeze(mean(CDFs(:,4,6:8,quant),3)));
d = mes(squeeze(mean(CDFs(:,6,6:8,quant),3)),squeeze(mean(CDFs(:,4,6:8,quant),3)),'hedgesg','isDep',1,'nBoot',nperm);
d.hedgesg
elseif test == 2
% Simulated race distribution vs. Miller's bound
[tstat,corx] = permtest_t(squeeze(mean(CDFs(:,8,1,quant),3)),squeeze(mean(CDFs(:,4,6:8,quant),3)));
d = mes(squeeze(mean(CDFs(:,8,1,quant),3)),squeeze(mean(CDFs(:,4,6:8,quant),3)),'hedgesg','isDep',1,'nBoot',nperm);
d.hedgesg
end
%% RESULTS SECTION
% 1. Reaction times and multisensory benefits
%% 1.1 Single trial reaction times (LME)
% A linear mixed-effects analysis was used to examine the effect of group,
% age and stimulus condition on RTs. Subject, ISI and preceding modality
% were included as random factors, with slope adjustments for condition.
close all hidden;
clc;
% Convert cell arrays to vectors
RT = cell2mat(RT_cell);
RTprev = cell2mat(RTprev_cell);
ISI = cell2mat(ISI_cell);
type = cell2mat(type_cell);
task = cell2mat(task_cell);
cond = cell2mat(cond_cell);
grp = cell2mat(grp_cell);
subj = cell2mat(subj_cell);
sex = cell2mat(sex_cell);
age = cell2mat(age_cell);
dev = cell2mat(dev_cell);
piq = cell2mat(piq_cell);
viq = cell2mat(viq_cell);
fsiq = cell2mat(fsiq_cell);
ados = cell2mat(ados_cell);
% Get previous modality
prev = task;
prev(prev==1|prev==4|prev==7) = 1;
prev(prev==2|prev==5|prev==8) = 2;
prev(prev==3|prev==6|prev==9) = 3;
prev(isnan(RTprev)) = NaN;
% Round RTs
ISI = round(ISI);
% Convert categorical variables to nominal or ordinal data
subj = categorical(subj,'Ordinal',0);
grp = categorical(grp,[1,2],{'NT','ASD'},'Ordinal',0);
dev = categorical(dev,[1,2,3,4],{'6-9','10-12','13-17','18-40'},'Ordinal',1);
cond = categorical(cond,[1,2,3],{'AV','A','V'},'Ordinal',0);
prev = categorical(prev,[1,2,3],{'AV','A','V'},'Ordinal',0);
type = categorical(type,[1,2],{'Switch','Repeat'},'Ordinal',0);
task = categorical(task,'Ordinal',0);
% Create dataset containing variables
ds = dataset(subj,grp,sex,age,dev,cond,prev,task,type,RT,RTprev,ISI,...
piq,viq,fsiq,ados);
% Fit linear mixed-effects model by ML criterion
disp('Fitting linear mixed-effects model...')
lm = fitlme(ds,'RT ~ grp + age * cond + (1+cond|subj) + (1+cond|prev) + (1|ISI)');
% Run ANOVA using Satterthwaite approximation
disp('Performing hypothesis tests on fixed effect terms...')
stats = anova(lm);
% Display LME and ANOVA stats
disp('Linear mixed-effects analysis:')
disp(lm.Rsquared)
disp(lm)
disp('ANOVA on fixed effect terms:')
disp(stats)
% Compute residuals stats
r = residuals(lm,'ResidualType','Raw');
pr = residuals(lm,'ResidualType','Pearson');
st = residuals(lm,'ResidualType','Standardized');
figure,
subplot(2,2,1), histfit(r), xlabel('Residuals'), ylabel('Frequency')
title('Histogram of residual with fitted normal density')
subplot(2,2,2), qqplot(r)
% subplot(2,2,3), plotResiduals(lm,'fitted')
subplot(2,2,4), plotResiduals(lm,'lagged')
figure, boxplot([r,pr,st])
% Check normality of residuals
mc_normalitytest(r);
% % Plot intercept and slope CIs and relationship
% figure, plotIntervals(ds,'RT ~ cond','subj')
% [~,~,RE] = randomEffects(lme);
% figure, scatter(RE.Estimate(1:2:end),RE.Estimate(2:2:end))
% [r,p] = corr(RE.Estimate(1:2:end),RE.Estimate(2:2:end))
%% 1.2 Multisensory benefits (LM)
% A linear regression analysis was used to examine the effects of diagnosis
% and age on multisensory benefit.
close all;
clc;
% Set params
ben_type = 'emp'; % 'pred' or 'emp'
stand_vars = false;
% Define variables
subj = 1:nSubjs;
grp = grp_vec;
sex = sex_vec;
age = age_vec;
dev = dev_vec;
switch ben_type
case 'pred'
rse = benPred;
case 'emp'
rse = benEmp;
end
% Standardize continuous variabiles
if stand_vars
rse = zscore(rse);
age = zscore(age);
end
% Convert non-numeric variables to categorical
subj = categorical(subj','Ordinal',0);
grp = categorical(grp,[1,2],{'NT','ASD'},'Ordinal',0);
sex = categorical(sex,[1,2],{'Male','Fem'},'Ordinal',0);
dev = categorical(dev,[1,2,3,4],{'6-9','10-12','13-17','18-40'},'Ordinal',1);
% Create dataset
ds = table(subj,grp,sex,age,dev,rse);
% Fit linear model to dataset
lm = fitlm(ds,'rse ~ grp + age');
% Perform hypothesis tests on fixed effect terms
disp('Performing hypothesis tests on fixed effect terms...')
stats = anova(lm);
% Display LME and ANOVA stats
disp(lm)
disp(stats)
% Define residuals
r = lm.Residuals.Raw;
pr = lm.Residuals.Pearson;